Class: Hashi::CustomHash
- Inherits:
-
Object
- Object
- Hashi::CustomHash
- Defined in:
- lib/hashi.rb
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
Instance Method Summary collapse
- #[](x) ⇒ Object
-
#initialize(h) ⇒ CustomHash
constructor
A new instance of CustomHash.
- #method_missing(name, *args) ⇒ Object
Constructor Details
#initialize(h) ⇒ CustomHash
Returns a new instance of CustomHash.
6 7 8 |
# File 'lib/hashi.rb', line 6 def initialize(h) @hash = h end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/hashi.rb', line 9 def method_missing(name, *args) name = name.to_s if name.kind_of? Symbol if name[-1,1] == "=" name = name.chop @hash[name] = args[0] else transform(@hash[name]) end end |
Instance Attribute Details
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
4 5 6 |
# File 'lib/hashi.rb', line 4 def hash @hash end |
Instance Method Details
#[](x) ⇒ Object
18 19 20 |
# File 'lib/hashi.rb', line 18 def [](x) transform(@hash[x]) end |