来自 c++ 背景,我对 Ruby 中的对象分配很好奇。对于以下对象分配应考虑哪些因素(如果有):
class MyClass
attr_accessor :a, :b
def initialize(a, b)
@a = a
@b = b
end
def some_method
puts "#{self.a} #{self.b}"
end
end
m = MyClass.new("first", "last")
n = MyClass.new("pizza", "hello")
q = n
q.some_method