Class: MethodedHash
- Inherits:
-
Hash
- Object
- Hash
- MethodedHash
- Defined in:
- lib/ruby/extensions/methoded_hash.rb
Overview
MethodedHash
is a subclass of Hash which basically will create an accessor method for every key in the hash, transforming all sub-hashes into MethodedHash
classes and so on (recursive).
Please note: it will NOT add a method if the method already exist.
Class Method Summary collapse
-
.create(h = {}) ⇒ Object
create(h = {}).
Instance Method Summary collapse
- #[]=(key, value) ⇒ Object
-
#initialize(h = {}) ⇒ MethodedHash
constructor
A new instance of MethodedHash.
Constructor Details
#initialize(h = {}) ⇒ MethodedHash
Returns a new instance of MethodedHash.
12 13 14 15 |
# File 'lib/ruby/extensions/methoded_hash.rb', line 12 def initialize(h = {}) duplicate_hash(h) self end |
Class Method Details
.create(h = {}) ⇒ Object
create(h = {})
create
force-creates a MethodedHash class, avoiding potential conflicts with children classes. However it can be overridden by children classes if needed.
73 74 75 |
# File 'lib/ruby/extensions/methoded_hash.rb', line 73 def create(h = {}) MethodedHash.new(h) end |
Instance Method Details
#[]=(key, value) ⇒ Object
17 18 19 20 |
# File 'lib/ruby/extensions/methoded_hash.rb', line 17 def []=(key, value) super common_methodizer(key) end |