Class: Rox::Core::RegularExpressionExtensions
- Inherits:
-
Object
- Object
- Rox::Core::RegularExpressionExtensions
- Defined in:
- lib/rox/core/roxx/regular_expression_extensions.rb
Instance Method Summary collapse
- #extend ⇒ Object
-
#initialize(parser) ⇒ RegularExpressionExtensions
constructor
A new instance of RegularExpressionExtensions.
Constructor Details
#initialize(parser) ⇒ RegularExpressionExtensions
Returns a new instance of RegularExpressionExtensions.
4 5 6 |
# File 'lib/rox/core/roxx/regular_expression_extensions.rb', line 4 def initialize(parser) @parser = parser end |
Instance Method Details
#extend ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rox/core/roxx/regular_expression_extensions.rb', line 8 def extend @parser.add_operator('match') do |_parser, stack, _context| text = stack.pop pattern = stack.pop flags = stack.pop unless text.is_a?(String) && pattern.is_a?(String) && flags.is_a?(String) raise ArgumentError, 'should be string' end = 0 flags.each_char do |flag| case flag when 'i' |= Regexp::IGNORECASE when 'x' |= Regexp::EXTENDED when 'm' |= Regexp::MULTILINE end end matched = !Regexp.new(pattern, ).match(text).nil? stack.push(matched) end end |