让对象拥有特殊变量或者方法
class Person
def getName
return "Tom"
end
end
tom1 = Person.new
tom2 = Person.new
# special class
class << tom1
def getAge
return 20
end
end
puts tom1.getAge
# error
puts tom2.getAge
让对象拥有特殊变量或者方法
class Person
def getName
return "Tom"
end
end
tom1 = Person.new
tom2 = Person.new
# special class
class << tom1
def getAge
return 20
end
end
puts tom1.getAge
# error
puts tom2.getAge