Sha256: b915bea6273ed6ed026303a2220d320af9da60294d5f76a83dcb2f8786f9e221

Contents?: true

Size: 711 Bytes

Versions: 1

Compression:

Stored size: 711 Bytes

Contents

require 'stringio'

module Kernel
  def command_result(command, target = binding)
    is_command = Pry.commands.to_a.map(&:first).any? do |cmd|
      case cmd
      when Regexp
        cmd =~ command.split(' ').first
      when String
        cmd == command.split(' ').first
      end
    end

    pager = Pry.config.pager
    color = Pry.config.color
    Pry.config.pager = false
    Pry.config.color = false

    if is_command
      output = StringIO.new
      Pry.run_command(command, output: output, show_output: true)
      output.string
    else
      eval(command, target)
    end
  ensure
    Pry.config.color = color
    Pry.config.pager = pager
    output.close if output.respond_to? :close
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pry-command_result-0.0.4 lib/pry-command_result/kernel_ext.rb