SHOW:
|
|
- or go back to the newest paste.
1 | class Commander | |
2 | - | def initialize |
2 | + | def initialize(&block) |
3 | - | instance_eval(&block) |
3 | + | # Initialize me! |
4 | ||
5 | if block.arity > 0 | |
6 | - | def welcome; end |
6 | + | yield self |
7 | - | def launch; end |
7 | + | else |
8 | - | def goodbye; end |
8 | + | instance_eval &block |
9 | end | |
10 | end | |
11 | ||
12 | def welcome; puts "hello" end | |
13 | def launch; puts "whee" end | |
14 | def goodbye; puts "bye" end | |
15 | end | |
16 | ||
17 | Commander.new do | |
18 | welcome | |
19 | launch | |
20 | goodbye | |
21 | end | |
22 | ||
23 | Commander.new do |c| | |
24 | c.welcome | |
25 | c.launch | |
26 | c.goodbye | |
27 | end |