class ActiveScaffold::DataStructures::Set

Public Instance Methods

<<(*args) click to toggle source
Alias for: add
[](name) click to toggle source
Alias for: find_by_name
add(*args) click to toggle source

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
Also aliased as: <<
each() { |i| ... } click to toggle source
# File lib/active_scaffold/data_structures/set.rb, line 47
def each
  @set.each {|i| yield i }
end
empty?() click to toggle source
# File lib/active_scaffold/data_structures/set.rb, line 56
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 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
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 40
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 35
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 52
def length
  @set.length
end
remove(*args) click to toggle source
Alias for: exclude
set_values(*args) click to toggle source
# File lib/active_scaffold/data_structures/set.rb, line 10
def set_values(*args)
  @set = []
  self.add *args
end

Public Class Methods

new(*args) click to toggle source
# File lib/active_scaffold/data_structures/set.rb, line 6
def initialize(*args)
  set_values(*args)
end