class Person def name return @name end def name=(name) @name = name end def hello print "我是" + @name endend alex = Person.newalex.name = "阿莱库斯"alex.hello
class Person def name return @name end def name=(name) @name = name end def hello print "我是" + @name end end alex = Person.new alex.name = "阿莱库斯" alex.hello
def name return @name end
冰水金刚 发表于 2014-8-4 20:02 对于属性来说,是既能写入又能读取 def name return @name
冰水金刚 发表于 2014-8-4 20:15 initialize是Object类的私有化方法 可以F1标准库查看 它的大概意思是,当你用new方法来生成一个类的实例时 ...