Class: MstdnIvory::DotAccessableHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/mstdn_ivory/dot_accessable_hash.rb

Overview

This class inherit hash. The value is accessed by key name method:

dah = DotAccessableHash.new
dah['strkey'] = 'strvalue'
dah[:symkey] = :symkey
dah.strkey # => "strvalue"
dah.symkey # => :symkey

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



10
11
12
13
# File 'lib/mstdn_ivory/dot_accessable_hash.rb', line 10

def method_missing(name)
  super unless self.has_key?(name) || self.has_key?(name.to_s)
  self[name.to_s] || self[name]
end

Instance Method Details

#respond_to_missing?(name) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/mstdn_ivory/dot_accessable_hash.rb', line 15

def respond_to_missing?(name)
  return self.has_key?(name) || self.has_key?(name.to_s)
end