Class: CaptainHoog::Struct

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/captain_hoog/struct/hoog_struct.rb

Direct Known Subclasses

Hoogfile

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



13
14
15
16
17
18
19
# File 'lib/captain_hoog/struct/hoog_struct.rb', line 13

def method_missing(method_name, *args, &block)
  if self.to_h.respond_to?(method_name)
    self.to_h.stringify_keys.send(method_name.to_s, *args, &block)
  else
    super
  end
end

Instance Method Details

#fetch(key, default = nil) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/captain_hoog/struct/hoog_struct.rb', line 4

def fetch(key, default = nil)
  if not self.respond_to?(key)
    raise IndexError unless default
    return default
  else
    self.public_send(key)
  end
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/captain_hoog/struct/hoog_struct.rb', line 21

def respond_to_missing?(method_name, include_private = false)
  self.to_h.respond_to?(method_name) || super
end