Skip to content

Instantly share code, notes, and snippets.

@pabloh
Created December 17, 2011 07:48
Show Gist options
  • Select an option

  • Save pabloh/1489603 to your computer and use it in GitHub Desktop.

Select an option

Save pabloh/1489603 to your computer and use it in GitHub Desktop.

Revisions

  1. pabloh renamed this gist Dec 17, 2011. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. pabloh created this gist Dec 17, 2011.
    15 changes: 15 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    # 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