Module: Finest::Struct
- Includes:
- Helper
- Defined in:
- lib/finest/builder.rb
Overview
Finest Struct
Defined Under Namespace
Classes: Error
Instance Method Summary collapse
- #initialize(json = {}, keys = []) ⇒ Object
- #method_missing(name, *args) ⇒ Object
- #respond_to_missing? ⇒ Boolean
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
130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/finest/builder.rb', line 130 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
123 124 125 126 127 128 |
# File 'lib/finest/builder.rb', line 123 def initialize(json = {}, keys = []) accessor_builder('to_h', {}) json.each do |k, v| send("#{k}=", v) end end |
#respond_to_missing? ⇒ Boolean
144 |
# File 'lib/finest/builder.rb', line 144 def respond_to_missing?; end |