Question about PStore API

D

Daniel Berger

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
 
M

Mark Volkmann

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'] =3D %w/foo bar baz/
s['tree'] =3D 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.
 
D

Daniel Berger

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.

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

Dan
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,662
Latest member
sxarexu

Latest Threads

Top