class SimpleProc def to_proc proc {"Simple Proc"} end end def method yield end obj = SimpleProc.new puts method(&obj)
请问为什么结果是Simple Proc ??
谢谢·~~~~
class SimpleProc def to_proc proc {"Simple Proc"} end end def method yield end obj = SimpleProc.new puts method(&obj)
请问为什么结果是Simple Proc ??
谢谢·~~~~
class SimpleProc
def to_proc
proc {"Simple Proc"}
end
end
def method
yield
end
obj = SimpleProc.new
puts method(&obj)
yield 调用 proc
将obj to_proc 不就是 Simple Proc 吗
看看下面的例子就明白了
def method
yield
end
puts method {"hello"} # hello