Ruby, Map, Object attributes

ruby, ruby-on-rails, ruby-on-rails-3

Solution

(@report_times.keys + @weekly_stats.keys).map do |attribute_name|
  {
    :name => attribute_name.upcase,
    :content => @report_times[attribute_name] ? format_date(@report_times[attribute_name]) : @weekly_stats[attribute_name] || "Not Currently Available"
  }
end

Problem

I have an object that looks like the below: ``` class Report attr_accessor :weekly_stats, :report_times def initialize @weekly_stats = Hash.new {|h, k| h[k]={}} @report_times = Hash.new {|h, k| h[k]={}} values = [] end end ``` I want to loop through the weekly_stats and report_times and upcase each key and assign it its value. Right now I have this: ``` report.weekly_stats.map do |attribute_name, value| report.values << { :name => attribute_name.upcase, :content => value ||= "Not Currently Available" } end report.report_times.map do |attribute_name, value| report.values << { :name => attribute_name.upcase, :content => format_date(value) } end report.values ``` Is there a way I could map both the weekly stats and report times in one loop? Thanks

Original source