Sha256: d597679a606b2d7479fa4208ea9f154ec406fe95bf7d6bb773c1aab540ffc923

Contents?: true

Size: 735 Bytes

Versions: 3

Compression:

Stored size: 735 Bytes

Contents

require 'blankslate'

# 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
class Parslet::Context < BlankSlate
  reveal :methods
  reveal :respond_to?
  reveal :inspect
  reveal :to_s
  reveal :instance_variable_set

  include Parslet
  
  def meta_def(name, &body)
    metaclass = class << self; self; end

    metaclass.send(:define_method, name, &body)
  end
  
  def initialize(bindings)
    bindings.each do |key, value|
      meta_def(key.to_sym) { value }
      instance_variable_set("@#{key}", value)
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
swift-pyrite-0.1.1 vendor/bundle/ruby/2.0.0/gems/parslet-1.7.1/lib/parslet/context.rb
swift-pyrite-0.1.0 vendor/bundle/ruby/2.0.0/gems/parslet-1.7.1/lib/parslet/context.rb
parslet-1.7.1 lib/parslet/context.rb