From: John Maclean Date: 2006-01-04T09:43:04+09:00 Subject: Re: More on the fundamentals... In this line of code can anyone tell me why "food" is a method? I thought that they are preceded by a dot. __ an array __ the method __ parameters for code block / / / [cornflakes, yam, rice].each { |food| eat food} / \ code block __/ \__block args On Tue, 3 Jan 2006 23:51:15 +0900 John Maclean wrote: > 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") > -- John Maclean MSc (DIC) 07739 171 531