Project

General

Profile

Bug #12437 » collect-workaround.rb

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

 
#! /usr/bin/ruby

require 'set'

class Categories < Set

def collect!
block_given? or return enum_for(__method__)
set = self.class.new
each { |o| set << yield(o) }
replace(set)
end

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
    (1-1/1)