class MaybePattern

An optional pattern for some pattern `p` this is equivalent to (?:p?)

Public Class Methods

new(*args) click to toggle source

Construct a new MaybePattern

@param [any] args arguments to pass to {PatternBase#initialize} @api private

@see maybe @see PatternBase#maybe

Calls superclass method RepeatablePattern::new
# File lib/ruby_grammar_builder/pattern_extensions/maybe.rb, line 14
def initialize(*args)
    # run the normal pattern
    super(*args)
    # add quantifying options
    @at_least = 0
    @at_most = 1
end

Public Instance Methods

do_get_to_s_name(top_level) click to toggle source

(see PatternBase#do_get_to_s_name)

# File lib/ruby_grammar_builder/pattern_extensions/maybe.rb, line 29
def do_get_to_s_name(top_level)
    top_level ? "maybe(" : ".maybe("
end
quantifying_allowed?() click to toggle source

(see Pattern#quantifying_allowed?) @return [false]

# File lib/ruby_grammar_builder/pattern_extensions/maybe.rb, line 24
def quantifying_allowed?
    false
end