module Gamefic::Serialize

Public Class Methods

string_to_constant(string) click to toggle source

@param string [String] @return [Object]

# File lib/gamefic/serialize.rb, line 36
def self.string_to_constant string
  space = Object
  string.split('::').each do |part|
    space = space.const_get(part)
  end
  space
end

Public Instance Methods

serialized_class(index) click to toggle source
# File lib/gamefic/serialize.rb, line 26
def serialized_class index
  if index.include?(self.class)
    "#<ELE_#{index.index(self.class)}>"
  else
    self.class.to_s
  end
end
to_serial(index = []) click to toggle source
# File lib/gamefic/serialize.rb, line 5
def to_serial(index = [])
  if index.include?(self)
    {
      'instance' => "#<ELE_#{index.index(self)}>",
      'ivars' => {}
    }
  else
    if self.class == Class && self.name
      {
        'class' => 'Class',
        'name' => name
      }
    else
      {
        'class' => serialized_class(index),
        'ivars' => serialize_instance_variables(index)
      }
    end
  end
end