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.
我想向数组中的每个对象发送一个方法。我知道我可以做这样的事情
array = ... array.each { |obj| obj.some_method }
但是有没有一种方法可以让我执行以下操作?
array = ... array.send_each :some_method
使用Symbol#to_proc:
Symbol#to_proc
array.each(&:some_method)