我正在学习红宝石的艰难之路- ex40
目前,代码工作正常。这不是我的问题。我的问题是每次我加一首新歌。我需要在初始化方法中创建一个实例变量。然后,我得给它一个attr_reader。
如果可以的话,我知道的是,( A)不必继续创建新的实例变量,而只需在Song类中创建变量。)不必为每个变量创建一个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()https://stackoverflow.com/questions/19529219
复制相似问题