Created
February 27, 2015 22:01
-
-
Save jongillies/651464b395ab8830610a to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
Payment = Struct.new(:payee, :amount, :tags) | |
Dateline = Struct.new(:date) | |
TRANSACTIONS = [ | |
Dateline.new("2015-01-01"), | |
Payment.new("Milliways", 25476, "dining travel"), | |
Payment.new("Sirius Cybernetics", 7839), | |
Payment.new("Old Pink Dog Bar", 2790, "dining"), | |
Dateline.new("2015-01-02"), | |
Payment.new("Magrathea", 49900000000000000, "real-estate"), | |
Payment.new("Big Bang Burger Bar", 4780), | |
Payment.new("Megadodo", 7850, "travel"), | |
] | |
# So you have an array of objects that contain 2 different object types. | |
# So you want just the payments? | |
puts TRANSACTIONS.grep(Payment) | |
# Think about that for a second... | |
# You did not pass grep a string, you passed in an struct object class. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment