Skip to content
Newer
Older
100644 35 lines (27 sloc) 643 Bytes
61e26a0 @newfront Ruby Primer Introduction Class Files and rdoc
authored Nov 3, 2010
1 #!/usr/bin/ruby
2
3 #
4 # = Greeter Class
5 #
6 # == Abstract
7 #This is a quick a dirty example of building a class in Ruby. We will create a
8 #Greeter class, you build the object by giving it a name, and it greets that name.
9 #
10 #<b>Use Cases</b>
11 #Instantiate New Object and append a name, invoke the say_hello method
12 # * greet = Greeter.new("Scott")
13 # * greet.say_hello
14 #
15
16 class Greeter
17
24160a4 @newfront Code Changes from Yesterdays Meetup
authored Nov 8, 2010
18 # declare @@name as an empty string
61e26a0 @newfront Ruby Primer Introduction Class Files and rdoc
authored Nov 3, 2010
19 @@name = ''
20
21 def initialize(str)
22 @@name = str.to_s
23 end
24
25 def say_hello
24160a4 @newfront Code Changes from Yesterdays Meetup
authored Nov 8, 2010
26 #returns nil
61e26a0 @newfront Ruby Primer Introduction Class Files and rdoc
authored Nov 3, 2010
27 puts "Hello, #{@@name}"
28 end
29
30 def say_hello!
31 puts "Hello, Sir #{@@name}. I understand it is urgent."
32 end
33
34 end
Something went wrong with that request. Please try again.