Skip to content

Instantly share code, notes, and snippets.

@KL-7
Created November 29, 2011 23:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KL-7/1407204 to your computer and use it in GitHub Desktop.
Save KL-7/1407204 to your computer and use it in GitHub Desktop.
binding.pry inside unbound method that was removed from the classes
$ cat pry-method-name.rb
require 'rubygems'
require 'pry'
class A
def self.generate_method(name)
define_method name do
binding.pry
end
m = instance_method name
remove_method name
m
end
end
um = A.generate_method('foo').bind(A.new).call
$ ruby pry-method-name.rb
pry-method-name.rb:7:in `method': undefined method `foo' for class `A' (NameError)
from pry-method-name.rb:7:in `block in generate_method'
from /home/kl-7/.rvm/gems/ruby-1.9.2-p290@global/gems/pry-0.9.7.4/lib/pry/method.rb:51:in `eval'
from /home/kl-7/.rvm/gems/ruby-1.9.2-p290@global/gems/pry-0.9.7.4/lib/pry/method.rb:51:in `from_binding'
from /home/kl-7/.rvm/gems/ruby-1.9.2-p290@global/gems/pry-0.9.7.4/lib/pry/default_commands/context.rb:141:in `block (2 levels) in <module:DefaultCommands>'
from /home/kl-7/.rvm/gems/ruby-1.9.2-p290@global/gems/pry-0.9.7.4/lib/pry/command_set.rb:19:in `instance_exec'
from /home/kl-7/.rvm/gems/ruby-1.9.2-p290@global/gems/pry-0.9.7.4/lib/pry/command_set.rb:19:in `call'
from /home/kl-7/.rvm/gems/ruby-1.9.2-p290@global/gems/pry-0.9.7.4/lib/pry/command_set.rb:200:in `run_command'
from /home/kl-7/.rvm/gems/ruby-1.9.2-p290@global/gems/pry-0.9.7.4/lib/pry/command_processor.rb:173:in `block in execute_command'
from /home/kl-7/.rvm/gems/ruby-1.9.2-p290@global/gems/pry-0.9.7.4/lib/pry/command_processor.rb:172:in `catch'
from /home/kl-7/.rvm/gems/ruby-1.9.2-p290@global/gems/pry-0.9.7.4/lib/pry/command_processor.rb:172:in `execute_command'
from /home/kl-7/.rvm/gems/ruby-1.9.2-p290@global/gems/pry-0.9.7.4/lib/pry/command_processor.rb:143:in `process_commands'
from /home/kl-7/.rvm/gems/ruby-1.9.2-p290@global/gems/pry-0.9.7.4/lib/pry/pry_instance.rb:346:in `process_line'
from /home/kl-7/.rvm/gems/ruby-1.9.2-p290@global/gems/pry-0.9.7.4/lib/pry.rb:16:in `block in <class:Pry>'
from /home/kl-7/.rvm/gems/ruby-1.9.2-p290@global/gems/pry-0.9.7.4/lib/pry/pry_instance.rb:113:in `call'
from /home/kl-7/.rvm/gems/ruby-1.9.2-p290@global/gems/pry-0.9.7.4/lib/pry/pry_instance.rb:113:in `exec_hook'
from /home/kl-7/.rvm/gems/ruby-1.9.2-p290@global/gems/pry-0.9.7.4/lib/pry/pry_instance.rb:152:in `repl_prologue'
from /home/kl-7/.rvm/gems/ruby-1.9.2-p290@global/gems/pry-0.9.7.4/lib/pry/pry_instance.rb:183:in `repl'
from /home/kl-7/.rvm/gems/ruby-1.9.2-p290@global/gems/pry-0.9.7.4/lib/pry/pry_class.rb:97:in `start'
from /home/kl-7/.rvm/gems/ruby-1.9.2-p290@global/gems/pry-0.9.7.4/lib/pry/core_extensions.rb:20:in `pry'
from pry-method-name.rb:7:in `block in generate_method'
from pry-method-name.rb:15:in `call'
from pry-method-name.rb:15:in `<main>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment