[#8815] Segfault in libc strlen, via rb_str_new2 — "Sean E. Russell" <ser@...>

Howdy,

12 messages 2006/09/09
[#8817] Re: Segfault in libc strlen, via rb_str_new2 — Eric Hodel <drbrain@...7.net> 2006/09/09

On Sep 8, 2006, at 10:10 PM, Sean E. Russell wrote:

Re: Behavior change for Hash#default in 1.8.5?

From: Yukihiro Matsumoto <matz@...>
Date: 2006-09-25 04:08:59 UTC
List: ruby-core #8916
Hi,

In message "Re: Behavior change for Hash#default in 1.8.5?"
    on Mon, 25 Sep 2006 12:33:02 +0900, Daniel Berger <djberg96@gmail.com> writes:

|It appears that something has changed with Hash#default between 1.8.4
|and 1.8.5:

Yes.

|irb(main):001:0> VERSION
|=> "1.8.4"
|irb(main):002:0> Hash.new{ |h,k| h[k] = k.to_i * 3 }.default
|=> 0

Under pre 1.8.5 versions, #default method erroneously calculate the
default value.  In above example, the block was called with k=nil, so
that the value of 0 was returned.

1.8.5 fixed this, so that #default returns nil that indicates it has
no default value set.  If you want to know the value for the specific
key, invoke #default with key argument specified

|irb(main):001:0> VERSION
|=> "1.8.5"
|irb(main):002:0> Hash.new{ |h,k| h[k] = k.to_i * 3 }.default
|=> nil

irb(main):003:0> Hash.new{ |h,k| h[k] = k.to_i * 3 }.default(3)
=> 9

							matz.

In This Thread

Prev Next