あるオブジェクトに対して1回で複数のメソッドを呼ぶ
書いて見た。jbuilderっぽい見た目になった。
class Object def call(*methods) methods.map do |method| self.send(method) end end end p [1,2,3].(:first, :last, :class) # => [1, 3, Array]
書いて見た。jbuilderっぽい見た目になった。
class Object def call(*methods) methods.map do |method| self.send(method) end end end p [1,2,3].(:first, :last, :class) # => [1, 3, Array]