diff options
Diffstat (limited to 'lib/pry/warning.rb')
-rw-r--r-- | lib/pry/warning.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/pry/warning.rb b/lib/pry/warning.rb new file mode 100644 index 00000000..6f7bee76 --- /dev/null +++ b/lib/pry/warning.rb @@ -0,0 +1,25 @@ +class Pry + # @api private + # @since ?.?.? + module Warning + # Prints a warning message with exact file and line location, similar to how + # Ruby's -W prints warnings. + # + # @param [String] message + # @return [void] + def self.warn(message) + if Kernel.respond_to?(:caller_locations) + location = caller_locations(1..1).first + path = location.path + lineno = location.lineno + else + # Ruby 1.9.3 support. + frame = caller.first.split(':') # rubocop:disable Performance/Caller + path = frame.first + lineno = frame[1] + end + + Kernel.warn("#{path}:#{lineno}: warning: #{message}") + end + end +end |