Class: Rouge::RegexLexer::Rule
- Inherits:
-
Object
- Object
- Rouge::RegexLexer::Rule
- Defined in:
- lib/rouge/regex_lexer.rb
Overview
A rule is a tuple of a regular expression to test, and a callback to perform if the test succeeds.
Instance Attribute Summary collapse
-
#callback ⇒ Object
readonly
Returns the value of attribute callback.
-
#re ⇒ Object
readonly
Returns the value of attribute re.
Instance Method Summary collapse
-
#beginning_of_line? ⇒ Boolean
Does the regex start with a ^?.
-
#initialize(re, callback) ⇒ Rule
constructor
A new instance of Rule.
- #inspect ⇒ Object
Constructor Details
#initialize(re, callback) ⇒ Rule
Returns a new instance of Rule.
13 14 15 16 |
# File 'lib/rouge/regex_lexer.rb', line 13 def initialize(re, callback) @re = re @callback = callback end |
Instance Attribute Details
#callback ⇒ Object (readonly)
Returns the value of attribute callback.
11 12 13 |
# File 'lib/rouge/regex_lexer.rb', line 11 def callback @callback end |
#re ⇒ Object (readonly)
Returns the value of attribute re.
12 13 14 |
# File 'lib/rouge/regex_lexer.rb', line 12 def re @re end |
Instance Method Details
#beginning_of_line? ⇒ Boolean
Does the regex start with a ^?
Since Regexps are immuntable, this is cached to avoid calling Regexp#source more than once.
22 23 24 25 26 |
# File 'lib/rouge/regex_lexer.rb', line 22 def beginning_of_line? return @beginning_of_line if instance_variable_defined?(:@beginning_of_line) @beginning_of_line = re.source[0] == ?^ end |
#inspect ⇒ Object
28 29 30 |
# File 'lib/rouge/regex_lexer.rb', line 28 def inspect "#<Rule #{@re.inspect}>" end |