General Purpose Transactions

Ask a Question related to Ruby, Design and Development.

  1. #1

    Default 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.

    -t0

    T. Onoma Guest

  2. Similar Questions and Discussions

    1. Purpose of Contribute
      Hi everyone, I have to create a content management system for a small website I'm creating for a client. I was planning on using xml and php to...
    2. Source for general purpose background graphics
      Creating a product brochure and have no problems with everything I want to do except the backgroud, if any, that the various pictures and text will...
    3. multi-purpose PHP page
      Hey everyone, here is my question... I am looking to have a single product page that is able to read a single table that would contain several...
    4. What is the purpose of FormsAuthentication.SignOut()?
      MSDN documentation says: Removes the authentication ticket. That's it. Where does it remove the authentication ticket from (server /...
    5. purpose of threads?
      Juha Laiho <Juha.Laiho@iki.fi> spewed forth with: As a relatively poor example of this, I'm writing a threaded YACMP (Yet Another Car Mp3...
  3. #2

    Default Re: General Purpose Transactions

    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 Guest

  4. #3

    Default Re: General Purpose Transactions

    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.
    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 :: [url]http://www.ngdc.noaa.gov/stp/[/url]
    | NGDC :: [url]http://www.ngdc.noaa.gov/[/url]
    | NESDIS :: [url]http://www.nesdis.noaa.gov/[/url]
    | NOAA :: [url]http://www.noaa.gov/[/url]
    | US DOC :: [url]http://www.commerce.gov/[/url]
    |
    | 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 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139