module Mustermann::Concat::Native
Mixin for patterns to support native concatenation. @!visibility private
Public Instance Methods
Source
# File lib/mustermann/concat.rb, line 11 def +(other) other &&= Mustermann.new(other, type: :identity, **options) if (patterns = look_ahead(other)) && !patterns.empty? concat = (self + patterns.inject(:+)) concat + other.patterns.slice(patterns.length..-1).inject(:+) else return super unless native = native_concat(other) self.class.new(native, **options) end end
@see Mustermann::Pattern#+
@!visibility private
Calls superclass method
Source
# File lib/mustermann/concat.rb, line 23 def look_ahead(other) return unless other.is_a?(Concat) other.patterns.take_while(&method(:native_concat?)) end
@!visibility private
Private Instance Methods
Source
# File lib/mustermann/concat.rb, line 29 def native_concat(other) "#{self}#{other}" if native_concat?(other) end
@!visibility private
Source
# File lib/mustermann/concat.rb, line 34 def native_concat?(other) other.class == self.class and other.options == options end
@!visibility private