Class: Parslet::Context Private

Inherits:
Object
  • Object
show all
Includes:
Parslet
Defined in:
lib/parslet/context.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Provides a context for tree transformations to run in. The context allows accessing each of the bindings in the bindings hash as local method.

Example:

ctx = Context.new(:a => :b)
ctx.instance_eval do 
  a # => :b
end

Instance Method Summary collapse

Methods included from Parslet

any, dynamic, exp, included, infix_expression, match, scope, sequence, simple, str, subtree

Constructor Details

#initialize(bindings) ⇒ Context

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Context



15
16
17
18
19
20
# File 'lib/parslet/context.rb', line 15

def initialize(bindings)
  bindings.each do |key, value|
    singleton_class.send(:define_method, key) { value }
    instance_variable_set("@#{key}", value)
  end
end