Class: ActiveScaffold::DataStructures::Set
- Includes:
- Configurable, Enumerable
- Defined in:
- lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/set.rb
Direct Known Subclasses
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#add(*args) ⇒ Object
(also: #<<)
the way to add items to the set.
- #each ⇒ Object
- #empty? ⇒ Boolean
-
#exclude(*args) ⇒ Object
(also: #remove)
the way to remove items from the set.
-
#find_by_name(name) ⇒ Object
(also: #[])
returns the item of the given name.
-
#find_by_names(*names) ⇒ Object
returns an array of items with the provided names.
-
#initialize(*args) ⇒ Set
constructor
A new instance of Set.
-
#length ⇒ Object
returns the number of items in the set.
Methods included from Configurable
Constructor Details
#initialize(*args) ⇒ Set
Returns a new instance of Set.
11 12 13 14 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/set.rb', line 11 def initialize(*args) @set = [] self.add *args end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class ActiveScaffold::Configurable
Instance Attribute Details
#label ⇒ Object
7 8 9 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/set.rb', line 7 def label as_(@label) end |
Instance Method Details
#add(*args) ⇒ Object Also known as: <<
the way to add items to the set.
17 18 19 20 21 22 23 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/set.rb', line 17 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 |
#each ⇒ Object
48 49 50 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/set.rb', line 48 def each @set.each {|i| yield i } end |
#empty? ⇒ Boolean
57 58 59 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/set.rb', line 57 def empty? @set.empty? end |
#exclude(*args) ⇒ Object Also known as: remove
the way to remove items from the set.
27 28 29 30 31 32 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/set.rb', line 27 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 |
#find_by_name(name) ⇒ Object Also known as: []
returns the item of the given name.
41 42 43 44 45 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/set.rb', line 41 def find_by_name(name) # this works because of `def item.==' item = @set.find { |c| c == name } item end |
#find_by_names(*names) ⇒ Object
returns an array of items with the provided names
36 37 38 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/set.rb', line 36 def find_by_names(*names) @set.find_all { |item| names.include? item } end |
#length ⇒ Object
returns the number of items in the set
53 54 55 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/set.rb', line 53 def length @set.length end |