module Regexp::Expression::Shared
def to_s(format = :full)
lit.to_s(:original) # => 'a +' # with quantifier AND intermittent decorations
lit.to_s(:base) # => 'a' # without quantifier
lit.to_s(:full) # => 'a+' # default; with quantifier
lit.to_s # => 'a+' # default; with quantifier
lit = Regexp::Parser.parse(/a +/x)[0]
Example:
It takes an optional format argument.
#to_s reproduces the original source, as an unparser would.
def to_s(format = :full) base = parts.each_with_object(''.dup) do |part, buff| if part.instance_of?(String) buff << part elsif !part.custom_to_s_handling buff << part.to_s(:original) end end "#{base}#{pre_quantifier_decoration(format)}#{quantifier_affix(format)}" end