Skip to content

Instantly share code, notes, and snippets.

@mkhuda
Last active June 3, 2017 01:25
Show Gist options
  • Select an option

  • Save mkhuda/b83d9e5732d12108e15118fae8455019 to your computer and use it in GitHub Desktop.

Select an option

Save mkhuda/b83d9e5732d12108e15118fae8455019 to your computer and use it in GitHub Desktop.
Creating Array of Hashes with Ruby
def self.create_aoh
aoh_hash = { project: [] }
self.all.each do |order|
aoh_hash[:orders] << {
text: order.texts.pluck(:id),
text_count: order.texts.pluck(:words),
doc: order.documents.pluck(:id),
doc_count: order.documents.pluck(:words)
}
end
return aoh_hash[:project]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment