我想知道是否有一個優雅的方式來創建變量使用循環在紅寶石?用循環創建多個變量?
說我想要把這個在某種循環
def workhours
@monday = blah
@tuesday = brah
@wednesday = bro
@thursday = blap
@friday = blagh
end
的我希望能夠做
def workhour_ideally
days = [ "monday", "tuesday", "wednesday", "thursday", "friday" ]
days.each do |smack|
@"smack" = whatever
end
end
這可能與紅寶石?
相關問題:http://stackoverflow.com/questions/1778638/idiomatic-object-creation-in-ruby – 2012-01-04 22:40:00