Skip to content

Instantly share code, notes, and snippets.

@rbrigby
Last active December 4, 2018 20:07
Show Gist options
  • Save rbrigby/8dbe3a52218e093b8317 to your computer and use it in GitHub Desktop.
Save rbrigby/8dbe3a52218e093b8317 to your computer and use it in GitHub Desktop.
Ruby Loops and Tricks
thing_list = []
f = File.open("/Users/ryan/Desktop/foobar.log", "r")
f.each_line do |line|
foo = Foo.where(id: 3).first
thing_hash = {}
if foo
thing_hash = {id: foo.id, stuff: foo.stuff}
thing_list << thing_hash
end
end
File.open("/Users/ryan/Desktop/stuff_list.txt", "w") do |f|
stuff_list.each do |thing|
f.write "#{thing} " + "\n"
end
end
@unicorns = Color.where(id: [1,2,3]).joins(:color_types).map(&:name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment