diff options
author | Jeremy Evans <code@jeremyevans.net> | 2019-08-07 09:01:33 -0700 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2019-09-21 16:10:37 -0700 |
commit | 2e551356a7a6e74ba07283e000ff16f5d1ea6506 (patch) | |
tree | 99c123bb12c43346d9b1748cd73c42b883c6bb0a /test/pathname/test_pathname.rb | |
parent | 7470f965650bf17875632f0c5f9e5a4d9de9fc3f (diff) | |
download | ruby-2e551356a7a6e74ba07283e000ff16f5d1ea6506.tar.gz |
Make Kernel#{Pathname,BigDecimal,Complex} return argument if given correct type
This is how Kernel#{Array,String,Float,Integer,Hash,Rational} work.
BigDecimal and Complex instances are always frozen, so this should
not cause backwards compatibility issues for those. Pathname
instances are not frozen, so potentially this could cause backwards
compatibility issues by not returning a new object.
Based on a patch from Joshua Ballanco, some minor changes by me.
Fixes [Bug #7522]
Diffstat (limited to 'test/pathname/test_pathname.rb')
-rw-r--r-- | test/pathname/test_pathname.rb | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/test/pathname/test_pathname.rb b/test/pathname/test_pathname.rb index eaecc52475..af523f9f98 100644 --- a/test/pathname/test_pathname.rb +++ b/test/pathname/test_pathname.rb @@ -471,6 +471,12 @@ class TestPathname < Test::Unit::TestCase assert_raise(ArgumentError) { Pathname.new("a\0") } end + def test_global_constructor + p = Pathname.new('a') + assert_equal(p, Pathname('a')) + assert_same(p, Pathname(p)) + end + class AnotherStringLike # :nodoc: def initialize(s) @s = s end def to_str() @s end |