Suppose I have a class A
class A
attr_accessor :x, :y
def initialize(x,y)
@x, @y = x, y
end
end
How can I get x
and y
attributes without knowing how exactly they were named.
E.g.
a = A.new(5,10)
a.attributes # => [5, 10]
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…