1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
module Icalendar
module Marshable
def self.included(base)
base.extend ClassMethods
end
def marshal_dump
instance_variables
.reject { |ivar| self.class.transient_variables.include?(ivar) }
.each_with_object({}) do |ivar, serialized|
serialized[ivar] = instance_variable_get(ivar)
end
end
def marshal_load(serialized)
serialized.each do |ivar, value|
unless self.class.transient_variables.include?(ivar)
instance_variable_set(ivar, value)
end
end
end
module ClassMethods
def transient_variables
@transient_variables ||= [:@transient_variables]
end
def transient_variable(name)
transient_variables.push(name.to_sym)
end
end
end
end
|