module Binky::Struct

Public Class Methods

new(json = nil) click to toggle source
# File lib/binky/builder.rb, line 68
def initialize(json = nil)
  accessor_builder('to_h',{})
  json&.each do |k, v|
    self.send("#{k}=", v)
  end
end

Public Instance Methods

method_missing(name, *args) click to toggle source
# File lib/binky/builder.rb, line 75
def method_missing(name, *args)
  attribute = name.to_s.start_with?(/\d/) ? "_#{name.to_s}" : name.to_s
  if attribute =~ /=$/
    if args[0].respond_to?(:key?) || args[0].is_a?(Hash)
      @to_h[attribute.chop] = self.class.new(args[0])
    else
      @to_h[attribute.chop] = args[0]
    end
  else
    @to_h[attribute]
  end
end