Class: Protos::TokenList
- Inherits:
-
Object
- Object
- Protos::TokenList
- Defined in:
- lib/protos/token_list.rb
Instance Attribute Summary collapse
-
#tokens ⇒ Object
readonly
DOCS: A list of utility tokens that can handle parsing and merging sets of tokens together safely.
Instance Method Summary collapse
- #add(tokens) ⇒ Object
- #clear ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(tokens = []) ⇒ TokenList
constructor
A new instance of TokenList.
- #remove(tokens) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(tokens = []) ⇒ TokenList
Returns a new instance of TokenList.
10 11 12 |
# File 'lib/protos/token_list.rb', line 10 def initialize(tokens = []) @tokens = Set.new(tokens) end |
Instance Attribute Details
#tokens ⇒ Object (readonly)
DOCS: A list of utility tokens that can handle parsing and merging sets of tokens together safely.
8 9 10 |
# File 'lib/protos/token_list.rb', line 8 def tokens @tokens end |
Instance Method Details
#add(tokens) ⇒ Object
27 28 29 30 |
# File 'lib/protos/token_list.rb', line 27 def add(tokens) @tokens.merge(parse(tokens)) self end |
#clear ⇒ Object
32 33 34 35 |
# File 'lib/protos/token_list.rb', line 32 def clear @tokens.clear self end |
#empty? ⇒ Boolean
14 15 16 |
# File 'lib/protos/token_list.rb', line 14 def empty? @tokens.empty? end |
#remove(tokens) ⇒ Object
22 23 24 25 |
# File 'lib/protos/token_list.rb', line 22 def remove(tokens) @tokens.subtract(parse(tokens)) self end |
#to_s ⇒ Object
18 19 20 |
# File 'lib/protos/token_list.rb', line 18 def to_s @tokens.join(" ") end |