Module: AngryHash::ExtensionAware::ClassMethods
- Defined in:
- lib/angry_hash/extension_aware.rb
Instance Method Summary collapse
- #[](seed) ⇒ Object
- #__convert(hash, cycle_watch = []) ⇒ Object
- #copy_extension(from, to_hash) ⇒ Object
- #dup_with_extension(other) ⇒ Object
-
#extended_with(hash) ⇒ Object
Given a hash, detect whether it’s extended & by which module.
- #new_extended(mod, seed = {}) ⇒ Object
Instance Method Details
#[](seed) ⇒ Object
9 10 11 12 13 |
# File 'lib/angry_hash/extension_aware.rb', line 9 def [](seed) super.tap {|hash| copy_extension(seed,hash) } end |
#__convert(hash, cycle_watch = []) ⇒ Object
15 16 17 18 19 |
# File 'lib/angry_hash/extension_aware.rb', line 15 def __convert(hash,cycle_watch=[]) super.tap {|new_hash| copy_extension(hash,new_hash) } end |
#copy_extension(from, to_hash) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/angry_hash/extension_aware.rb', line 35 def copy_extension(from,to_hash) to_hash.tap {|to| to.extend(from.__angry_hash_extension) if from.respond_to?(:__angry_hash_extension) to.__parent_hash = from.__parent_hash if to.respond_to?(:__parent_hash=) && from.respond_to?(:__parent_hash) } end |
#dup_with_extension(other) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/angry_hash/extension_aware.rb', line 25 def dup_with_extension(other) if AngryHash === other other.respond_to?(:dup_with_extension) ? other.dup_with_extension : other.dup elsif Hash === other dup_with_extension(AngryHash[other]) elsif other.dup end end |
#extended_with(hash) ⇒ Object
Given a hash, detect whether it’s extended & by which module.
43 44 45 |
# File 'lib/angry_hash/extension_aware.rb', line 43 def extended_with(hash) hash.__angry_hash_extension if hash.respond_to?(:__angry_hash_extension) end |
#new_extended(mod, seed = {}) ⇒ Object
21 22 23 |
# File 'lib/angry_hash/extension_aware.rb', line 21 def new_extended(mod,seed={}) self[ seed ].tap {|hash| hash.extend(mod) } end |