Sha256: 2859e0c8069d49ca186566d87b7ae6caa7ef414e12fc3433294a9a23a42af5e5

Contents?: true

Size: 820 Bytes

Versions: 31

Compression:

Stored size: 820 Bytes

Contents

class HashObject
  attr_accessor :hash
  
  def initialize(hash = {})
    @hash = HashWithIndifferentAccess.new(hash)
  end
  
  def empty?        ; @hash.keys.empty?     ; 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

31 entries across 31 versions & 1 rubygems

Version Path
imagine_cms-4.2.4 lib/hash_object.rb
imagine_cms-4.1.4 lib/hash_object.rb
imagine_cms-4.2.3 lib/hash_object.rb
imagine_cms-4.2.2 lib/hash_object.rb
imagine_cms-4.2.1 lib/hash_object.rb
imagine_cms-4.2.0 lib/hash_object.rb
imagine_cms-4.1.3 lib/hash_object.rb
imagine_cms-4.1.2 lib/hash_object.rb
imagine_cms-4.1.1 lib/hash_object.rb
imagine_cms-4.1.0 lib/hash_object.rb
imagine_cms-4.0.1 lib/hash_object.rb
imagine_cms-4.0.0 lib/hash_object.rb
imagine_cms-3.0.33 lib/hash_object.rb
imagine_cms-3.0.32 lib/hash_object.rb
imagine_cms-3.0.31 lib/hash_object.rb
imagine_cms-3.0.30 lib/hash_object.rb
imagine_cms-3.0.29 lib/hash_object.rb
imagine_cms-3.0.28 lib/hash_object.rb
imagine_cms-3.0.27 lib/hash_object.rb
imagine_cms-3.0.26 lib/hash_object.rb