Project

General

Profile

Actions

Bug #10180

closed

#to_hash vs. #to_h

Added by herwinw (Herwin Quarantainenet) over 9 years ago. Updated over 9 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
2.1.2p95
[ruby-core:64605]

Description

The class Hash has a method try_convert, that is documented as "Try to convert obj into a hash, using #to_hash method." Surpisingly, the Array class doesn't have a method to_hash, but it does have a method to_h which converts it into a Hash. This looks like there are two possible methods with different names, but with the same expected behaviour, which breaks some usage of Hash#try_convert.

Updated by matz (Yukihiro Matsumoto) over 9 years ago

  • Status changed from Open to Rejected

Ruby often has two conversion methods for an object, e.g. #to_s and #to_str, #to_i and #to_int, #to_h and #to_hash.
The former is used for explicit conversion, the latter is used for implicit conversion (from an object with identical method signature e.g. proxy).

Matz.

Actions

Also available in: Atom PDF

Like0
Like0