#eachを使ったら負け

 #eachを使ったら負け

Enumerable使いましょう!

each指数スクリプト:https://gist.github.com/3008383

※2012/6/28の会社内LTで使用した資料

70762059db0218c6f0ff48042ca0756a?s=128

Leonard Chin

June 27, 2012
Tweet

Transcript

  1. 7.

    Enumerable.instance_methods.sort => [:all?, :any?, :chunk, :collect, :collect_concat, :count, :cycle, :detect,

    :drop, :drop_while, :each_cons, :each_entry, :each_slice, :each_with_index, :each_with_object, :entries, :find, :find_all, :find_index, :first, :flat_map, :grep, :group_by, :include?, :inject, :map, :max, :max_by, :member?, :min, :min_by, :minmax, :minmax_by, :none?, :one?, :partition, :reduce, :reject, :reverse_each, :select, :slice_before, :sort, :sort_by, :take, :take_while, :to_a, :zip]
  2. 10.
  3. 11.
  4. 21.

    #each_with_object # Better than inject for building hashes %w(one two

    three).each_with_object({}) {|w, hash| hash[word] = word.length } # => {"one"=>3, "two"=>3, "three"=>5}