R
Reginald Tan
Hi guys. I want my PStore to act more like a Hash. Basically I want to
add "map" functionality to it. For a regular hash, you can do the
following:
h = {0 => "sword", 5 => "hammer", 3 => "arrow"}
puts h.map{ |x| x[0]}.max # gives the highest key which is 5
I want pstore to be able to do same thing. I've included Enumerable but
I do have to implement the each method which I dont know how to go
about. Any suggestions? Thanks
class PStore
include Enumerable
def each &block
end
end
p = PStore.new("temp.store")
p.transaction do
p[0] = "sword"
p[1] = "hammer"
p[2] = "arrow"
end
p.transaction do
puts p.map{|x| x[0]}.max # wont work yet
end
add "map" functionality to it. For a regular hash, you can do the
following:
h = {0 => "sword", 5 => "hammer", 3 => "arrow"}
puts h.map{ |x| x[0]}.max # gives the highest key which is 5
I want pstore to be able to do same thing. I've included Enumerable but
I do have to implement the each method which I dont know how to go
about. Any suggestions? Thanks
class PStore
include Enumerable
def each &block
end
end
p = PStore.new("temp.store")
p.transaction do
p[0] = "sword"
p[1] = "hammer"
p[2] = "arrow"
end
p.transaction do
puts p.map{|x| x[0]}.max # wont work yet
end