delegate-callee.rb

Avdi Grimm, 01/12/2014 06:27 PM

Download (452 Bytes)

 
1
require "delegate"
2

    
3
class Target
4
  def foo
5
    puts "__callee__ in Target#foo: #{__callee__}"
6
  end
7
end
8

    
9
class Proxy < SimpleDelegator
10
  def foo
11
    puts "__callee__ in Proxy#foo: #{__callee__}"
12
    super
13
  end
14
end
15

    
16
class DelegateClassProxy < DelegateClass(Target)
17
  def foo
18
    puts "__callee__ in DelegateClassProxy#foo: #{__callee__}"
19
    super
20
  end
21
end
22

    
23
puts "Ruby #{RUBY_VERSION}"
24
Proxy.new(Target.new).foo
25
DelegateClassProxy.new(Target.new).foo