module OFC2::OWJSON

specjal module included in each class with that module we add to_hash method there is also a method_missing which allow user to set/get any instance variable if user try to get not setted instance variable it return nil and generate a warn

Public Instance Methods

method_missing(method_id, *arguments) click to toggle source

method_missing handle setting and getting instance variables You can set variable in two ways:

  1. variable_name = value

  2. set_variable_name(value)

you can get only alredy setted variables, otherwise return nil

# File lib/ofc2.rb, line 27
def method_missing(method_id, *arguments)
  a = arguments[0] if arguments and arguments.size > 0
  method = method_id.to_s
  if method =~ /^(.*)(=)$/
    self.instance_variable_set("@#{$1.gsub('_','__')}", a)
  elsif method =~ /^(set_)(.*)$/
    self.instance_variable_set("@#{$2.gsub('_','__')}", a)
  elsif self.instance_variable_defined?("@#{method_id.to_s.gsub('_','__')}")
    self.instance_variable_get("@#{method_id.to_s.gsub('_','__')}") # that will be return instance variable value or nil, handy
  else
    nil
  end
end
to_h()
Alias for: to_hash
to_hash() click to toggle source

return a hash of instance values

# File lib/ofc2.rb, line 9
def to_hash
  self.instance_values
end
Also aliased as: to_h