Class: Structish::Hash
- Includes:
- Validations
- Defined in:
- lib/structish/hash.rb
Instance Method Summary collapse
- #compact ⇒ Object
- #except(*except_keys) ⇒ Object
- #except!(*except_keys) ⇒ Object
-
#initialize(raw_constructor = {}) ⇒ Hash
constructor
A new instance of Hash.
- #merge(other) ⇒ Object
- #merge!(other) ⇒ Object
Methods included from Validations
Methods inherited from Hash
Constructor Details
#initialize(raw_constructor = {}) ⇒ Hash
Returns a new instance of Hash.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/structish/hash.rb', line 6 def initialize(raw_constructor = {}) raise(ArgumentError, "Only hash-like objects can be used as constructors for Structish::Hash") unless raw_constructor.respond_to?(:to_hash) constructor = self.class.symbolize? ? raw_constructor.symbolize_keys : raw_constructor hash = constructor.to_h validate_structish(hash) super() update(hash) self.default = hash.default if hash.default self.default_proc = hash.default_proc if hash.default_proc end |
Instance Method Details
#compact ⇒ Object
36 37 38 |
# File 'lib/structish/hash.rb', line 36 def compact self.class.new(to_h.compact) end |
#except(*except_keys) ⇒ Object
27 28 29 |
# File 'lib/structish/hash.rb', line 27 def except(*except_keys) self.class.new(to_h.except(*except_keys)) end |
#except!(*except_keys) ⇒ Object
31 32 33 34 |
# File 'lib/structish/hash.rb', line 31 def except!(*except_keys) super(*except_keys) validate_structish(self) end |
#merge(other) ⇒ Object
18 19 20 |
# File 'lib/structish/hash.rb', line 18 def merge(other) self.class.new(to_h.merge(other)) end |
#merge!(other) ⇒ Object
22 23 24 25 |
# File 'lib/structish/hash.rb', line 22 def merge!(other) super(other) validate_structish(self) end |