Permalink
Browse files

Pry::WrappedModule.from_str respects binding

* module are now looked up with respect to the optional binding parameter to from_str
* also improved some docs
  • Loading branch information...
1 parent e6b280d commit 08dd259161dba1d27f128324c3c75bdb606c0252 @banister banister committed Apr 17, 2012
@@ -18,8 +18,8 @@ module DefaultCommands
Use the `-n` switch (the default) to search for methods whose name matches the given regex.
Use the `-c` switch to search for methods that contain the given code.
- e.g find re Pry # find all methods whose name match /re/. Matches Pry#repl, etc.
- e.g find -c 'output.puts' Pry # find all methods that contain the code: output.puts
+ e.g find re Pry # find all methods whose name match /re/ inside the Pry namespace. Matches Pry#repl, etc.
+ e.g find -c 'output.puts' Pry # find all methods that contain the code: output.puts inside the Pry namepsace.
BANNER
def setup
@@ -67,7 +67,7 @@ def options(opt)
end
def process_module(name)
- mod = Pry::WrappedModule.from_str(name)
+ mod = Pry::WrappedModule.from_str(name, target)
if opts.present?(:all)
all_modules(mod)
@@ -187,8 +187,8 @@ def process
description "Show the source for METH or CLASS. Aliases: $, show-method"
banner <<-BANNER
- Usage: show-method [OPTIONS] [METH|CLASS]
- Aliases: $, show-source
+ Usage: show-source [OPTIONS] [METH|CLASS]
+ Aliases: $, show-method
Show the source for method METH or CLASS. Tries instance methods first and then methods by default.
@@ -227,7 +227,7 @@ def process_method
end
def process_module(name)
- mod = Pry::WrappedModule.from_str(name)
+ mod = Pry::WrappedModule.from_str(name, target)
if opts.present?(:all)
all_modules(mod)
@@ -26,7 +26,12 @@ class WrappedModule
# @example
# Pry::WrappedModule.from_str("Pry::Code")
def self.from_str(mod_name, binding=TOPLEVEL_BINDING)
- Pry::WrappedModule.new(binding.eval(mod_name))
+ mod = binding.eval(mod_name)
+ if mod.is_a?(Module)
+ Pry::WrappedModule.new(mod)
+ else
+ nil
+ end
rescue RescuableException
nil
end

0 comments on commit 08dd259

Please sign in to comment.