Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Ruby
More on the fundamentals...
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="John Maclean, post: 4499524"] Please have a look at the comments below to see that I'm understanding things correctly; #!/usr/bin/ruby #Tue Jan 3 14:04:28 GMT 2006 class Greeter # a new class cllaed Greeter def initialize(name) # creating a new method called name @name = name # we define a new @instance variable called name end def say(phrase) # creating a new method called phrase... puts "#{phrase}, #{@name}" # ... which uses doube quotes to substitute end end # say hello g1 = Greeter.new("jayeola") g2 = Greeter.new("buddy") g3 = Greeter.new("vimmer") g4 = Greeter.new("slammer") # we have just created four new (object) instances belonging to the class # Greeter. They can now use the instance variables that have been created # above g1.say("Hello") g2.say("Wotcha") g3.say("Ire!") g4.say("Elake") [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Ruby
More on the fundamentals...
Top