class Oj::Bag

are provided as the Class is intended for reading only.
can be accessed using the variable name (without the @ prefix). No setters
are added using the instance_variable_set() method. All instance variables
Class for auto-generated classes in the storage system. Instance variables
A generic class that is used only for storing attributes. It is the base

def self.define_class(classname)

Raises:
  • (NameError) - if the classname is invalid.

Returns:
  • (Object) - an instance of the specified Class.

Parameters:
  • classname (String) -- Class name or symbol that includes Module names.
def self.define_class(classname)
  classname = classname.to_s unless classname.is_a?(String)
  tokens = classname.split('::').map(&:to_sym)
  raise NameError.new("Invalid classname '#{classname}") if tokens.empty?
  m = Object
  tokens[0..-2].each do |sym|
    if m.const_defined?(sym)
      m = m.const_get(sym)
    else
      c = Module.new
      m.const_set(sym, c)
      m = c
    end
  end
  sym = tokens[-1]
  if m.const_defined?(sym)
    c = m.const_get(sym)
  else
    c = Class.new(Oj::Bag)
    m.const_set(sym, c)
  end
  c
end

def eql?(other)

Returns:
  • (Boolean) - true if each variable and value are the same, otherwise false.

Parameters:
  • other (Object) -- Object to compare self to
def eql?(other)
  return false if (other.nil? or self.class != other.class)
  ova = other.instance_variables
  iv = instance_variables
  return false if ova.size != iv.size
  iv.all? { |vid| instance_variable_get(vid) != other.instance_variable_get(vid) }
end

def initialize(args = {})

Parameters:
  • args (Hash) -- instance variable symbols and their values

Other tags:
    Example: Oj::Bag.new(:@x => 42, :@y => 57) -
def initialize(args = {})
  args.each do |k, v|
    self.instance_variable_set(k, v)
  end
end

def method_missing(m, *args, &block)

Raises:
  • (NoMethodError) - if the instance variable is not defined.
  • (ArgumentError) - if an argument is given. Zero arguments expected.

Returns:
  • (Boolean) - the value of the specified instance variable.

Parameters:
  • m (Symbol) -- method symbol
def method_missing(m, *args, &block)
  raise ArgumentError.new("wrong number of arguments (#{args.size} for 0) to method #{m}") unless args.nil? or args.empty?
  at_m = :"@#{m}"
  raise NoMethodError.new("undefined method #{m}", m) unless instance_variable_defined?(at_m)
  instance_variable_get(at_m)
end

def respond_to?(m)

Returns:
  • (Boolean) - true for any method that matches an instance

Parameters:
  • m (Symbol) -- method symbol
def respond_to?(m)
  return true if super
  instance_variables.include?(:"@#{m}")
end