[ruby-core:55162] [ruby-trunk - Feature #8449][Open] Array#ary_plus always returns an array

1 view
Skip to first unread message

txemagon (José M. González)

unread,
May 25, 2013, 6:48:04 AM5/25/13
to ruby...@ruby-lang.org

Issue #8449 has been reported by txemagon (José M. González).

----------------------------------------
Feature #8449: Array#ary_plus always returns an array
https://bugs.ruby-lang.org/issues/8449

Author: txemagon (José M. González)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:


=begin

Even when Array is subclassified, + operator keeps on returning an Array.

Don't know if it is a bug or intentional, but it has surprised me for sure.

I paste some code for demonstrational purposes:


#!/usr/bin/env ruby
#ary_plus.rb

# Shows an unexpected behavior to me
# when adding Array subclasess.

class Subarray < Array; end

a = Subarray.new
b = Subarray.new

result = a + b
# I was expecting to have a Subarray back

unless result.is_a? Subarray
puts "result is not a [Subarray]"
end

puts "result variable is a [#{result.class.name}]"

=end



--
http://bugs.ruby-lang.org/

zzak (Zachary Scott)

unread,
Jun 2, 2013, 3:23:43 AM6/2/13
to ruby...@ruby-lang.org

Issue #8449 has been updated by zzak (Zachary Scott).

Category set to core
Assignee set to nobu (Nobuyoshi Nakada)

For what it's worth this happens with String too:

>> class Substring < String; end
=> nil
>> a = Substring.new
=> ""
>> b = Substring.new
=> ""
>> result = a + b
=> ""
>> result.class
=> String

Maybe nobu can tell us
----------------------------------------
Feature #8449: Array#ary_plus always returns an array
https://bugs.ruby-lang.org/issues/8449#change-39636

Author: txemagon (José M. González)
Status: Open
Priority: Normal
Assignee: nobu (Nobuyoshi Nakada)
Category: core
Reply all
Reply to author
Forward
0 new messages