Sha256: 1afaf3b401e087c263eb14988932c635cbb190f5fb794c87955de4963d4a6592

Contents?: true

Size: 1002 Bytes

Versions: 40

Compression:

Stored size: 1002 Bytes

Contents

#A normal hash that uses 'method_missing' to be able to call keys by using methods. It is heavily used by Knj::Objects and have some pre-defined methods because of it to optimize performance.
#===Examples
# hm = Knj::Hash_methods(:test => "Test")
# print hm.test
class Knj::Hash_methods < Hash
  #Spawns the object and takes a hash as argument.
  def initialize(hash = {})
    self.update(hash)
  end
  
  #Returns the db-key.
  def db
    return self[:db]
  end
  
  #Returns the ob-key.
  def ob
    return self[:ob]
  end
  
  #Returns the args-key.
  def args
    return self[:args]
  end
  
  #Returns the data-key.
  def data
    return self[:data]
  end
  
  def to_hash
    h = {}
    self.each do |key, val|
      h[k] = val
    end
    
    return h
  end
  
  #Proxies methods into the hash as keys.
  def method_missing(method, *args)
    method = method.to_sym
    return self[method] if self.key?(method)
    
    raise "No such method '#{method}' on class '#{self.class.name}'"
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
knjrbfw-0.0.116 lib/knj/hash_methods.rb
knjrbfw-0.0.115 lib/knj/hash_methods.rb
knjrbfw-0.0.114 lib/knj/hash_methods.rb
knjrbfw-0.0.113 lib/knj/hash_methods.rb
knjrbfw-0.0.111 lib/knj/hash_methods.rb
knjrbfw-0.0.110 lib/knj/hash_methods.rb
knjrbfw-0.0.109 lib/knj/hash_methods.rb
knjrbfw-0.0.108 lib/knj/hash_methods.rb
knjrbfw-0.0.107 lib/knj/hash_methods.rb
knjrbfw-0.0.105 lib/knj/hash_methods.rb
knjrbfw-0.0.104 lib/knj/hash_methods.rb
knjrbfw-0.0.103 lib/knj/hash_methods.rb
knjrbfw-0.0.102 lib/knj/hash_methods.rb
knjrbfw-0.0.101 lib/knj/hash_methods.rb
knjrbfw-0.0.100 lib/knj/hash_methods.rb
knjrbfw-0.0.99 lib/knj/hash_methods.rb
knjrbfw-0.0.98 lib/knj/hash_methods.rb
knjrbfw-0.0.97 lib/knj/hash_methods.rb
knjrbfw-0.0.96 lib/knj/hash_methods.rb
knjrbfw-0.0.95 lib/knj/hash_methods.rb