So, unless you count merge! and update, there doesn't seem to be a way
to shove stuff into a hash and get the resulting updated hash back.
Now, I know merge and update make it real easy:
h = {}
h.update(:a => :b).update(:c => :d).update(:e => :f)
but this some how feels unnatural to me. maybe the following is
better for me and others?
---code---
require 'ext/singleton_class'
class Hash
def <<(k)
if @shift_value.nil? then
@shift_value = Object.new.singleton_def(:key) {k}
else
key, @shift_value = @shift_value.key, nil
self[key] = k
end
self
end
end
---end code---
---usage---
h = {}
h << :language << :ruby << :creator << :matz << :users << :"comp.lang.ruby"
p h
---result---
{:language=>:ruby, :creator=>:matz, :users=>:"comp.lang.ruby"}
···
-------------
Just a question of flavour, really.
--
There's no word in the English language for what you do to a dead
thing to make it stop chasing you.