Skip to content

Instantly share code, notes, and snippets.

@pabloh
Created December 17, 2011 07:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pabloh/1489603 to your computer and use it in GitHub Desktop.
Save pabloh/1489603 to your computer and use it in GitHub Desktop.
# 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