Project

General

Profile

Actions

Bug #12437

closed

Is it "legal" to call collect! in class initializer?

Added by vo.x (Vit Ondruch) almost 8 years ago. Updated over 6 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
[ruby-core:75770]

Description

Is there any reason the following script should not work?

#! /usr/bin/ruby

require 'set'

class Categories < Set

  def initialize(categories=[])
    categories.collect! { |category| category } if categories
    super categories
  end

end

categories = Categories.new()
categories += [1, 2, 3]
p categories

categories2 = Categories.new(categories)
p categories2

It fails with stack level too deep (SystemStackError) error and this regression seems to be introduced by r52591.

For details, please take a look at original issue reported here: https://bugzilla.redhat.com/show_bug.cgi?id=1308057


Files

collect-workaround.rb (452 Bytes) collect-workaround.rb workaround using custom collect method valtri (František Dvořák), 06/19/2016 06:49 PM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0