class DpStmMap::JsonMessage
Public Class Methods
class_from_string(str)
click to toggle source
# File lib/dp_stm_map/Message.rb, line 31 def self.class_from_string(str) str.split('::').inject(Object) do |mod, class_name| mod.const_get(class_name) end end
deserialize(string)
click to toggle source
# File lib/dp_stm_map/Message.rb, line 20 def self.deserialize string # return YAML::load(string) json=JSON.parse(string) type=json.delete('type') cls=class_from_string(type) obj=cls.new obj.from_hash! json obj end
Public Instance Methods
from_hash!(hash)
click to toggle source
# File lib/dp_stm_map/Message.rb, line 47 def from_hash! hash hash.each do |var, val| self.instance_variable_set var, val end end
serialize()
click to toggle source
# File lib/dp_stm_map/Message.rb, line 37 def serialize # return YAML::dump(self) hash = {} self.instance_variables.each do |var| hash[var] = self.instance_variable_get var end hash['type']=self.class.name hash.to_json end