Class: Rux::Lex::CharsetPattern
- Inherits:
-
Object
- Object
- Rux::Lex::CharsetPattern
- Defined in:
- lib/rux/lex/patterns.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#chars ⇒ Object
readonly
Returns the value of attribute chars.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(chars) ⇒ CharsetPattern
constructor
A new instance of CharsetPattern.
- #matches?(char) ⇒ Boolean
Constructor Details
#initialize(chars) ⇒ CharsetPattern
Returns a new instance of CharsetPattern.
26 27 28 |
# File 'lib/rux/lex/patterns.rb', line 26 def initialize(chars) @chars = Set.new(chars) end |
Instance Attribute Details
#chars ⇒ Object (readonly)
Returns the value of attribute chars.
24 25 26 |
# File 'lib/rux/lex/patterns.rb', line 24 def chars @chars end |
Class Method Details
.parse(str) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rux/lex/patterns.rb', line 10 def self.parse(str) pairs = str.scan(/(.)-?(.)?/) new( pairs.flat_map do |pair| if pair[1] (pair[0]..pair[1]).to_a else [pair[0]] end end ) end |
Instance Method Details
#matches?(char) ⇒ Boolean
30 31 32 |
# File 'lib/rux/lex/patterns.rb', line 30 def matches?(char) chars.include?(char) end |