J
John Maclean
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")
#!/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")