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.72 lib/knj/hash_methods.rb
knjrbfw-0.0.71 lib/knj/hash_methods.rb
knjrbfw-0.0.70 lib/knj/hash_methods.rb
knjrbfw-0.0.69 lib/knj/hash_methods.rb
knjrbfw-0.0.68 lib/knj/hash_methods.rb
knjrbfw-0.0.67 lib/knj/hash_methods.rb
knjrbfw-0.0.66 lib/knj/hash_methods.rb
knjrbfw-0.0.65 lib/knj/hash_methods.rb
knjrbfw-0.0.64 lib/knj/hash_methods.rb
knjrbfw-0.0.63 lib/knj/hash_methods.rb
knjrbfw-0.0.62 lib/knj/hash_methods.rb
knjrbfw-0.0.59 lib/knj/hash_methods.rb
knjrbfw-0.0.58 lib/knj/hash_methods.rb
knjrbfw-0.0.57 lib/knj/hash_methods.rb
knjrbfw-0.0.55 lib/knj/hash_methods.rb
knjrbfw-0.0.54 lib/knj/hash_methods.rb
knjrbfw-0.0.53 lib/knj/hash_methods.rb
knjrbfw-0.0.52 lib/knj/hash_methods.rb
knjrbfw-0.0.51 lib/knj/hash_methods.rb
knjrbfw-0.0.50 lib/knj/hash_methods.rb