DEV Community

Discussion on: OO Ruby Concepts Part 1, Object Behavior

Collapse
 
dharshann profile image
Dharshan Bharathuru • Edited

If it is written for a beginner understanding, I think you have to consider typos and explanation.

garfield = cat.new
# Class name is a Camel case 
# garfield = Cat.new

cat.name = "Garfield"
# cat isn't initialised! you mean cat = Cat.new ? and invoking cat.name ?

puts garfield.name # "Garfield" Congrats! You've made a new cat! 

garfield.meow # Garfield can't meow. Why? meow isn't an instance variable like 'name'.
cat.meow # "Meow!" Cat can. Why? meow is a local variable. Only Cat can use it.