module Aquarium::Utils::SetUtils

Public Class Methods

strip_set_nils(set) click to toggle source

Return a new set that is a copy of the input set with all nils removed.

   # File lib/aquarium/utils/set_utils.rb
21 def self.strip_set_nils set
22   set.delete_if {|x| x.nil?}
23 end

Public Instance Methods

make_set(*value_or_set_or_array) click to toggle source

Return a set containing the input item or list of items. If the input is a set or an array, it is returned. In all cases, the constructed set is a flattened version of the input and any nil elements are removed by strip_set_nils. Note that this behavior effectively converts nil to [].

   # File lib/aquarium/utils/set_utils.rb
11 def make_set *value_or_set_or_array
12   strip_set_nils(convert_to_set(*value_or_set_or_array))
13 end
strip_set_nils(set) click to toggle source

Return a new set that is a copy of the input set with all nils removed.

   # File lib/aquarium/utils/set_utils.rb
16 def strip_set_nils set
17   SetUtils.strip_set_nils set
18 end

Protected Instance Methods

convert_to_set(*value_or_set_or_array) click to toggle source
   # File lib/aquarium/utils/set_utils.rb
26 def convert_to_set *value_or_set_or_array
27   if value_or_set_or_array.nil? or value_or_set_or_array.empty?
28     Set.new
29   elsif value_or_set_or_array[0].kind_of?(Set)
30     value_or_set_or_array[0]
31   else
32     Set.new value_or_set_or_array.flatten
33   end
34 end