How to re-replace Hash default value behaviour?
by Siep Korteling other posts by this author
May 8 2008 5:47PM messages near this date
HI.How to install instal qtruby4-1.4.9-mswin32.gem with gem???
|
Re: How to re-replace Hash default value behaviour?
Hash.new(0) and the block form of Hash.new{_smart_stuff_} come in
really handy while reading in a hash.
When the reading is done however, my hash serves to provide data. At
that stage, the default_value behaviour gets in the way. For instance,
if the hash contains the number of goals for soccerplayers, I don't want
the hash to return value "0" for the key "Wolfgang Amadeus Mozart"; by
then I want plain old Nil, or "No data available".
failed experiment:
Class Hash
def default_proc
Nil
end
end
How can Hash.new behaviour be changed?
regards,
Siep
--
Posted via http://www.ruby-forum.com/.
Thread:
Siep Korteling
Andrea Fazzi
Craig Demyanovich
Siep Korteling
Matt Neuburg
|