From: Tomas Matousek Date: 2009-03-06T16:52:47+09:00 Subject: [ruby-core:22698] Re: [Bug #1248] e.exception(e) returns self Well the reason is that arg is supposed to be a message, right? A message can be an arbitrary object. So if I pass e as a message, why it doesn't become a value of the message property? irb(main):001:0> a = Exception.new => # irb(main):002:0> b = Exception.new => # irb(main):003:0> c = a.exception(b) => #> # this is ok, b is now a message of c irb(main):004:0> c.message == b => true irb(main):005:0> c = a.exception(a) => # irb(main):006:0> c.message == a # a is not a message of c => false irb(main):007:0> c == a # instead, c is a => true It's not about saving an allocation. It's that for all objects, except for self, the method sets a message on a new exception object. Only for self it doesn't. (at least as far as I observe) Tomas -----Original Message----- From: Yukihiro Matsumoto [mailto:matz@ruby-lang.org] Sent: Thursday, March 05, 2009 10:55 PM To: ruby-core@ruby-lang.org Subject: [ruby-core:22696] Re: [Bug #1248] e.exception(e) returns self Hi, In message "Re: [ruby-core:22687] [Bug #1248] e.exception(e) returns self" on Fri, 6 Mar 2009 04:36:56 +0900, Tomas Matousek writes: |Exception#exception(arg) instance method should return a new exception of the same class as self with message arg. It does so for any object passed in as an argument except for if e is passed in. I don't see any reason for special casing the method this way. | |Repro: |e = Exception.new |p e.exception(e).object_id == e.object_id # => true; it should return false You've missed the reason why you considered this behavior to be a bug. Have you been bitten by this? Or just for the sake of your feeling of consistency? Avoiding object allocation is one good reason. matz.