Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > General Purpose Transactions

Reply
Thread Tools

General Purpose Transactions

 
 
T. Onoma
Guest
Posts: n/a
 
      11-14-2003
I was writing a piece a code where I needed to change a few object attributes, call a method, then reset those attributes to what they were. And it occured to me that it might be nice to have general purpose tranactions.


anobject = AClass.new
anobject.attrib = 'set'
transaction do
anobject.attrib = 'temp'
anobject.amethod
end
p anobject.attrib # => 'set'


Seems like there may already be a simple way to do this, but it's not coming to mind.

-t0

 
Reply With Quote
 
 
 
 
Gavin Sinclair
Guest
Posts: n/a
 
      11-14-2003
On Friday, November 14, 2003, 11:30:26 AM, T. wrote:

> I was writing a piece a code where I needed to change a few object attributes, call a method, then reset those attributes to what they were. And it occured to me that it might be nice to have
> general purpose tranactions.



> anobject = AClass.new
> anobject.attrib = 'set'
> transaction do
> anobject.attrib = 'temp'
> anobject.amethod
> end
> p anobject.attrib # => 'set'



> Seems like there may already be a simple way to do this, but it's not coming to mind.


Austin Ziegler's Transaction::Simple will help, with slightly
different semantics, I think. Search the RAA for it.

Gavin


 
Reply With Quote
 
 
 
 
Ara.T.Howard
Guest
Posts: n/a
 
      11-14-2003
On Fri, 14 Nov 2003, T. Onoma wrote:

> Date: Fri, 14 Nov 2003 09:30:26 +0900
> From: T. Onoma <(E-Mail Removed)>
> Newsgroups: comp.lang.ruby
> Subject: General Purpose Transactions
>
> I was writing a piece a code where I needed to change a few object attributes, call a method, then reset those attributes to what they were. And it occured to me that it might be nice to have general purpose tranactions.
>
>
> anobject = AClass.new
> anobject.attrib = 'set'
> transaction do
> anobject.attrib = 'temp'
> anobject.amethod
> end
> p anobject.attrib # => 'set'
>
>
> Seems like there may already be a simple way to do this, but it's not coming to mind.


austin's transaction::simple (RAA) does this. also, there's always:

begin
org = obj and obj = Marshal.load(Marshal.dump(obj))
obj.parm = 42
obj.method()
ensure
obj = org
end

-a
--

ATTN: please update your address books with address below!

================================================== =============================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
| STP :: http://www.ngdc.noaa.gov/stp/
| NGDC :: http://www.ngdc.noaa.gov/
| NESDIS :: http://www.nesdis.noaa.gov/
| NOAA :: http://www.noaa.gov/
| US DOC :: http://www.commerce.gov/
|
| The difference between art and science is that science is what we
| understand well enough to explain to a computer.
| Art is everything else.
| -- Donald Knuth, "Discover"
|
| /bin/sh -c 'for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done'
================================================== =============================

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
recommended general-purpose string template packages? John Machin Python 6 08-16-2006 01:35 PM
NEWB: General purpose list iteration? Donald Newcomb Python 4 08-12-2005 10:33 PM
Storing general-purpose and specific entries Robert Bj?rn XML 0 06-01-2004 11:36 AM
Python is the best and most popular general purpose scripting language; the universal scripting language Ron Stephens Python 23 04-12-2004 05:32 PM
Looking for very simple general purpose tokenizer Maarten van Reeuwijk Python 6 01-21-2004 04:37 AM



Advertisments