banister/binding_of_caller


Retrieve the binding of a method's caller in MRI 1.9.2+

License: MIT

Language: C


Build Status

binding_of_caller

(C) John Mair (banisterfiend) 2012

Retrieve the binding of a method's caller in MRI (>= 1.9.2) and RBX (Rubinius)

The binding_of_caller gem provides the Binding#of_caller method.

Using binding_of_caller we can grab bindings from higher up the call stack and evaluate code in that context. Allows access to bindings arbitrarily far up the call stack, not limited to just the immediate caller.

Recommended for use only in debugging situations. Do not use this in production apps.

Works in MRI Ruby (>= 1.9.2) and RBX (Rubinius)

Example: Modifying a local inside the caller of a caller

def a
  var = 10
  b
  puts var
end

def b
  c
end

def c
  binding.of_caller(2).eval('var = :hello')
end

a()

# OUTPUT
# => hello

Spinoff project

This project is a spinoff from the Pry REPL project.

Features and limitations

  • Works in MRI (>= 1.9.2) and RBX (Rubinius)
  • Does not work in 1.8.7, but there is a well known (continuation-based) hack to get a Binding#of_caller there.
  • There is experimental support for jruby 1.7.x, but it only works in interpreted mode (i.e. use the option -Djruby.compile.mode=OFF or append compile.mode=OFF to your .jrubyrc)

Contact

Problems or questions contact me at github

License

(The MIT License)

Copyright (c) 2012 (John Mair)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Project Statistics

Sourcerank 17
Repository Size 365 KB
Stars 540
Forks 35
Watchers 17
Open issues 16
Dependencies 5
Contributors 16
Tags 12
Created
Last updated
Last pushed

Top Contributors See all

John Mair Amadeus Folego Jordon Bedwell Matt, Murahashi Kenichi Conrad Irwin Marc-André Lafortune Fabien LEFEBVRE Aboobacker MK cabo Chris Marshall Akira Matsuda David Celis Lennart Fridén Omer Katz Martin Schürrer Chris Price

Packages Referencing this Repo

binding_of_caller
Retrieve the binding of a method's caller. Can also retrieve bindings even further up the stack.
Latest release 0.8.0 - Updated - 540 stars

Recent Tags See all

v0.8.0 January 10, 2018
v0.7.3 October 22, 2017
v0.7.3.pre1 August 20, 2014
v0.7.2 June 07, 2013
v0.7.0 February 16, 2013
v0.6.9 February 14, 2013
v0.6.8 September 12, 2012
v0.6.7 March 06, 2012
v0.6.6 March 01, 2012
v0.6.5 February 29, 2012
v0.6.4 February 29, 2012
v0.4.0 October 19, 2011

Interesting Forks See all

MSch/binding_of_caller
Retrieve the binding of a method's caller in MRI 1.9.2
C - MIT - Updated - 1 stars

Something wrong with this page? Make a suggestion

Last synced: 2018-01-10 15:15:49 UTC

Login to resync this repository