Sha256: 95802d43b5e674b5f0ba457f6450b9b40eecec0c152b17f93c7e7aab6b475187

Contents?: true

Size: 719 Bytes

Versions: 5

Compression:

Stored size: 719 Bytes

Contents

# Taken, and then modified, from the _wrong_ gem:
# https://github.com/sconover/wrong/blob/30475fc5ac9d0f73135d229b1b44c045156a7e7a/lib/wrong/irb.rb
# Thanks for showing the way

if defined? IRB
  module IRB
    class Context

      def all_lines
        @all_lines.join
      end

      original_evaluate = instance_method(:evaluate)

      # Save every line that is evaluated.  This gives cute_print a
      # way to get the source when it is run in irb.
      define_method :evaluate do |line, line_no|
        @all_lines ||= []
        @all_lines += ["\n"] * (line_no - @all_lines.size - 1)
        @all_lines[line_no - 1] = line
        original_evaluate.bind(self).call line, line_no
      end

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
cute_print-1.1.0 lib/cute_print/core_ext/irb.rb
cute_print-1.0.1 lib/cute_print/core_ext/irb.rb
cute_print-1.0.0 lib/cute_print/core_ext/irb.rb
cute_print-0.4.0 lib/cute_print/core_ext/irb.rb
cute_print-0.3.0 lib/cute_print/core_ext/irb.rb