S
Sylvain Joyeux
I have a class inheriting Array, and I expected slice() and []
to return Array objects. Unfortunately
irb(main):001:0> class Expression < Array
irb(main):002:1> end
=> nil
irb(main):003:0> test = Expression.new
=> []
irb(main):004:0> test.concat( (1..10).to_a )
=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
irb(main):005:0> test.slice(1..5)
=> [2, 3, 4, 5, 6]
irb(main):006:0> test.slice(1..5).class
=> Expression
And I don't understand why ...
Moreover, since my Expression class has instance variables, the instance
produced by slice() does not have it anymore (which is bad)
I wokarounded this by using Delegator
Any idea on why this behaviour ?
Sylvain
to return Array objects. Unfortunately
irb(main):001:0> class Expression < Array
irb(main):002:1> end
=> nil
irb(main):003:0> test = Expression.new
=> []
irb(main):004:0> test.concat( (1..10).to_a )
=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
irb(main):005:0> test.slice(1..5)
=> [2, 3, 4, 5, 6]
irb(main):006:0> test.slice(1..5).class
=> Expression
And I don't understand why ...
Moreover, since my Expression class has instance variables, the instance
produced by slice() does not have it anymore (which is bad)
I wokarounded this by using Delegator
Any idea on why this behaviour ?
Sylvain