# Question about PStore API

**URL:** <https://www.ruby-forum.com/t/question-about-pstore-api/53374>\
**Category:** Ruby\
**Created:** [February 2, 2006, 9:30pm UTC](https://www.ruby-forum.com/t/question-about-pstore-api/53374 "2006-02-02T21:30:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [February 2, 2006, 9:30pm UTC](https://www.ruby-forum.com/t/question-about-pstore-api/53374/1 "2006-02-02T21:30:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [February 2, 2006, 9:45pm UTC](https://www.ruby-forum.com/t/question-about-pstore-api/53374/2 "2006-02-02T21:45:20Z")

</div>

On Fri, 3 Feb 2006, Daniel B. 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

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [February 2, 2006, 9:54pm UTC](https://www.ruby-forum.com/t/question-about-pstore-api/53374/3 "2006-02-02T21:54:23Z")

</div>

On 2/2/06, Daniel B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [February 2, 2006, 10:03pm UTC](https://www.ruby-forum.com/t/question-about-pstore-api/53374/4 "2006-02-02T22:03:27Z")

</div>

removed\_email\_address@domain.invalid 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
