Module: Finest::Struct

Includes:
Helper
Defined in:
lib/finest/builder.rb

Overview

Finest Struct

Defined Under Namespace

Classes: Error

Instance Method Summary collapse

Methods included from Helper

#accessor_builder, #attribute_from_inner_key, #build_by_keys, #nested_hash_value

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/finest/builder.rb', line 121

def method_missing(name, *args)
  attribute = name.to_s.start_with?(/\d/) ? "_#{name.to_s}" : name.to_s
  if attribute =~ /=$/
    @to_h[attribute.chop] =
      if args[0].respond_to?(:key?) || args[0].is_a?(Hash)
        self.class.new(json: args[0])
      else
        args[0]
      end
  else
    @to_h[attribute]
  end
end

Instance Method Details

#initialize(json = {}, keys = []) ⇒ Object



114
115
116
117
118
119
# File 'lib/finest/builder.rb', line 114

def initialize(json = {}, keys = [])
  accessor_builder('to_h', {})
  json.each do |k, v|
    send("#{k}=", v)
  end
end

#respond_to_missing?Boolean

Returns:

  • (Boolean)


135
# File 'lib/finest/builder.rb', line 135

def respond_to_missing?; end