Hatena::Groupruby

mrのRuby学習帳 このページをアンテナに追加 RSSフィード

2009-09-26

arrayのdetectメソッド arrayのdetectメソッド - mrのRuby学習帳 を含むブックマーク

irb(main):001:0> a = ["a","b","c","a","b","c"]
=> ["a", "b", "c", "a", "b", "c"]
irb(main):002:0> a.detect("b")
LocalJumpError: no block given
        from (irb):2:in `detect'
        from (irb):2:in `each'
        from (irb):2:in `detect'
        from (irb):2
irb(main):003:0> a.detect{|x| x = "b"}
=> "a"
irb(main):004:0> a.detect{|x| x = "c"}
=> "a"
irb(main):005:0> a.detect{|x| x == "c"}
=> "c"

比較は==だった。