<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>File: snapshot.rb</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta http-equiv="Content-Script-Type" content="text/javascript" /> <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" /> <script type="text/javascript"> // <![CDATA[ function popupCode( url ) { window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400") } function toggleCode( id ) { if ( document.getElementById ) elem = document.getElementById( id ); else if ( document.all ) elem = eval( "document.all." + id ); else return false; elemStyle = elem.style; if ( elemStyle.display != "block" ) { elemStyle.display = "block" } else { elemStyle.display = "none" } return true; } // Make codeblocks hidden by default document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" ) // ]]> </script> </head> <body> <div id="fileHeader"> <h1>snapshot.rb</h1> <table class="header-table"> <tr class="top-aligned-row"> <td><strong>Path:</strong></td> <td>lib/carat/snapshot.rb </td> </tr> <tr class="top-aligned-row"> <td><strong>Last Update:</strong></td> <td>Mon Apr 11 12:17:58 EDT 2005</td> </tr> </table> </div> <!-- banner header --> <div id="bodyContent"> <div id="contextContent"> <div id="description"> <h1>Snapshot</h1> <p> A lightweight single-depth object state capture. The take_snapshot method reads the object’s state, which is generally it’s collection of instance variables, and returns them in a hash. The state can be restored with apply_snapshot. </p> <h2>Usage</h2> <pre> require 'raspberry/new/snapshot' Customer = Struct.new("Customer", :name, :address, :zip) joe = Customer.new( "Joe Pitare", "1115 Lila Ln.", 47634 ) # simple transactions joe_snap = joe.take_snapshot begin do_something_with( joe ) rescue joe.apply_snapshot( joe_snap ) end joe_snap[:name] => "Joe Pitare" joe_snap[:address] => "1115 Lila Ln." joe_snap[:zip] => 47634 </pre> <h2>TODO</h2> <ul> <li>Perhaps extend to offer multiple depths. </li> <li>Should key consitancy be enforced? Currently <a href="../../../classes/Struct.html">Struct</a>’s will have symobl keys while other classes will have string keys in the form of "@name". </li> <li>Add other core classes. </li> </ul> <h2>History</h2> <ul> <li>20005.04.11 Passed basic test. </li> </ul> <h2></h2> </div> </div> </div> <!-- if includes --> <div id="section"> <!-- if method_list --> </div> <div id="validator-badges"> <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p> </div> </body> </html>