2011-04-30 03:08:01 -04:00
|
|
|
class Object
|
2012-04-01 06:52:50 -04:00
|
|
|
# Start a Pry REPL. This method only differs from Pry.start in that it
|
2012-04-01 07:02:04 -04:00
|
|
|
# assumes that the target is `self`. It also accepts and passses the same
|
|
|
|
# exact options hash that Pry.start accepts. POSSIBLE DEPRICATION WARNING:
|
2012-04-01 06:52:50 -04:00
|
|
|
# In the future the backwards compatibility with pry(binding) could be
|
|
|
|
# removed so please properly use Object.pry or if you use pry(binding)
|
|
|
|
# switch Pry.start(binding).
|
|
|
|
|
|
|
|
# @param [Binding] the binding or options hash if no binding needed.
|
|
|
|
# @param [Hash] the options hash.
|
|
|
|
# @example First
|
2011-04-30 03:08:01 -04:00
|
|
|
# "dummy".pry
|
2012-04-01 06:52:50 -04:00
|
|
|
# @example Second
|
|
|
|
# binding.pry
|
|
|
|
# @example An example with options
|
|
|
|
# def my_method
|
|
|
|
# binding.pry :quiet => true
|
|
|
|
# end
|
|
|
|
# my_method()
|
2012-04-01 04:51:55 -04:00
|
|
|
|
2012-04-01 06:52:50 -04:00
|
|
|
def pry(*args)
|
|
|
|
if args.first.is_a?(Hash) || args.length == 0
|
|
|
|
args.unshift(self)
|
2012-04-01 04:51:55 -04:00
|
|
|
end
|
2012-06-06 19:20:51 -04:00
|
|
|
|
2012-04-01 06:52:50 -04:00
|
|
|
Pry.start(*args)
|
2011-04-30 03:08:01 -04:00
|
|
|
end
|
2010-12-30 10:01:11 -05:00
|
|
|
|
2011-04-30 03:08:01 -04:00
|
|
|
# Return a binding object for the receiver.
|
|
|
|
def __binding__
|
|
|
|
if is_a?(Module)
|
|
|
|
return class_eval "binding"
|
2010-12-25 08:59:37 -05:00
|
|
|
end
|
|
|
|
|
2012-06-06 19:20:51 -04:00
|
|
|
unless respond_to?(binding_impl = :__binding_impl__)
|
|
|
|
binding_impl_method = <<-METHOD
|
|
|
|
def #{binding_impl}
|
|
|
|
binding
|
|
|
|
end
|
|
|
|
METHOD
|
|
|
|
|
2011-04-30 03:08:01 -04:00
|
|
|
begin
|
2012-06-06 19:20:51 -04:00
|
|
|
instance_eval binding_impl_method
|
2011-04-30 03:08:01 -04:00
|
|
|
rescue TypeError
|
2012-06-06 19:20:51 -04:00
|
|
|
self.class.class_eval binding_impl_method
|
2010-12-25 08:59:37 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-04-30 03:08:01 -04:00
|
|
|
__binding_impl__
|
|
|
|
end
|
2010-12-25 08:59:37 -05:00
|
|
|
end
|
2012-05-26 03:30:38 -04:00
|
|
|
|
|
|
|
# There's a splat bug on jruby in 1.9 emulation mode, which breaks the
|
|
|
|
# pp library.
|
|
|
|
#
|
|
|
|
# * http://jira.codehaus.org/browse/JRUBY-6687
|
|
|
|
# * https://github.com/pry/pry/issues/568
|
|
|
|
#
|
|
|
|
# Until that gets fixed upstream, let's monkey-patch here:
|
|
|
|
if [[1, 2]].pretty_inspect == "[1]\n"
|
|
|
|
class Array
|
|
|
|
def pretty_print(q)
|
|
|
|
q.group(1, '[', ']') {
|
|
|
|
i = 0
|
|
|
|
q.seplist(self) { |*|
|
|
|
|
q.pp self[i]
|
|
|
|
i += 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|