diff options
author | Robert <r-obert@users.noreply.github.com> | 2017-09-01 14:37:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-01 14:37:04 +0100 |
commit | a93e9a924bf2bba5276fa65440ec3dca9c1deb8b (patch) | |
tree | c40bdf9c73ade181f8549cd44cba6ffc6a94ee1f | |
parent | 075a5c4a45469ec5b0e34e21674e197d89829cee (diff) | |
parent | a54a5c76bd7108469c77ce6b66e5b3b43deacf1d (diff) | |
download | pry-a93e9a924bf2bba5276fa65440ec3dca9c1deb8b.tar.gz |
Merge pull request #1635 from pry/pry-helpers
add Pry#helpers, fix #1634
-rw-r--r-- | lib/pry/helpers/colors.rb | 2 | ||||
-rw-r--r-- | lib/pry/pry_instance.rb | 23 |
2 files changed, 24 insertions, 1 deletions
diff --git a/lib/pry/helpers/colors.rb b/lib/pry/helpers/colors.rb index de5c2faf..b1c7967b 100644 --- a/lib/pry/helpers/colors.rb +++ b/lib/pry/helpers/colors.rb @@ -14,7 +14,7 @@ module Pry::Helpers::Colors } color_enabled = lambda do |pry| - (pry and pry.color) or (defined?(_pry_) and _pry_.color) or Pry.color + (pry and pry.color) or (defined?(_pry_) ? _pry_.color : Pry.color) end COLORS.each_pair do |color, value| diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb index 4ffe4c58..c4664505 100644 --- a/lib/pry/pry_instance.rb +++ b/lib/pry/pry_instance.rb @@ -81,6 +81,29 @@ class Pry exec_hook(:when_started, target, options, self) end + # + # @example + # + # Pry.hooks.add_hook(:before_session, "hook_name") do |_, _, pry| + # puts pry.helpers.green("Starting new session.") + # end + # + # @return [Module] + # Returns a module that includes utility helper functions from + # {Pry::Helpers::Text}, and {Pry::Helpers::BaseHelpers}. + # + def helpers + @helpers ||= lambda { + this = self + Module.new do + include Pry::Helpers::Text + include Pry::Helpers::BaseHelpers + define_method(:_pry_) { this } + extend self + end + }.call + end + # The current prompt. # This is the prompt at the top of the prompt stack. # |