Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
cute_print writes debug output to stderr. Optionally prints the source filename and line number, or the source of the debug statement. Easily inspect the middle of a call chain.
Add this line to your application's Gemfile:
gem "cute_print"
And then execute:
$ bundle
Or install it yourself:
$ gem install cute_print
Start with:
require "cute_print"
q work like Kernel#p, except that it prints to $stderr instead of $stdout.
q "abc" # "abc"
q [1, 2, 3 + 4] # [1, 2, 7]
By passing a block, you can have the debug source printed along with the value:
i = 1
q {i + 2} # i + 2 is 3
ql will also print the source location:
ql "abc" # foo.rb:12: "abc"
ql {1 + 2} # foo.rb:13: 1 + 2 is 3
When called with no arguments, ql just prints the source location:
ql # foo.rb:14
This is very handy for answering "which branch did it take?," or "did it even get to that method?"
qq pretty-prints its arguments to $stderr:
a = (1..30).to_a
qq a # [1,
# 2,
# ...
# 20,
# 30]
When called with a bock, qq prints the debug source as well:
a = (1..30).to_a
qq {a} # a is [1,
# 2,
# ...
# 20,
# 30]
qql also prints the source location:
a = (1..30).to_a
qq a # foo.rb:12: [1,
# 2,
# ...
# 20,
# 30]
When called with a block, qql prints the debug source as well:
a = (1..30).to_a
qq {a} # foo.rb:12: a is [1,
# 2,
# ...
# 20,
# 30]
tapq inspects the middle of a call chain:
["1", "2"].map(&:to_i).tapq.inject(&:+)
# [1, 2]
tapql also prints the source location:
["1", "2"].map(&:to_i).tapql.inject(&:+)
# bar.rb:12: [1, 2]
tapqq pretty-prints the middle of a call chain:
a = (1..30).to_a
sum = a.tapqq.inject(:+) # [1,
# 2,
# ...
# 20,
# 30]
tapqql also prints the source location:
a = (1..30).to_a
sum = a.tapqq.inject(:+) # foo.rb:12: [1,
# 2,
# ...
# 20,
# 30]
To change the output device:
CutePrint.configure do |c|
c.out = File.open('/tmp/debug')
end
Any object that responds to #print will do.
To cause #ql, #qql and #tapql to print the full path rather than just the filename:
CutePrint.configure do |c|
c.location_format = :path
end
The terminal width is detected, if possible, but you can override it:
CutePrint.configure do |c|
c.term_width = 132
end
To set the terminal width back to being detected:
CutePrint.configure do |c|
c.term_width = :detect
end
To reset the configuration to its defaults:
CutePrint.configure do |c|
c.reset
end
By default, this gem defines many methods on Object, making them globally available. To use this gem without any global methods, require "cute_print/core" and then call one of the CutePrint class methods:
require "cute_print/core"
CutePrint.q {1 + 2} # 1 + 2 is 3
The "tap" methods are not available when using CutePrint this way.
As of version 1.4.0, cute_print is known to work with these versions of Ruby:
As of version 1.3.0, cute_print is known to work with these versions of Ruby:
As of version 1.1.6, cute_print is known to work with these versions of Ruby:
As of version 1.1.5, cute_print is known to work with these versin of Ruby:
This gem is developed and tested with Linux. It should work on Windows and OSX as well. If it does not work for you, please file an issue on github.
The wrong gem includes the excellent #d method, which is very much like this gem's #q method. This gem's ability to read the debug statement's source is derived from the wrong gem.
This gem uses semantic versioning 2.0.
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that cute_print demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.