Module: Peregrine::Features::Taggable
- Defined in:
- lib/peregrine/features/taggable.rb
Overview
Provides methods for adding and removing tags to and from objects. This essentially provides yet another method for identifying and filtering various objects. Intended to be included in classes requiring this functionality.
Instance Method Summary collapse
-
#add_tags(*list) ⇒ Object
(also: #add_tag)
Add the given tags to the object.
-
#remove_tags!(*list) ⇒ Object
(also: #remove_tag!)
Removes the given tags from the object.
-
#tags ⇒ Object
Returns the array of tags this object contains.
Instance Method Details
#add_tags(*list) ⇒ Object Also known as: add_tag
Add the given tags to the object. Tags may be any kind of object. Tags identical to existing tags are ignored. Returns an array of all tags this object contains.
16 17 18 19 |
# File 'lib/peregrine/features/taggable.rb', line 16 def (*list) .push(*list).uniq! end |
#remove_tags!(*list) ⇒ Object Also known as: remove_tag!
Removes the given tags from the object. Returns an array of the removed tags.
24 25 26 27 28 |
# File 'lib/peregrine/features/taggable.rb', line 24 def (*list) removed = [] .reject! { |tag| list.include?(tag) ? removed.push(tag) : false } removed end |
#tags ⇒ Object
Returns the array of tags this object contains. Lazily evaluated.
9 10 11 |
# File 'lib/peregrine/features/taggable.rb', line 9 def ||= [] end |