Last active
December 4, 2018 20:07
-
-
Save rbrigby/8dbe3a52218e093b8317 to your computer and use it in GitHub Desktop.
Ruby Loops and Tricks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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