Class: AutoHash

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

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ AutoHash

Returns a new instance of AutoHash.



3
4
5
6
# File 'lib/auto_hash.rb', line 3

def initialize(*args)
  super()
  @update, @update_index = args[0][:update], args[0][:update_key] unless args.empty?
end

Instance Method Details

#[](k) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/auto_hash.rb', line 8

def [](k)
  if self.has_key?k
    super(k)
  else
    AutoHash.new(:update => self, :update_key => k)
  end
end

#[]=(k, v) ⇒ Object



16
17
18
19
# File 'lib/auto_hash.rb', line 16

def []=(k, v)
  @update[@update_index] = self if @update and @update_index
  super
end