Class: Ripar::Combinder::BindingWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/ripar/combinder.rb

Overview

Forward method calls to bound variables Could probably just use Combinder here. TODO this should be accessing bound_self, right? Variables are accessed anyway by Ruby interpreter because They’re in the binding. Not sure.

Instance Method Summary collapse

Constructor Details

#initialize(wrapped_binding) ⇒ BindingWrapper

Returns a new instance of BindingWrapper.



87
88
89
90
# File 'lib/ripar/combinder.rb', line 87

def initialize( wrapped_binding )
  @binding = wrapped_binding
  @binding.extend BindingNiceness
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &blk) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/ripar/combinder.rb', line 92

def method_missing(meth, *args, &blk)
  ::Kernel.raise "outside variables can't take arguments" if args.size != 0

  if @binding.local_variables.include?( meth )
    @binding.eval meth.to_s
  elsif @binding.self.respond_to? meth
    @binding.self.send meth, *args, &blk
  else
    ::Kernel.raise NoMethodError, "No such outside variable #{meth}"
  end
end

Instance Method Details

#respond_to_missing?(meth, include_all = false) ⇒ Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/ripar/combinder.rb', line 104

def respond_to_missing?( meth, include_all = false )
  @binding.local_variables.include?(meth) || @binding.self.respond_to?(meth, include_all)
end