Sha256: d615ea0d8e037b60c1f946277940aad36486c3d2e1d470c93216d068eeccc66f

Contents?: true

Size: 897 Bytes

Versions: 40

Compression:

Stored size: 897 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
  
  #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.49 lib/knj/hash_methods.rb
knjrbfw-0.0.48 lib/knj/hash_methods.rb
knjrbfw-0.0.47 lib/knj/hash_methods.rb
knjrbfw-0.0.46 lib/knj/hash_methods.rb
knjrbfw-0.0.45 lib/knj/hash_methods.rb
knjrbfw-0.0.44 lib/knj/hash_methods.rb
knjrbfw-0.0.43 lib/knj/hash_methods.rb
knjrbfw-0.0.42 lib/knj/hash_methods.rb
knjrbfw-0.0.41 lib/knj/hash_methods.rb
knjrbfw-0.0.40 lib/knj/hash_methods.rb
knjrbfw-0.0.39 lib/knj/hash_methods.rb
knjrbfw-0.0.38 lib/knj/hash_methods.rb
knjrbfw-0.0.37 lib/knj/hash_methods.rb
knjrbfw-0.0.36 lib/knj/hash_methods.rb
knjrbfw-0.0.35 lib/knj/hash_methods.rb
knjrbfw-0.0.34 lib/knj/hash_methods.rb
knjrbfw-0.0.33 lib/knj/hash_methods.rb
knjrbfw-0.0.32 lib/knj/hash_methods.rb
knjrbfw-0.0.31 lib/knj/hash_methods.rb
knjrbfw-0.0.30 lib/knj/hash_methods.rb