General Purpose Transactions

Discussion in 'Ruby' started by T. Onoma, Nov 14, 2003.

  1. T. Onoma

    T. Onoma Guest

    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
     
    T. Onoma, Nov 14, 2003
    #1
    1. Advertising

  2. 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
     
    Gavin Sinclair, Nov 14, 2003
    #2
    1. Advertising

  3. T. Onoma

    Ara.T.Howard Guest

    On Fri, 14 Nov 2003, T. Onoma wrote:

    > Date: Fri, 14 Nov 2003 09:30:26 +0900
    > From: T. Onoma <>
    > 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'
    ===============================================================================
     
    Ara.T.Howard, Nov 14, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robert Bj?rn
    Replies:
    0
    Views:
    433
    Robert Bj?rn
    Jun 1, 2004
  2. Maarten van Reeuwijk

    Looking for very simple general purpose tokenizer

    Maarten van Reeuwijk, Jan 19, 2004, in forum: Python
    Replies:
    6
    Views:
    397
  3. Ron Stephens
    Replies:
    23
    Views:
    3,022
    Ron Stephens
    Apr 12, 2004
  4. Donald Newcomb

    NEWB: General purpose list iteration?

    Donald Newcomb, Aug 12, 2005, in forum: Python
    Replies:
    4
    Views:
    329
    Donald Newcomb
    Aug 12, 2005
  5. John Machin
    Replies:
    6
    Views:
    407
    metaperl
    Aug 16, 2006
Loading...

Share This Page