Class: Keydown::Classnames
- Inherits:
-
Object
- Object
- Keydown::Classnames
- Defined in:
- lib/keydown/classnames.rb
Instance Method Summary collapse
- #add(names) ⇒ Object
- #include?(name) ⇒ Boolean
-
#initialize(names = '') ⇒ Classnames
constructor
A new instance of Classnames.
- #remove(names) ⇒ Object
- #to_hash ⇒ Object
- #to_s ⇒ Object
Constructor Details
permalink #initialize(names = '') ⇒ Classnames
Returns a new instance of Classnames.
4 5 6 7 |
# File 'lib/keydown/classnames.rb', line 4 def initialize(names = '') @names = [] add(names) end |
Instance Method Details
permalink #add(names) ⇒ Object
[View source]
9 10 11 12 |
# File 'lib/keydown/classnames.rb', line 9 def add(names) @names += names.split(" ") @names.uniq! end |
permalink #include?(name) ⇒ Boolean
18 19 20 |
# File 'lib/keydown/classnames.rb', line 18 def include?(name) @names.include? name end |
permalink #remove(names) ⇒ Object
[View source]
14 15 16 |
# File 'lib/keydown/classnames.rb', line 14 def remove(names) @names -= names.split(' ') end |
permalink #to_hash ⇒ Object
[View source]
22 23 24 |
# File 'lib/keydown/classnames.rb', line 22 def to_hash @names.empty? ? {} : { :class => self.to_s } end |
permalink #to_s ⇒ Object
[View source]
26 27 28 |
# File 'lib/keydown/classnames.rb', line 26 def to_s @names.sort.join(' ') end |