首页 > 解决方案 > 将实例方法传递给 #each 的简洁方法

问题描述

我正在寻找一种更简洁的方式传递#func#each.

class My
  def hello
    input = %w[a b c]
    input.each(&method(:func))
  end

  private

  def func(i)
    puts i
  end
end

My.new.hello

有没有?

标签: ruby

解决方案


推荐阅读