Class: Hashi::CustomHash

Inherits:
Object
  • Object
show all
Defined in:
lib/hashi.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#hashObject (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