This example demonstrates the use of ‘private’
@first_name + ’ ’ + @last_name
first_name, last_name = name.split(/\s+/)
@first_name = name
@last_name = name
From the book:
" private tells Ruby that any methods declared in this class from
there on should be kept private. This means that only code within the
object’s methods can
access those private methods, whereas code outside of the class cannot.
For example, this code no longer works "
p = Person.new(“Fred Bloggs”)
NoMethodError: private method ‘set_last_name’ called for
When the author says, “only code within the object’s methods can
access those private methods, whereas code outside of the class
cannot.”, what is the code in the example that can “access those private
methods”, and what is the “code outside of the class that cannot” ?
That’s it for now, more questions later. Apologies to the author of
this book, it’s not you, it’s me. I’m a really slow learner.