我正在经历 Learn Ruby the Hard Way - ex40
目前,代码工作正常。那不是我的问题。我的问题是每次我添加一首新歌。A)我需要在初始化方法中创建一个实例变量。B) 然后,我必须给它一个 attr_reader。
我知道我是否可以 A)不必继续创建新的实例变量,而只需在 Song 类中创建变量。B)不必为每个变量创建一个 attr_reader。
class Song
def initialize()
@jcole_lighter = "Come here, I\'m about to take you higher"
@hold_on_drake = ["Cause you\'re a good girl and you know it",
"You act so different around me",
"Cause you\'re a good girl and you know it"]
end
def sing_me_a_song()
for line in initialize
puts line
end
end
attr_reader :jcole_lighter
attr_reader :hold_on_drake
end
thing = Song.new
puts thing.jcole_lighter()
puts "-"*10
thing= Song.new
puts thing.hold_on_drake()