Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我有这个 Ruby 方法:
def get_proc_from_block(&block) return block end
现在,如果我用这样的块调用它:
p = get_proc_from_block(&:length)
...有什么办法让我以某种方式检查p并从中获取字符串"length"?
p
"length"
以下每个表达式都会产生相同的正则过程:
get_proc_from_block(&:length) :length.to_proc proc{ |a| a.length }
并且 Ruby 不支持检查他们的源代码。有关更详细的答案,请查看以下问题: