Class: Bundler::Thor::CoreExt::HashWithIndifferentAccess
Do not use. This class is for internal use only.
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Hash
|
|
Instance Chain:
self,
Hash
|
|
Inherits: |
Hash
|
Defined in: | lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb |
Overview
Class Method Summary
- .new(hash = {}) ⇒ HashWithIndifferentAccess constructor
Instance Method Summary
- #[](key)
- #[]=(key, value)
- #delete(key)
- #except(*keys)
- #fetch(key, *args)
- #key?(key) ⇒ Boolean
- #merge(other)
- #merge!(other)
- #replace(other_hash)
- #reverse_merge(other)
- #reverse_merge!(other_hash)
- #slice(*keys)
-
#to_hash
Convert to a Hash with String keys.
- #values_at(*indices)
- #convert_key(key) protected
-
#method_missing(method, *args)
protected
Magic predicates.
Constructor Details
.new(hash = {}) ⇒ HashWithIndifferentAccess
# File 'lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb', line 12
def initialize(hash = {}) super() hash.each do |key, value| self[convert_key(key)] = value end end
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) (protected)
Magic predicates. For instance:
force? # => !!options['force']
.shebang # => "/usr/lib/local/ruby"
.test_framework?(:rspec) # => options[:test_framework] == :rspec
.
# File 'lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb', line 93
def method_missing(method, *args) method = method.to_s if method =~ /^(\w+)\?$/ if args.empty? !!self[$1] else self[$1] == args.first end else self[method] end end
Instance Method Details
#[](key)
[ GitHub ]# File 'lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb', line 19
def [](key) super(convert_key(key)) end
#[]=(key, value)
[ GitHub ]# File 'lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb', line 23
def []=(key, value) super(convert_key(key), value) end
#convert_key(key) (protected)
[ GitHub ]# File 'lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb', line 83
def convert_key(key) key.is_a?(Symbol) ? key.to_s : key end
#delete(key)
[ GitHub ]# File 'lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb', line 27
def delete(key) super(convert_key(key)) end
#except(*keys)
[ GitHub ]# File 'lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb', line 31
def except(*keys) dup.tap do |hash| keys.each { |key| hash.delete(convert_key(key)) } end end
#fetch(key, *args)
[ GitHub ]# File 'lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb', line 37
def fetch(key, *args) super(convert_key(key), *args) end
#key?(key) ⇒ Boolean
# File 'lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb', line 45
def key?(key) super(convert_key(key)) end
#merge(other)
[ GitHub ]# File 'lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb', line 53
def merge(other) dup.merge!(other) end
#merge!(other)
[ GitHub ]# File 'lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb', line 57
def merge!(other) other.each do |key, value| self[convert_key(key)] = value end self end
#replace(other_hash)
[ GitHub ]# File 'lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb', line 72
def replace(other_hash) super(other_hash) end
#reverse_merge(other)
[ GitHub ]#reverse_merge!(other_hash)
[ GitHub ]# File 'lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb', line 68
def reverse_merge!(other_hash) replace(reverse_merge(other_hash)) end
#slice(*keys)
[ GitHub ]# File 'lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb', line 41
def slice(*keys) super(*keys.map{ |key| convert_key(key) }) end
#to_hash
Convert to a Hash with String keys.
#values_at(*indices)
[ GitHub ]# File 'lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb', line 49
def values_at(*indices) indices.map { |key| self[convert_key(key)] } end