Sha256: 61d57d454d453422ea2f695d8b6e9caf74926e90b766dc89cae8c97e87d6003a

Contents?: true

Size: 767 Bytes

Versions: 28

Compression:

Stored size: 767 Bytes

Contents

class HashObject
  attr_accessor :hash
  
  def initialize(hash = {})
    @hash = HashWithIndifferentAccess.new(hash)
  end
  
  def id            ; @hash['id']           ; end
  def id=(val)      ; @hash['id'] = val     ; end
  
  def [](key)       ; @hash[key.to_s]       ; end
  def []=(key, val) ; @hash[key.to_s] = val ; end
  
  def delete(key)   ; @hash.delete(key)     ; end
  
  def rename_key(key, new_key)
    @hash[new_key.to_s] = @hash[key]
    @hash.delete(key)
  end
  
  def each(&block)
    @hash.each { |k,v| yield(k,v) }
  end
  
  def method_missing(method_id, *args)
    key = method_id.id2name.to_s
    
    if key[-1, 1] == '='
      key.slice!(-1, 1)
      val = args.shift
      @hash[key] = val
    else
      @hash[key]
    end
  end
  
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
imagine_cms-3.0.15 lib/hash_object.rb
imagine_cms-3.0.14 lib/hash_object.rb
imagine_cms-3.0.13 lib/hash_object.rb
imagine_cms-3.0.12 lib/hash_object.rb
imagine_cms-3.0.11 lib/hash_object.rb
imagine_cms-3.0.10 lib/hash_object.rb
imagine_cms-3.0.9 lib/hash_object.rb
imagine_cms-3.0.8 lib/hash_object.rb
imagine_cms-3.0.7 lib/hash_object.rb
imagine_cms-3.0.6 lib/hash_object.rb
imagine_cms-3.0.5 lib/hash_object.rb
imagine_cms-3.0.4 lib/hash_object.rb
imagine_cms-3.0.3 lib/hash_object.rb
imagine_cms-3.0.2 lib/hash_object.rb
imagine_cms-3.0.1 lib/hash_object.rb
imagine_cms-3.0.0 lib/hash_object.rb
imagine_cms-3.0.0.beta13 lib/hash_object.rb
imagine_cms-3.0.0.beta12 lib/hash_object.rb
imagine_cms-3.0.0.beta11 lib/hash_object.rb
imagine_cms-3.0.0.beta10 lib/hash_object.rb