Upgrade to Pro — share decks privately, control downloads, hide ads and more …

#eachを使ったら負け

 #eachを使ったら負け

Enumerable使いましょう!

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

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

Leonard Chin

June 27, 2012
Tweet

More Decks by Leonard Chin

Other Decks in Programming

Transcript

  1. #eachΛ࢖ͬͨΒෛ͚

    View full-size slide

  2. GPSΛ࢖͍·͠ΐ͏

    View full-size slide

  3. ʜ͡Όͳͯ͘

    View full-size slide

  4. FBDIΛ࢖͏ͱ͍͏͜ͱ͸

    View full-size slide

  5. &OVNFSBCMFΛ࢖͍ͬͯͳ͍ͬͯ͜ͱ

    View full-size slide

  6. &OVNFSBCMFΛ΋ͬͱ࢖͍·͠ΐ͏

    View full-size slide

  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]

    View full-size slide

  8. IUUQTHJTUHJUIVCDPN

    View full-size slide

  9. ஫ҙɿશવݡ͘ͳ͍ूܭํ๏

    View full-size slide

  10. ack --no-group --ruby
    "[\s\.\{\(=]"

    View full-size slide

  11. &OVNFSBCMFͷϝιου໊ͱ
    ඃͬͨΒ਺͑ͯ͠·͏

    View full-size slide

  12. ΋ͬͱ&OVNFSBCMFʹ͍ͭͯ஌Γ͍ͨਓ΁

    View full-size slide

  13. IUUQSVCZEPDPSHDPSF&OVNFSBCMFIUNM

    View full-size slide

  14. 3VCJOJVT
    kernel/common/enumerable*.rb

    View full-size slide

  15. ͓·͚ɿ
    ͓͢͢Ίͷ&OVNFSBCMFϝιου

    View full-size slide

  16. #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}

    View full-size slide