调用作为数组元素的方法

can*_*noe 0 ruby

class Shop
  def self.name
    "kids-toy"
  end

  def self.postcode
    1000
  end
end

methods = ["name", "postcode"]
methods.each {|m|
  mcall = "Shop.#{m}"
  eval mcall
}
Run Code Online (Sandbox Code Playgroud)

有没有其他方法而不是调用eval调用作为数组元素的方法?

tok*_*and 5

使用Object#send:

methods.each { |m| Shop.send(m) }
Run Code Online (Sandbox Code Playgroud)