I have an hash consisting of:
flow = ["a", "b", "c"]
h = [{"case_id"=>1, "a"=>{"x"=>"text", "option"=>"..." },"b"=>{"report"=>"text", "option"=>"..." } ,"c"=>{"y"=>"text", "option"=>"..." }},{"case_id"=>2, "a"=>{"x"=>"text", "option"=>"..." },"b"=>{"report"=>"text", "option"=>"..." } ,"c"=>{"y"=>"text", "option"=>"..." }}]
@case = 0
@report = ""
flow.each do |step|
if h[@case][step]['report']
@report = h[@case][step]['report']
end
end
the console gives me the following error:
NoMethodError in MainController#index
undefined method `[]' for nil:NilClass
Why?! In a previous program, but using ruby 187, gave no problem. But now, with ruby 193, gives this error.
Ruby has some great iteration helper provided by enumeration class
http://www.ruby-doc.org/core-1.9.3/Array.html#method-i-each