Project

General

Profile

Feature #16697

Hash.ruby2_keywords_hash?(value) should support any object

Added by Eregon (Benoit Daloze) 9 months ago. Updated 3 days ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
[ruby-core:97554]

Description

But currently it raises, which makes it needlessly inconvenient to use:

> Hash.ruby2_keywords_hash?({})
=> false
> Hash.ruby2_keywords_hash?("hello")
Traceback (most recent call last):
        5: from /home/eregon/.rubies/ruby-trunk/bin/irb:23:in `<main>'
        4: from /home/eregon/.rubies/ruby-trunk/bin/irb:23:in `load'
        3: from /home/eregon/prefix/ruby-trunk/lib/ruby/gems/2.8.0/gems/irb-1.2.3/exe/irb:11:in `<top (required)>'
        2: from (irb):4
        1: from (irb):4:in `ruby2_keywords_hash?'
TypeError (wrong argument type String (expected Hash))

See https://github.com/ruby/ruby/pull/2966/files#r394741112 for a motivating example.

I'd like to suggest backporting this to 2.7 too.

#1

Updated by hsbt (Hiroshi SHIBATA) 2 months ago

  • Target version changed from 36 to 3.0

Updated by jbeschi (jacopo beschi) 4 days ago

I'd like to contribute here but I'm new to this so please forgive me if this is a stupid question: we basically just need to change ruby2_keywords_hash? to return false if the argument is not an Hash instead of raising a TypeError ?

Updated by Eregon (Benoit Daloze) 3 days ago

I think we need to decide if this change is accepted, I'll add it to the dev meeting agenda.

Indeed, the concrete change would just be that, feel free to give it a try.

#4

Updated by Eregon (Benoit Daloze) 3 days ago

  • Backport deleted (2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN)
  • ruby -v deleted (ruby 2.8.0dev (2020-02-28T14:32:56Z master f7be85a2b7) [x86_64-linux])
  • Tracker changed from Bug to Feature

Updated by jbeschi (jacopo beschi) 3 days ago

Thanks! I'll give it a try :-)

Also available in: Atom PDF