class Knj::Hash_methods

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

Public Class Methods

new(hash = {}) click to toggle source

Spawns the object and takes a hash as argument.

# File lib/knj/hash_methods.rb, line 7
def initialize(hash = {})
  self.update(hash)
end

Public Instance Methods

args() click to toggle source

Returns the args-key.

# File lib/knj/hash_methods.rb, line 22
def args
  return self[:args]
end
data() click to toggle source

Returns the data-key.

# File lib/knj/hash_methods.rb, line 27
def data
  return self[:data]
end
db() click to toggle source

Returns the db-key.

# File lib/knj/hash_methods.rb, line 12
def db
  return self[:db]
end
method_missing(method, *args) click to toggle source

Proxies methods into the hash as keys.

# File lib/knj/hash_methods.rb, line 41
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
ob() click to toggle source

Returns the ob-key.

# File lib/knj/hash_methods.rb, line 17
def ob
  return self[:ob]
end
to_hash() click to toggle source
# File lib/knj/hash_methods.rb, line 31
def to_hash
  h = {}
  self.each do |key, val|
    h[k] = val
  end
  
  return h
end