Forum: Ruby Question about PStore API

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F3b7b8756d0c7f71cc7460cc33aefaee?d=identicon&s=25 Daniel Berger (Guest)
on 2006-02-02 21:30
(Received via mailing list)
Hi all,

This is one of those, "Why are things this way" kind of questions.

Why doesn't PStore#transaction yield itself?  That way I could write:

store.transaction{ |s|
    s['names'] = %w/foo bar baz/
    s['tree']  = T.new
}

Or maybe we could even use method_missing to clean things up even more:

store.transaction{ |s|
    s.names = %w/foo bar baz/ # same as s['names']
    s.tree  = T.new
}

Some thread safety issue I'm not aware of in the first case?  Too slow
in the
second?

Just curious.

Dan
Cb48ca5059faf7409a5ab3745a964696?d=identicon&s=25 unknown (Guest)
on 2006-02-02 21:45
(Received via mailing list)
On Fri, 3 Feb 2006, Daniel Berger wrote:

> Hi all,
>
> This is one of those, "Why are things this way" kind of questions.
>
> Why doesn't PStore#transaction yield itself?  That way I could write:
>
> store.transaction{ |s|
>   s['names'] = %w/foo bar baz/
>   s['tree']  = T.new
> }

hmmm.

   harp:~ > ruby -r pstore -e ' PStore::new("ps").transaction{|ps| p
ps.class} '
   PStore

   harp:~ > ruby -v
   ruby 1.8.4 (2006-01-12) [i686-linux]


   jib:~ > ruby -r pstore -e ' PStore::new("ps").transaction{|ps| p
ps.class} '
   PStore

   jib:~ > ruby -v
   ruby 1.8.1 (2003-12-25) [i686-linux]

seems to for me?  is that what you meant.


> Or maybe we could even use method_missing to clean things up even more:
>
> store.transaction{ |s|
>   s.names = %w/foo bar baz/ # same as s['names']
>   s.tree  = T.new
> }

that would be a nice hack for string keys - of course keys don't have to
be
keys but i bet they are 99% of the time.  good idea.  submit a patch!
;-)

cheers.

-a
52a177e9dbd3e614825aabc4e45f8cd6?d=identicon&s=25 Mark Volkmann (Guest)
on 2006-02-02 21:54
(Received via mailing list)
On 2/2/06, Daniel Berger <Daniel.Berger@qwest.com> wrote:
> Hi all,
>
> This is one of those, "Why are things this way" kind of questions.
>
> Why doesn't PStore#transaction yield itself?  That way I could write:
>
> store.transaction{ |s|
>     s['names'] = %w/foo bar baz/
>     s['tree']  = T.new
> }

I'm guessing it's because you've already got a variable holding the
store, so obviously you can just use that in the block. This is
different from say File.open where that method call is creating the
object you want to operate on inside the block that follows it. Of
course you might write a method that returns the store to you and want
to invoke a transaction on it. For example,

get_store("some-store-lookup-key").transaction do |store|
  # do something with store here
end

In this case I can see where your suggestion would be nice to have.
F3b7b8756d0c7f71cc7460cc33aefaee?d=identicon&s=25 Daniel Berger (Guest)
on 2006-02-02 22:03
(Received via mailing list)
ara.t.howard@noaa.gov wrote:
>>   s['tree']  = T.new
>   ruby 1.8.4 (2006-01-12) [i686-linux]
>
>
>   jib:~ > ruby -r pstore -e ' PStore::new("ps").transaction{|ps| p
> ps.class} '
>   PStore
>
>   jib:~ > ruby -v
>   ruby 1.8.1 (2003-12-25) [i686-linux]
>
> seems to for me?  is that what you meant.

Gah! I could have sworn that didn't work.  Disregard.

Dan
This topic is locked and can not be replied to.