Hash#keyがRuby 1.8でも使えるようになった
Rubyでハッシュの逆検索を行うHash#keyはRuby 1.9から使えるようになり、それに伴い現行のHash#indexはdeprecatedになる。移行措置もないのにいきなりdeprecatedにするのはあんまりだ。Ruby 1.8.7がRuby 1.9への移行措置だと考えたらRuby 1.8.7にHash#keyを入れるべきだと提案したら受け入れられた^^
RUBY_VERSION # => "1.9.0" hash = {1=>"one", 2=>"two"} hash.key "two" # => 2 hash.index "two" # => 2 # !> Hash#index is deprecated; use Hash#key
# 1.8系最新版 RUBY_VERSION # => "1.8.7" hash = {1=>"one", 2=>"two"} hash.key "two" # => 2 hash.index "two" # => 2 # !> Hash#index is deprecated and will be removed in 1.9; use Hash#key
RUBY_VERSION # => "1.8.7" RUBY_PATCHLEVEL # => 17 hash = {1=>"one", 2=>"two"} hash.index "two" # => 2 hash.key "two" # => # ~> -:5: undefined method `key' for {1=>"one", 2=>"two"}:Hash (NoMethodError)