Friday, September 16, 2011

Ruby - Objects

Creating an object

irb(main):012:0> g = Greeter.new("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.



0 comments:

Post a Comment

Contact Form

Name

Email *

Message *

The Insane Techie - Android App

Launched an android app for the blog on 07th June 2016. Get it from google play store... Tips for using the app Use in landscape mo...