Skip to content

Instantly share code, notes, and snippets.

@farleyknight
Forked from anonymous/hash.rb
Created May 30, 2011 03:09
Show Gist options
  • Save farleyknight/998401 to your computer and use it in GitHub Desktop.
Save farleyknight/998401 to your computer and use it in GitHub Desktop.
def index
@carriers = Carrier.all.sort_by(&:name)
@lines = Array.new
@carriers.each do |c|
c.sw_profiles.each do |p|
@lines.push(prepend_hash_keys("carrier", c.attributes).merge(prepend_hash_keys("sw_profile", p.attributes)))
end
end
end
def prepend_hash_keys(name, hash)
h = {}
hash.each do |k, v|
h["#{name}_#{k}"] = v
end
h
end
# which results in
[{Carrier id: ... name: ...} => {SWProfile id: ... name: ...}...]
# what I need is a new Array:
[{NewHash carrier_id: ... carrier_name: ... sw_profile_name: ... ...}, {} ...]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment