Ruby - Objects

Creating an object

irb(main):012:0> g ="Ruby")
=> #<Greeter:0x16cac @name="Ruby">
irb(main):013:0> g.say_hi
Hi Ruby!
=> nil
irb(main):014:0> g.say_bye
Bye Ruby, come back soon
=> nil

Once the object g is created, it remembers that the name is Ruby. Hmm, what if we want to get at the name directly?

irb(main):015:0> g.@name
SyntaxError: compile error
(irb):52: syntax error
        from (irb):52

Nope, can’t do it.

Post a Comment