【发布时间】:2015-07-27 22:29:20
【问题描述】:
假设我有:
def foo(bar, baz)
puts "Called foo, bar = #{bar}, baz = #{baz}"
blah_blah
end
我可以为这样的编辑器宏做什么:
def foo(bar, baz)
puts "<the answer to this question>"
blah_blah
end
并得到相同的调试结果?
【问题讨论】:
假设我有:
def foo(bar, baz)
puts "Called foo, bar = #{bar}, baz = #{baz}"
blah_blah
end
我可以为这样的编辑器宏做什么:
def foo(bar, baz)
puts "<the answer to this question>"
blah_blah
end
并得到相同的调试结果?
【问题讨论】:
在方法中有一些可用的元信息:
def foo(bar, baz=2)
p __method__ #=> : foo
p method(__method__).parameters # => [[:req, :bar], [:opt, :baz]]
end
foo( 1, 2)
def foo(a: "bar",b: )
p method(__method__).parameters # => [[:keyreq, :b], [:key, :a]]
end
foo(a: 1,b: 2)
【讨论】: