top
、top_middle
、bottom_middle
およびbottom
は 4 つの長い文字列です。
current
の文字列値が - で使用されている変数の名前と同じであるがthe_line
、実際の変数ではない場合、次をどのように DRY できますか。
それが何であるかについて、ある種の「variable.variable_name」はありますか?
[top,top_middle,bottom_middle,bottom].each_with_index do |the_line, i|
current=
case i
when 0 then "top"
when 1 then "top_middle"
when 2 then "bottom_middle"
when 3 then "bottom"
end
puts current
puts the_line
end
出力はそのままで問題ありません:
top
―― | ―― ―― | | ―― | ―― ―― ――
top_middle
| | | __| __| |__| |__ |__ | |__| |__|
bottom_middle
| | | | | | | | | | | | |
bottom
―― | ―― ―― | ―― ―― | ―― |