Project

General

Profile

Actions

Bug #10180

closed

#to_hash vs. #to_h

Added by herwinw (Herwin Quarantainenet) over 10 years ago. Updated over 10 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 10 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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy