Refinement to facets/more/snapshot.rb

Suggestion for facets library snapshot.rb

Consider adding optional fields argument to both take_snapshot() and
restore_snapshot() to selectively take snapshot of selected fields as
against all fields which is the default.
Patch provided below over 1.8.54 : methods changes take_snapshot and
restore_snapshot for Object only.

= snapshot.rb

class Object
def take_snapshot(fields=nil)
snap = Hash.new
fields = instance_variables unless fields
fields.each do |iv|
snap[iv] = instance_variable_get(iv)
end
snap
end

def restore_snapshot(snap, fields=nil)
fields = instance_variables unless fields
fields.each do |iv|
instance_variable_set(iv, snap[iv])
end
end
end

  • nasir

On Jul 25, 1:28 am, “Nasir K.” [email protected] wrote:

class Object
fields = instance_variables unless fields
fields.each do |iv|
instance_variable_set(iv, snap[iv])
end
end
end

Good idea.

BTW, there’s a Facets mailing list now. You can sign up via Rubyforge
or Google G…

http://rubyforge.org/mail/?group_id=804
http://groups.google.com/group/facets-universal?lnk=li

Thanks!
T.