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
···
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’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
···
On Fri, 14 Nov 2003, T. Onoma wrote:
Date: Fri, 14 Nov 2003 09:30:26 +0900
From: T. Onoma transami@runbox.com
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.
–
ATTN: please update your address books with address below!
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’
===============================================================================