kachick / irb-power_assert

power_assert in irb

Home Page:https://kachick.github.io/irb-power_assert/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

irb-power_assert

Build Status Gem Version

Overview

screenshot - expression

ruby/power_assert is a recent my favorites.
(the author is @k-tsj, thank you!)

It is super helpful in complex testing.

Don't say ruby/irb is old-fashioned.

I just would get irb version of yui-knk/pry-power_assert

Honor should be bestowed upon them.

Usage

Require Ruby 3.2 or higher # Tested only in ruby-head and the last 2 stable versions

$ gem install irb-power_assert
Should be installed!
$ irb -r irb-power_assert
# Then enabled this gem!

Or specify in your ~/.irbrc as below

require 'irb/power_assert'
$ irb
# Then enabled this gem!

Then you can use pa as an IRB command.

irb(main):001:0> pa %q{ "0".class == "3".to_i.times.map {|i| i + 1 }.class }
result: false

 "0".class == "3".to_i.times.map {|i| i + 1 }.class
     |     |      |    |     |                |
     |     |      |    |     |                Array
     |     |      |    |     [1, 2, 3]
     |     |      |    #<Enumerator: ...>
     |     |      3
     |     false
     String
=> nil

The pa just takes strings of the code.

If you want to directly pass expression, .irbrc is the hack for single line code.
if you don't have the file yet, putting the file as one of your $IRBRC, $XDG_CONFIG_HOME/irb/irbrc or $HOME/.irbrc

Then you can use the pa as below...

irb(main):001:0> pa "0".class == "3".to_i.times.map {|i| i + 1 }.class
result: false

"0".class == "3".to_i.times.map {|i| i + 1 }.class
    |     |      |    |     |                |
    |     |      |    |     |                Array
    |     |      |    |     [1, 2, 3]
    |     |      |    #<Enumerator: ...>
    |     |      3
    |     false
    String
=> nil

References

About

power_assert in irb

https://kachick.github.io/irb-power_assert/

License:MIT License


Languages

Language:Ruby 87.8%Language:Nix 12.2%