class ActiveScaffold::DataStructures::Set
Attributes
Public Class Methods
Source
# File lib/active_scaffold/data_structures/set.rb, line 6 def initialize(*args) set_values(*args) end
Public Instance Methods
Source
# File lib/active_scaffold/data_structures/set.rb, line 63 def +(other) self.class.new(@set, *other) end
Source
# File lib/active_scaffold/data_structures/set.rb, line 20 def add(*args) args.flatten! # allow [] as a param args.each do |arg| arg = arg.to_sym if arg.is_a? String @set << arg unless @set.include? arg # avoid duplicates end end
the way to add items to the set.
Also aliased as: <<
Source
# File lib/active_scaffold/data_structures/set.rb, line 50 def each(&) @set.each(&) end
Source
# File lib/active_scaffold/data_structures/set.rb, line 59 def empty? @set.empty? end
Source
# File lib/active_scaffold/data_structures/set.rb, line 30 def exclude(*args) args.flatten! # allow [] as a param args.collect!(&:to_sym) # symbolize the args # check respond_to? :to_sym, ActionColumns doesn't respond to to_sym @set.reject! { |c| c.respond_to?(:to_sym) && args.include?(c.to_sym) } # reject all items specified end
the way to remove items from the set.
Also aliased as: remove
Source
# File lib/active_scaffold/data_structures/set.rb, line 44 def find_by_name(name) # this works because of `def item.==' @set.find { |c| c == name } end
returns the item of the given name.
Also aliased as: []
Source
# File lib/active_scaffold/data_structures/set.rb, line 39 def find_by_names(*names) @set.find_all { |item| names.include? item } end
returns an array of items with the provided names
Source
# File lib/active_scaffold/data_structures/set.rb, line 10 def initialize_dup(other) @set = other.set.dup end
Source
# File lib/active_scaffold/data_structures/set.rb, line 55 def length @set.length end
returns the number of items in the set
Source
# File lib/active_scaffold/data_structures/set.rb, line 14 def set_values(*args) @set = [] add(*args) end