class ActiveScaffold::DataStructures::Set

Attributes

set[R]

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

Public Instance Methods

<<(*args)
Alias for: add
[](name)
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 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
Also aliased as: <<
each() { |i| ... } click to toggle source
# File lib/active_scaffold/data_structures/set.rb, line 51
def each
  @set.each { |i| yield i }
end
empty?() click to toggle source
# File lib/active_scaffold/data_structures/set.rb, line 60
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 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
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 44
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 39
def find_by_names(*names)
  @set.find_all { |item| names.include? item }
end
initialize_dup(other) click to toggle source
# File lib/active_scaffold/data_structures/set.rb, line 10
def initialize_dup(other)
  @set = other.set.dup
end
length() click to toggle source

returns the number of items in the set

# File lib/active_scaffold/data_structures/set.rb, line 56
def length
  @set.length
end
remove(*args)
Alias for: exclude
set_values(*args) click to toggle source
# File lib/active_scaffold/data_structures/set.rb, line 14
def set_values(*args)
  @set = []
  add(*args)
end