the way to add items to the set.
# File lib/active_scaffold/data_structures/set.rb, line 16 def add(*args) args.flatten! # allow [] as a param args.each { |arg| arg = arg.to_sym if arg.is_a? String @set << arg unless @set.include? arg # avoid duplicates } end
# File lib/active_scaffold/data_structures/set.rb, line 47 def each @set.each {|i| yield i } end
# File lib/active_scaffold/data_structures/set.rb, line 56 def empty? @set.empty? end
the way to remove items from the set.
# File lib/active_scaffold/data_structures/set.rb, line 26 def exclude(*args) args.flatten! # allow [] as a param args.collect! { |a| a.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 and args.include? c.to_sym } # reject all items specified end
returns the item of the given name.
# File lib/active_scaffold/data_structures/set.rb, line 40 def find_by_name(name) # this works because of `def item.==' item = @set.find { |c| c == name } item end
returns an array of items with the provided names
# File lib/active_scaffold/data_structures/set.rb, line 35 def find_by_names(*names) @set.find_all { |item| names.include? item } end
returns the number of items in the set
# File lib/active_scaffold/data_structures/set.rb, line 52 def length @set.length end
# File lib/active_scaffold/data_structures/set.rb, line 10 def set_values(*args) @set = [] self.add *args end
# File lib/active_scaffold/data_structures/set.rb, line 6 def initialize(*args) set_values(*args) end