Sha256: 4eab82374cf6aeed898ecf7d39fd4117c79f3b07186c74fcebd83cc0591cea03

Contents?: true

Size: 696 Bytes

Versions: 9

Compression:

Stored size: 696 Bytes

Contents

module Hobo

  class ProcBinding

    def self.eval(proc, self_, locals)
      ProcBinding.new(self_, locals).instance_eval(&proc)
    end

    def initialize(self_, locals)
      @self_ = self_
      @locals = locals
      locals.symbolize_keys!
    end

    def method_missing(name, *args, &block)
      if @locals.has_key?(name)
        @locals[name]
      else
        @self_.send(name, *args, &block)
      end
    end

  end

  (Object.instance_methods + 
   Object.private_instance_methods +
   Object.protected_instance_methods).each do |m|
    ProcBinding.send(:undef_method, m) unless
      %w{initialize method_missing send instance_eval}.include?(m) || m.starts_with?('_')
  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
hobo-0.5.3 hobo_files/plugin/lib/hobo/proc_binding.rb
hobo-0.6 hobo_files/plugin/lib/hobo/proc_binding.rb
hobo-0.6.1 hobo_files/plugin/lib/hobo/proc_binding.rb
hobo-0.6.2 hobo_files/plugin/lib/hobo/proc_binding.rb
hobo-0.6.3 hobo_files/plugin/lib/hobo/proc_binding.rb
hobo-0.6.4 hobo_files/plugin/lib/hobo/proc_binding.rb
hobo-0.7.0 hobo_files/plugin/lib/hobo/proc_binding.rb
hobo-0.7.1 hobo_files/plugin/lib/hobo/proc_binding.rb
hobo-0.7.2 hobo_files/plugin/lib/hobo/proc_binding.rb