Pistos (owner)

Revisions

gist: 177395 Download_button fork
public
Description:
Passing accessors to children
Public Clone URL: git://gist.github.com/177395.git
Embed All Files: show embed
/home/pistos/ruby/method-test.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Child
  def initialize( accessor )
    @acc = accessor
  end
 
  def work
    puts @acc.call
  end
end
 
 
class Parent
  def initialize
    @child = Child.new( method( :data ) )
  end
 
  def data
    Time.now
  end
 
  def work
    @child.work
  end
end
 
p = Parent.new
p.work
sleep 2
p.work