我不明白,为什么在这短短的Ruby脚本不利用“劳伦斯”:它为什么不把它大写?
class Player
def his_name #the same as attr_reader :name ?
@name
end
def his_name=(new_name) #the same as attr_writer :name ?
@name = new_name.capitalize
end
def initialize(name, health=100)
@name = name.capitalize
@health = health
end
player2 = Player.new('larry', 60)
puts player2.his_name
puts player2.his_name=('lawrence')
,我得到这样的输出:
60
Larry
lawrence #why not Lawrence ?
感谢
'把player2.his_name#=> Lawrence' – xlembouras