【发布时间】:2012-04-17 21:52:22
【问题描述】:
假设我有一个班级A
class A
attr_accessor :x, :y
def initialize(x,y)
@x, @y = x, y
end
end
如何在不知道它们的确切命名方式的情况下获得 x 和 y 属性。
例如
a = A.new(5,10)
a.attributes # => [5, 10]
【问题讨论】:
标签: ruby metaprogramming