Class: ActiveReport::HashEntry

Inherits:
Hash
  • Object
show all
Defined in:
lib/active_report/base.rb

Overview

Special form of a hash that responds to methods if the method is a key in the entry. Also allows passing a hash as the argement to new to allow for initialization of the HashEntry.

Note: This means you should not have keys whose name is the name of an existing Hash method.

Instance Method Summary collapse

Constructor Details

#initialize(hash = nil) ⇒ HashEntry

Returns a new instance of HashEntry.



10
11
12
13
14
# File 'lib/active_report/base.rb', line 10

def initialize(hash = nil)
  super
  
  self.update(hash) unless has.nil?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args, &block) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/active_report/base.rb', line 16

def method_missing(symbol, *args, &block)
  if self[symbol]
    self[symbol]
  else
    super
  end
end

Instance Method Details

#respond_to?(symbol, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
# File 'lib/active_report/base.rb', line 24

def respond_to?(symbol, include_private = false)
  if self[symbol]
    true
  else
    super
  end
end