Class: Tags
- Inherits:
-
Object
- Object
- Tags
- Includes:
- Comparable
- Defined in:
- lib/tags.rb,
lib/tags/version.rb
Constant Summary collapse
- VERSION =
"1.0.1"
Instance Method Summary collapse
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #<=>(other) ⇒ Object
-
#initialize(str_or_ary = nil) ⇒ Tags
constructor
A new instance of Tags.
- #to_a ⇒ Object
- #to_s ⇒ Object
- #to_set ⇒ Object
Constructor Details
#initialize(str_or_ary = nil) ⇒ Tags
Returns a new instance of Tags.
10 11 12 13 |
# File 'lib/tags.rb', line 10 def initialize(str_or_ary = nil) ary = str_or_ary.is_a?(Array) ? str_or_ary : str_or_ary.to_s.split(' ') @tags_set = Set.new(ary) end |
Instance Method Details
#+(other) ⇒ Object
33 34 35 36 37 |
# File 'lib/tags.rb', line 33 def +(other) raise ArgumentError, "must be a #{self.class} object" unless other.is_a?(self.class) ary_add = ( + other.to_set).to_a self.class.new(ary_add) end |
#-(other) ⇒ Object
27 28 29 30 31 |
# File 'lib/tags.rb', line 27 def -(other) raise ArgumentError, "must be a #{self.class} object" unless other.is_a?(self.class) ary_diff = ( - other.to_set).to_a self.class.new(ary_diff) end |
#<=>(other) ⇒ Object
39 40 41 |
# File 'lib/tags.rb', line 39 def <=>(other) <=> other.to_set end |
#to_a ⇒ Object
19 20 21 |
# File 'lib/tags.rb', line 19 def to_a .to_a end |
#to_s ⇒ Object
15 16 17 |
# File 'lib/tags.rb', line 15 def to_s to_a.join(' ') end |
#to_set ⇒ Object
23 24 25 |
# File 'lib/tags.rb', line 23 def to_set .dup end |