Project

General

Profile

Bug #10277 ยป ampersand-to_proc.rb

jridgewell (Justin Ridgewell), 09/21/2014 10:26 PM

 
1
class AmpersandMethod
2
  def mapper(*args)
3
    'instance method'
4
  end
5

    
6
  def to_proc
7
    method(:mapper)
8
  end
9
end
10

    
11
class AmpersandMethodToProc
12
  def mapper(*args)
13
    'instance method'
14
  end
15

    
16
  def to_proc
17
    method(:mapper).to_proc
18
  end
19
end
20

    
21
def yielder
22
  yield
23
end
24

    
25
a = [1]
26

    
27
# Works
28
puts yielder(&AmpersandMethod.new.method(:mapper))
29
puts a.map(&AmpersandMethod.new.method(:mapper))
30

    
31
# Works
32
puts yielder(&AmpersandMethodToProc.new)
33
puts a.map(&AmpersandMethodToProc.new)
34
puts yielder(&AmpersandMethodToProc.new)
35
puts a.map(&AmpersandMethodToProc.new)
36

    
37
# Errors
38
puts yielder(&AmpersandMethod.new)
39
puts a.map(&AmpersandMethod.new)