This link has been bookmarked by 18 people . It was first bookmarked on 24 Sep 2007, by swan lin.
-
21 May 12
-
04 Apr 12
-
21 Oct 11
-
21 Mar 11
-
19 Feb 11
-
Calling a method in Ruby is as easy as just mentioning its name to Ruby. If the method doesn’t take parameters that’s all you need. You can add empty parentheses if you’d like, but they’re not needed.
-
What’s the
#{name}bit? That’s Ruby’s way of inserting something into a string. -
If it’s obvious what you’re doing, the parentheses are optional.
-
other trick is the default parameter
World. What this is saying is “If the name isn’t supplied, use the default name of"World"”. -
new keyword here is
class. This defines a new class called Greeter and a bunch of methods for that class. Also notice@name -
. This is an instance variable, and is available to all the methods of the class.
-
-
02 Jul 10
-
One is that we’re calling the method without parentheses again. If it’s obvious what you’re doing, the parentheses are optional. The other trick is the default parameter
World. What this is saying is “If the name isn’t supplied, use the default name of"World"”. -
The new keyword here is
class. This defines a new class called Greeter and a bunch of methods for that class. Also notice@name. This is an instance variable, and is available to all the methods of the class. As you can see it’s used bysay_hiandsay_bye.
-
-
13 Apr 10
-
21 Jan 10
-
02 Nov 08
-
19 Aug 08
-
24 Sep 07
-
Ruby’s response
=> niltells us that it knows we’re done defining the method -
hto take a name as a parameter. -
saying is “If the name isn’t supplied, use the default name of
"World"”. -
@name. This is an instance variable, and is available to all the methods of the class
-
-
01 Mar 07
-
08 Nov 06
-
14 Oct 06
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.