class Parslet::Context

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

@api private

Public Class Methods

new(bindings) click to toggle source
# File lib/parslet/context.rb, line 29
def initialize(bindings)
  bindings.each do |key, value|
    meta_def(key.to_sym) { value }
    instance_variable_set("@#{key}", value)
  end
end

Public Instance Methods

meta_def(name, &body) click to toggle source
# File lib/parslet/context.rb, line 23
def meta_def(name, &body)
  metaclass = class << self; self; end

  metaclass.send(:define_method, name, &body)
end