class Lab42::Rgxargs::SyntaxDefiner

Instanciated with an Rgxargs parser it can run a block in its own context so that the block accesses the parser's functionality with syntactic sugar w/o cluttering ther parser itself with too many methods E.g.:

```ruby
    syntax

```

Attributes

arg_name[R]
parser[R]

Public Class Methods

new(parser, arg_name) click to toggle source
# File lib/lab42/rgxargs/syntax_definer.rb, line 30
def initialize(parser, arg_name)
  @arg_name = arg_name
  @parser   = parser
end

Public Instance Methods

run(code) click to toggle source
# File lib/lab42/rgxargs/syntax_definer.rb, line 16
def run code
  instance_exec(&code)
end
syntax(matcher, value=nil, &blk) click to toggle source
# File lib/lab42/rgxargs/syntax_definer.rb, line 20
def syntax(matcher, value=nil, &blk)
  if value
    parser.add_syntax(matcher, ->(){value}, as: arg_name )
  else
    parser.add_syntax(matcher, blk, as: arg_name)
  end
end