Class: HashWithIndifferentAccess
- Inherits:
-
Hash
- Object
- Hash
- HashWithIndifferentAccess
- Defined in:
- lib/irc_cat/indifferent_access.rb
Overview
Direct Known Subclasses
Instance Method Summary collapse
- #[]=(key, value) ⇒ Object
- #default(key = nil) ⇒ Object
- #delete(key) ⇒ Object
- #dup ⇒ Object
- #fetch(key, *extras) ⇒ Object
-
#initialize(constructor = {}) ⇒ HashWithIndifferentAccess
constructor
A new instance of HashWithIndifferentAccess.
- #key?(key) ⇒ Boolean (also: #include?, #has_key?, #member?)
- #merge(hash) ⇒ Object
- #regular_update ⇒ Object
- #regular_writer ⇒ Object
- #stringify_keys! ⇒ Object
- #symbolize_keys! ⇒ Object
- #update(other_hash) ⇒ Object (also: #merge!)
- #values_at(*indices) ⇒ Object
Constructor Details
#initialize(constructor = {}) ⇒ HashWithIndifferentAccess
Returns a new instance of HashWithIndifferentAccess.
5 6 7 8 9 10 11 12 |
# File 'lib/irc_cat/indifferent_access.rb', line 5 def initialize(constructor = {}) if constructor.is_a?(Hash) super() update(constructor) else super(constructor) end end |
Instance Method Details
#[]=(key, value) ⇒ Object
25 26 27 |
# File 'lib/irc_cat/indifferent_access.rb', line 25 def []=(key, value) regular_writer(convert_key(key), convert_value(value)) end |
#default(key = nil) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/irc_cat/indifferent_access.rb', line 14 def default(key = nil) if key.is_a?(Symbol) && include?(key = key.to_s) self[key] else super end end |
#delete(key) ⇒ Object
60 61 62 |
# File 'lib/irc_cat/indifferent_access.rb', line 60 def delete(key) super(convert_key(key)) end |
#dup ⇒ Object
52 53 54 |
# File 'lib/irc_cat/indifferent_access.rb', line 52 def dup HashWithIndifferentAccess.new(self) end |
#fetch(key, *extras) ⇒ Object
44 45 46 |
# File 'lib/irc_cat/indifferent_access.rb', line 44 def fetch(key, *extras) super(convert_key(key), *extras) end |
#key?(key) ⇒ Boolean Also known as: include?, has_key?, member?
36 37 38 |
# File 'lib/irc_cat/indifferent_access.rb', line 36 def key?(key) super(convert_key(key)) end |
#merge(hash) ⇒ Object
56 57 58 |
# File 'lib/irc_cat/indifferent_access.rb', line 56 def merge(hash) self.dup.update(hash) end |
#regular_update ⇒ Object
23 |
# File 'lib/irc_cat/indifferent_access.rb', line 23 alias_method :regular_update, :update |
#regular_writer ⇒ Object
22 |
# File 'lib/irc_cat/indifferent_access.rb', line 22 alias_method :regular_writer, :[]= |
#stringify_keys! ⇒ Object
64 |
# File 'lib/irc_cat/indifferent_access.rb', line 64 def stringify_keys!; self end |
#symbolize_keys! ⇒ Object
65 |
# File 'lib/irc_cat/indifferent_access.rb', line 65 def symbolize_keys!; self end |
#update(other_hash) ⇒ Object Also known as: merge!
29 30 31 32 |
# File 'lib/irc_cat/indifferent_access.rb', line 29 def update(other_hash) other_hash.each_pair { |key, value| regular_writer(convert_key(key), convert_value(value)) } self end |
#values_at(*indices) ⇒ Object
48 49 50 |
# File 'lib/irc_cat/indifferent_access.rb', line 48 def values_at(*indices) indices.collect {|key| self[convert_key(key)]} end |