class AxTrack::Object
Public Class Methods
new(json_response)
click to toggle source
# File lib/ax_track/object.rb, line 6 def initialize(json_response) # for each key create an own instance variable with a getter json_response.each do |key, value| instance_variable_set "@#{key}", value end create_getters end
Public Instance Methods
create_getters(required_getter_methods = instance_variables.map { |attr_name| attr_name[1..-1 ]})
click to toggle source
pass in an array for getters which should be generated. if nothing is passed in, it will create an instance variable for all instance variables.
# File lib/ax_track/object.rb, line 17 def create_getters(required_getter_methods = instance_variables.map { |attr_name| attr_name[1..-1 ]}) required_getter_methods.each do |attr| singleton_class.send :attr_reader, attr unless self.respond_to? attr end end