Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Changed Hash#delete / #default behaviour ?

1 view
Skip to first unread message

dooby

unread,
Feb 2, 2003, 5:34:30 PM2/2/03
to

Hi,

Should Hash#delete and Hash#[] give differing results when a
default is given ?

puts "ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"

hsh = {'a' => 1}
hsh.default='missing'

puts hsh['a']
puts hsh.delete('a')
puts hsh['b']
puts hsh.delete('b')


# ruby 1.6.7 (2002-03-01) [i586-mswin32]
# 1
# 1
# missing
# missing


# ruby 1.7.3 (2002-11-17) [i386-mswin32]
# 1
# 1
# missing
# nil


IMO the previous behaviour was more useful when using #delete to select
an entry for once-only processing with a dummy object in the default
slot.
Better than: hsh.delete('b') || 'missing'.

(I'll add to the Pickaxe-update wiki if this change was intentional.)

Regards,

daz

0 new messages