Class: Parslet::Transform::Context
- Inherits:
-
BlankSlate
- Object
- BlankSlate
- Parslet::Transform::Context
- Defined in:
- lib/parslet/transform/context.rb
Overview
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
-
#initialize(bindings) ⇒ Context
constructor
A new instance of Context.
- #meta_def(name, &body) ⇒ Object
Constructor Details
#initialize(bindings) ⇒ Context
Returns a new instance of Context.
26 27 28 29 30 31 |
# File 'lib/parslet/transform/context.rb', line 26 def initialize(bindings) bindings.each do |key, value| (key.to_sym) { value } instance_variable_set("@#{key}", value) end end |
Instance Method Details
#meta_def(name, &body) ⇒ Object
20 21 22 23 24 |
# File 'lib/parslet/transform/context.rb', line 20 def (name, &body) = class <<self; self; end .send(:define_method, name, &body) end |