Git Product home page Git Product logo

cute_print's Issues

Source introspection does not work in irb

wayne@treebeard:~$ irb
2.1.2 :001 > require 'cute_print'
 => true 
2.1.2 :002 > q {1 + 2}
Errno::ENOENT: No such file or directory @ rb_sysopen - (irb)

The gem currently reads the source from a file. With irb, there is no file.

The wrong gem's #d method has special code to make it work with irb. We should probably do what it does.

Stack trace when source is modified

If source code is modified while it is running, cute_print causes a "Method call not found (RuntimeError)" stack trace.

To reproduce

Run this program

require "cute_print"
loop do
  ql {1 + 2}
  sleep 1
end

While the program is running, edit it. Comment out the "ql" line and save your edits.

This stack trace results:

...
foo.rb:6: (1 + 2) is 3
foo.rb:6: (1 + 2) is 3
/home/wayne/.rvm/gems/ruby-2.2.0/gems/cute_print-1.0.1/lib/cute_print/ruby_parser/method_call.rb:17:in `call?': undefined method `[]' for nil:NilClass (NoMethodError)
        from /home/wayne/.rvm/gems/ruby-2.2.0/gems/cute_print-1.0.1/lib/cute_print/ruby_parser/method_call.rb:13:in `call_to_method?'
        from /home/wayne/.rvm/gems/ruby-2.2.0/gems/cute_print-1.0.1/lib/cute_print/ruby_parser/parsed_code.rb:24:in `method_call_node'
        from /home/wayne/.rvm/gems/ruby-2.2.0/gems/cute_print-1.0.1/lib/cute_print/ruby_parser/parsed_code.rb:18:in `first_call_to_method'
        from /home/wayne/.rvm/gems/ruby-2.2.0/gems/cute_print-1.0.1/lib/cute_print/source_label.rb:21:in `block_code'
        from /home/wayne/.rvm/gems/ruby-2.2.0/gems/cute_print-1.0.1/lib/cute_print/source_label.rb:13:in `to_s'
        from /home/wayne/.rvm/gems/ruby-2.2.0/gems/cute_print-1.0.1/lib/cute_print/formatter.rb:72:in `join'
        from /home/wayne/.rvm/gems/ruby-2.2.0/gems/cute_print-1.0.1/lib/cute_print/formatter.rb:72:in `make_label'
        from /home/wayne/.rvm/gems/ruby-2.2.0/gems/cute_print-1.0.1/lib/cute_print/formatter.rb:65:in `label'
        from /home/wayne/.rvm/gems/ruby-2.2.0/gems/cute_print-1.0.1/lib/cute_print/formatter.rb:32:in `block in write'
        from /home/wayne/.rvm/gems/ruby-2.2.0/gems/cute_print-1.0.1/lib/cute_print/formatter.rb:31:in `write'
        from /home/wayne/.rvm/gems/ruby-2.2.0/gems/cute_print-1.0.1/lib/cute_print/printer.rb:61:in `ql'
        from /home/wayne/.rvm/gems/ruby-2.2.0/gems/cute_print-1.0.1/lib/cute_print/cute_print.rb:54:in `ql'
        from /home/wayne/.rvm/gems/ruby-2.2.0/gems/cute_print-1.0.1/lib/cute_print/mixin.rb:18:in `ql'
        from /tmp/foo.rb:6:in `block in <main>'
        from /tmp/foo.rb:5:in `loop'
        from /tmp/foo.rb:5:in `<main>'

Possible fixes

  • It seems that the parsed source should be cached and so not parsed from source every time. This would cause cute_print to print the right thing even after the source changed, and would generally help performance.
  • Even with cached source, there is a race condition. In the time between when the program starts running and when it first parses the source, the source could have been changed, moved, etc. cute_print should behave gracefully when it can't parse the source.

Shorten names for tapq / tapql

Since q and qq already look like dyslexic version of p and pp you could also have:

object.taq # "tack"
object.taql # "tackle"

pretty-print

Add Kernel#qq. It should work like Kernel#q, but should format the inspected objects like Kernel#pp from the pp (pretty-print) library.

Warning with ruby-2.4.3 or ruby-2.5.0

When tests are run with ruby-2.4.3 or ruby-2.5.0:

/home/wayne/.rvm/gems/ruby-2.5.0/gems/hirb-0.7.3/lib/hirb/helpers/table.rb:254: warning: `+' after local variable or literal is interpreted as binary operator
/home/wayne/.rvm/gems/ruby-2.5.0/gems/hirb-0.7.3/lib/hirb/helpers/table.rb:254: warning: even though it seems like unary operator

These are caused by this expression in ~/.rvm/gems/ruby-2.5.0/gems/hirb-0.7.3/lib/hirb/helpers/:

     format_values(@headers).join(' ' + chars[:top][:vertical][:inside] +' ') +                                                       |    pry-byebug (3.6.0)
      ' ' + chars[:top][:vertical][:outside]                                                                                           |      byebug (~> 10.0)

hirb is no longer maintained. cute_print is using the latest version of hirb, which was released on Jan. 23rd, 2015. cute_print should probably be modified to no longer use hirb. If we need a quick fix, we can monkey-patch hirb.

Evaluates argument twice

cute_print evaluates its argument twice. This script:

require "cute_print"

class Foo
  include Enumerable
  def each  
    p "each"
  end
end

foo = Foo.new
ql {foo.count}

outputs:

"each"
"each"
foo.rb:11: foo.count is 0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.