Skip to content

Commit

Permalink
Pry::WrappedModule.from_str respects binding
Browse files Browse the repository at this point in the history
* module are now looked up with respect to the optional binding parameter to from_str
* also improved some docs
  • Loading branch information
banister committed Apr 17, 2012
1 parent e6b280d commit 08dd259
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/pry/default_commands/find_method.rb
Expand Up @@ -18,8 +18,8 @@ module DefaultCommands
Use the `-n` switch (the default) to search for methods whose name matches the given regex. 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. 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 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 e.g find -c 'output.puts' Pry # find all methods that contain the code: output.puts inside the Pry namepsace.
BANNER BANNER


def setup def setup
Expand Down
8 changes: 4 additions & 4 deletions lib/pry/default_commands/introspection.rb
Expand Up @@ -67,7 +67,7 @@ def options(opt)
end end


def process_module(name) def process_module(name)
mod = Pry::WrappedModule.from_str(name) mod = Pry::WrappedModule.from_str(name, target)


if opts.present?(:all) if opts.present?(:all)
all_modules(mod) all_modules(mod)
Expand Down Expand Up @@ -187,8 +187,8 @@ def process
description "Show the source for METH or CLASS. Aliases: $, show-method" description "Show the source for METH or CLASS. Aliases: $, show-method"


banner <<-BANNER banner <<-BANNER
Usage: show-method [OPTIONS] [METH|CLASS] Usage: show-source [OPTIONS] [METH|CLASS]
Aliases: $, show-source Aliases: $, show-method
Show the source for method METH or CLASS. Tries instance methods first and then methods by default. Show the source for method METH or CLASS. Tries instance methods first and then methods by default.
Expand Down Expand Up @@ -227,7 +227,7 @@ def process_method
end end


def process_module(name) def process_module(name)
mod = Pry::WrappedModule.from_str(name) mod = Pry::WrappedModule.from_str(name, target)


if opts.present?(:all) if opts.present?(:all)
all_modules(mod) all_modules(mod)
Expand Down
7 changes: 6 additions & 1 deletion lib/pry/wrapped_module.rb
Expand Up @@ -26,7 +26,12 @@ class WrappedModule
# @example # @example
# Pry::WrappedModule.from_str("Pry::Code") # Pry::WrappedModule.from_str("Pry::Code")
def self.from_str(mod_name, binding=TOPLEVEL_BINDING) 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 rescue RescuableException
nil nil
end end
Expand Down

0 comments on commit 08dd259

Please sign in to comment.