Created
November 6, 2018 12:40
-
-
Save miyohide/51845505679104c4120a3697383b112f 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
Issue = Struct.new(:id, :name) | |
Note = Struct.new(:id, :issue_id, :name) | |
issue1 = Issue.new(1, "aaa") | |
issue2 = Issue.new(2, "bbb") | |
note1_1 = Note.new(1, 1, "note1-1") | |
note1_2 = Note.new(2, 1, "note1-2") | |
note2_1 = Note.new(3, 2, "note2-1") | |
issues = [issue1, issue2] | |
notes = [note1_1, note1_2, note2_1] | |
p notes.select { |n| n.issue_id == issue1.id } # => [#<struct Note id=1, issue_id=1, name="note1-1">, #<struct Note id=2, issue_id=1, name="note1-2">] | |
p notes.select { |n| n.issue_id == issue2.id } # => [#<struct Note id=3, issue_id=2, name="note2-1">] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment