Skip to content

How about supporting Thor::CoreExt::HashWithIndifferentAccess#slice method? #804

@shuuuuun

Description

@shuuuuun

When extracting a part of options hash in a Thor command, options.slice(:foo) does not work as expected.
Wouldn't it be more intuitive to support the Thor::CoreExt::HashWithIndifferentAccess#slice method?

require 'thor'

hash = Thor::CoreExt::HashWithIndifferentAccess.new 'foo' => 'bar'

hash['foo'] #=> 'bar'
hash[:foo]  #=> 'bar'
hash.slice('foo') #=> {'foo'=>'bar'}
hash.slice(:foo)  #=> {}

As a side note, ActiveSupport::HashWithIndifferentAccess works as expected.

require 'active_support/core_ext/hash/indifferent_access'

hash = ActiveSupport::HashWithIndifferentAccess.new 'foo' => 'bar'

hash['foo'] #=> 'bar'
hash[:foo]  #=> 'bar'
hash.slice('foo') #=> {'foo'=>'bar'}
hash.slice(:foo)  #=> {'foo'=>'bar'}

I checked with thor v1.2.1 and current main branch.
https://github.com/rails/thor/blob/v1.2.1/lib/thor/core_ext/hash_with_indifferent_access.rb
https://github.com/rails/thor/blob/e4907fdd663d0a1ff51d18eb1827552ee61300a3/lib/thor/core_ext/hash_with_indifferent_access.rb

Thank you. 🌈

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions