Created
December 17, 2011 07:48
-
-
Save pabloh/1489603 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Instant result methods w/block (and different arities) | |
[ [ %w[partition group_by sort_by min_by max_by minmax_by | |
any? one? all? none?], ""], | |
[ %w[each_slice each_cons each_with_object], "arg" ], | |
[ %w[each_with_index reverse_each each_entry find | |
detect find_index], "*args"] ].each do |methods, arguments| | |
methods.each do |method| | |
class_eval <<-METHOD_DEF | |
def #{method} #{arguments} | |
block_given? ? super : to_lazy_enum(:#{method}) | |
end | |
METHOD_DEF | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment