Issue #7522 has been reported by jballanc (Joshua Ballanco). ---------------------------------------- Bug #7522: Non-core "Type()" Kernel methods return new objects https://bugs.ruby-lang.org/issues/7522 Author: jballanc (Joshua Ballanco) Status: Open Priority: Normal Assignee: Category: Target version: ruby -v: 2.0.0-preview1 The methods Array(), String(), Float(), Integer(), Hash(), and Rational() all return their argument when the argument is already an instance of the type in question. For example: a = [] a.equal? Array(a) #=> true However, the similar methods Pathname(), BigDecimal(), and Complex() do not do this: p = Pathname.new('/tmp') p.equal? Pathname(p) #=> false I had the impression that the "Type()" methods were intended as "safe" coercion methods. That is, if no type conversion is required, then the system is left unchanged (and no new objects are created). The attached patch fixes the three methods mentioned above to adhere to this same invariant.
on 2012-12-05 22:18
on 2012-12-09 04:16
Issue #7522 has been updated by charliesome (Charlie Somerville). Your change to ext/bigdecimal/bigdecimal.c will cause a compiler warning: compiling bigdecimal.c bigdecimal.c: In function ‘BigDecimal_global_new’: bigdecimal.c:2414: warning: ISO C90 forbids mixed declarations and code You should move the declaration of 'pv' above the your if statement, but leave the assignment where it is. ---------------------------------------- Bug #7522: Non-core "Type()" Kernel methods return new objects https://bugs.ruby-lang.org/issues/7522#change-34549 Author: jballanc (Joshua Ballanco) Status: Open Priority: Normal Assignee: Category: Target version: ruby -v: 2.0.0-preview1 The methods Array(), String(), Float(), Integer(), Hash(), and Rational() all return their argument when the argument is already an instance of the type in question. For example: a = [] a.equal? Array(a) #=> true However, the similar methods Pathname(), BigDecimal(), and Complex() do not do this: p = Pathname.new('/tmp') p.equal? Pathname(p) #=> false I had the impression that the "Type()" methods were intended as "safe" coercion methods. That is, if no type conversion is required, then the system is left unchanged (and no new objects are created). The attached patch fixes the three methods mentioned above to adhere to this same invariant.
on 2012-12-09 20:25
Issue #7522 has been updated by jballanc (Joshua Ballanco). File kernel_methods.diff added Ah, thanks for that catch! Updated patch is attached. ---------------------------------------- Bug #7522: Non-core "Type()" Kernel methods return new objects https://bugs.ruby-lang.org/issues/7522#change-34569 Author: jballanc (Joshua Ballanco) Status: Open Priority: Normal Assignee: Category: Target version: ruby -v: 2.0.0-preview1 The methods Array(), String(), Float(), Integer(), Hash(), and Rational() all return their argument when the argument is already an instance of the type in question. For example: a = [] a.equal? Array(a) #=> true However, the similar methods Pathname(), BigDecimal(), and Complex() do not do this: p = Pathname.new('/tmp') p.equal? Pathname(p) #=> false I had the impression that the "Type()" methods were intended as "safe" coercion methods. That is, if no type conversion is required, then the system is left unchanged (and no new objects are created). The attached patch fixes the three methods mentioned above to adhere to this same invariant.
on 2013-01-25 04:51
Issue #7522 has been updated by ko1 (Koichi Sasada). Category set to core Assignee set to mame (Yusuke Endoh) Target version set to 2.0.0 I'm not sure who should take this issue. ---------------------------------------- Bug #7522: Non-core "Type()" Kernel methods return new objects https://bugs.ruby-lang.org/issues/7522#change-35610 Author: jballanc (Joshua Ballanco) Status: Open Priority: Normal Assignee: mame (Yusuke Endoh) Category: core Target version: 2.0.0 ruby -v: 2.0.0-preview1 The methods Array(), String(), Float(), Integer(), Hash(), and Rational() all return their argument when the argument is already an instance of the type in question. For example: a = [] a.equal? Array(a) #=> true However, the similar methods Pathname(), BigDecimal(), and Complex() do not do this: p = Pathname.new('/tmp') p.equal? Pathname(p) #=> false I had the impression that the "Type()" methods were intended as "safe" coercion methods. That is, if no type conversion is required, then the system is left unchanged (and no new objects are created). The attached patch fixes the three methods mentioned above to adhere to this same invariant.
on 2013-02-02 04:05
Issue #7522 has been updated by mame (Yusuke Endoh). Status changed from Open to Assigned Assignee changed from mame (Yusuke Endoh) to matz (Yukihiro Matsumoto) Target version changed from 2.0.0 to next minor Sorry but let me postpone this to the next minor. I'm afraid if the existing code depends on the traditional behavior. It should have been included in rc1, which is my fault. Sorry, blame me. -- Yusuke Endoh <mame@tsg.ne.jp> ---------------------------------------- Bug #7522: Non-core "Type()" Kernel methods return new objects https://bugs.ruby-lang.org/issues/7522#change-35773 Author: jballanc (Joshua Ballanco) Status: Assigned Priority: Normal Assignee: matz (Yukihiro Matsumoto) Category: core Target version: next minor ruby -v: 2.0.0-preview1 The methods Array(), String(), Float(), Integer(), Hash(), and Rational() all return their argument when the argument is already an instance of the type in question. For example: a = [] a.equal? Array(a) #=> true However, the similar methods Pathname(), BigDecimal(), and Complex() do not do this: p = Pathname.new('/tmp') p.equal? Pathname(p) #=> false I had the impression that the "Type()" methods were intended as "safe" coercion methods. That is, if no type conversion is required, then the system is left unchanged (and no new objects are created). The attached patch fixes the three methods mentioned above to adhere to this same invariant.
on 2013-02-03 11:08
Issue #7522 has been updated by jballanc (Joshua Ballanco). No apology necessary. Thanks for the help! ---------------------------------------- Bug #7522: Non-core "Type()" Kernel methods return new objects https://bugs.ruby-lang.org/issues/7522#change-35802 Author: jballanc (Joshua Ballanco) Status: Assigned Priority: Normal Assignee: matz (Yukihiro Matsumoto) Category: core Target version: next minor ruby -v: 2.0.0-preview1 The methods Array(), String(), Float(), Integer(), Hash(), and Rational() all return their argument when the argument is already an instance of the type in question. For example: a = [] a.equal? Array(a) #=> true However, the similar methods Pathname(), BigDecimal(), and Complex() do not do this: p = Pathname.new('/tmp') p.equal? Pathname(p) #=> false I had the impression that the "Type()" methods were intended as "safe" coercion methods. That is, if no type conversion is required, then the system is left unchanged (and no new objects are created). The attached patch fixes the three methods mentioned above to adhere to this same invariant.
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.