class ActiveScaffold::DataStructures::Set
Public Class Methods
new(*args)
click to toggle source
# File lib/active_scaffold/data_structures/set.rb, line 6 def initialize(*args) @set = [] self.add *args end
Public Instance Methods
add(*args)
click to toggle source
the way to add items to the set.
# File lib/active_scaffold/data_structures/set.rb, line 12 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
Also aliased as: <<
each() { |i| ... }
click to toggle source
# File lib/active_scaffold/data_structures/set.rb, line 43 def each @set.each {|i| yield i } end
empty?()
click to toggle source
# File lib/active_scaffold/data_structures/set.rb, line 52 def empty? @set.empty? end
exclude(*args)
click to toggle source
the way to remove items from the set.
# File lib/active_scaffold/data_structures/set.rb, line 22 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
Also aliased as: remove
find_by_name(name)
click to toggle source
returns the item of the given name.
# File lib/active_scaffold/data_structures/set.rb, line 36 def find_by_name(name) # this works because of `def item.==' item = @set.find { |c| c == name } item end
Also aliased as: []
find_by_names(*names)
click to toggle source
returns an array of items with the provided names
# File lib/active_scaffold/data_structures/set.rb, line 31 def find_by_names(*names) @set.find_all { |item| names.include? item } end
length()
click to toggle source
returns the number of items in the set
# File lib/active_scaffold/data_structures/set.rb, line 48 def length @set.length end