假设我有一堂课 A
class A
attr_accessor :x, :y
def initialize(x,y)
@x, @y = x, y
end
end
Run Code Online (Sandbox Code Playgroud)
如何在不知道它们的确切名称的情况下获取x和y归属.
例如
a = A.new(5,10)
a.attributes # => [5, 10]
Run Code Online (Sandbox Code Playgroud)