ITP2 - OOP Tutorials - Instance Methods

When you run this program, nothing happens. This is because the speak
method returned the string "Arf!", but we now need to print it out. So
we should add puts in front of it, like this:

puts sparky.speak           # => Arf!

Now, we should see that the output of our program is the string "Arf!".
We told sparky to speak and he did. Now, suppose we have another GoodDog
object:

fido = GoodDog.new("Fido")
puts fido.speak             # => Arf!

Our second fido object can also perform GoodDog behaviors. So again, all
objects of the same class have the same behaviors, though they contain
different states; here, the differing state is the name.

What if we wanted to not just say "Arf!", but say "Sparky says arf!"? In
our instance methods, which is what all the methods are so far, we have
access to instance variables. So, we can use string interpolation and
change our speak method to this (other code ommitted):

def speak
  "#{@name} says arf!"
end