Class: Object

Inherits:
BasicObject
Defined in:
lib/ruby-serial/_object.rb

Instance Method Summary collapse

Instance Method Details

#get_instance_vars_to_rubyserialObject

Get the list of instance variables that are meant to be serialized

Result
  • map<String,Object>: Set of instance variables, per name



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ruby-serial/_object.rb', line 7

def get_instance_vars_to_rubyserial
  # Compute the list of attributes to serialize
  instance_var_names = []
  klass = self.class
  if (klass.rubyserial_only_lst != nil)
    if (klass.dont_rubyserial_lst != nil)
      instance_var_names = klass.rubyserial_only_lst - klass.dont_rubyserial_lst
    else
      instance_var_names = klass.rubyserial_only_lst
    end
  elsif (klass.dont_rubyserial_lst != nil)
    instance_var_names = self.instance_variables - klass.dont_rubyserial_lst
  else
    instance_var_names = self.instance_variables
  end
  # Compute the resulting map
  instance_vars = {}
  instance_var_names.each do |sym_var|
    instance_vars[sym_var.to_s] = self.instance_variable_get(sym_var)
  end
  return instance_vars
end

#set_instance_vars_from_rubyserial(instance_vars) ⇒ Object

Set the list of instance variables that were serialized

Parameters
  • instance_vars (map<String,Object>): Set of instance variables, per name



34
35
36
37
38
# File 'lib/ruby-serial/_object.rb', line 34

def set_instance_vars_from_rubyserial(instance_vars)
  instance_vars.each do |var_name, value|
    self.instance_variable_set(var_name.to_sym, value)
  end
end