"Crystallizing" Objects

R

Robert Klemme

[growinghash.rb]require 'delegate'

class GrowingHash < DelegateClass(Hash)
def initialize(*a,&b)
super(Hash === a[0] ? a[0] : Hash.new(*a,&b))
end

def store(k,v)
raise ArgumentError, "Key already set: #{k.inspect}" if key? k
super
end

alias []= store

def set_if_unset(k,v=nil)
store(k, block_given? ? yield : v) unless key? k
end
end

Is this intended to be thread-safe?

Of course not. (see my posting)

Kind regards

robert
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,079
Latest member
ElidaWarin

Latest Threads

Top