Created
December 5, 2012 20:08
-
-
Save canadaduane/4219039 to your computer and use it in GitHub Desktop.
Make an Iterator
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
# Here's my method that loops over a collection and yields a block | |
def tardies_for_student(student_id, now=Time.zone.now) | |
submissions_by_student_id[student_id].each do |submission| | |
assignment = @assignments_by_id[submission.assignment_id] | |
yield build_tardy(assignment, submission, now) | |
end | |
end | |
# now I know I can do this... | |
tardies_for_student(1) do |tardy| | |
# do something with tardy | |
end | |
# but I want to be able to do this... | |
tardies_for_student(1).each do |tardy| | |
# do something with tardy | |
end | |
# OR | |
tardies_for_student(1).map do |tardy| | |
# do something with tardy | |
end |
jenseng
commented
Dec 5, 2012
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment