Class: Lab42::Rgxargs::SyntaxDefiner
- Inherits:
-
Object
- Object
- Lab42::Rgxargs::SyntaxDefiner
- Defined in:
- lib/lab42/rgxargs/syntax_definer.rb
Overview
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
```
Instance Attribute Summary collapse
-
#arg_name ⇒ Object
readonly
Returns the value of attribute arg_name.
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
Instance Method Summary collapse
Instance Attribute Details
#arg_name ⇒ Object (readonly)
Returns the value of attribute arg_name.
14 15 16 |
# File 'lib/lab42/rgxargs/syntax_definer.rb', line 14 def arg_name @arg_name end |
#parser ⇒ Object (readonly)
Returns the value of attribute parser.
14 15 16 |
# File 'lib/lab42/rgxargs/syntax_definer.rb', line 14 def parser @parser end |
Instance Method Details
#run(code) ⇒ Object
16 17 18 |
# File 'lib/lab42/rgxargs/syntax_definer.rb', line 16 def run code instance_exec(&code) end |
#syntax(matcher, value = nil, &blk) ⇒ Object
20 21 22 23 24 25 26 |
# 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 |