Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
title: More Inspections | ||
date: 2015-05-12 | ||
tags: core, irb, cli-options | ||
--- | ||
|
||
Some of IRB's command-line options can be called idiosyncratic as well. Take *math mode* as an example: It will require the infamous [mathn](https://github.com/ruby/ruby/blob/trunk/lib/mathn.rb) library on start up: | ||
|
||
$ irb -m | ||
>> Math #=> CMath | ||
>> 3/2 #=> (3/2) | ||
>> !!defined?(Vector) #=> true | ||
|
||
And another one surprised me: You can pass custom [inspectors](https://github.com/ruby/ruby/blob/trunk/lib/irb/inspector.rb) to IRB, for example, *yaml*: | ||
|
||
$ irb -f --inspect yaml | ||
>> [1,2,3] | ||
=> --- | ||
- 1 | ||
- 2 | ||
- 3 | ||
|
||
Or *marshal*: | ||
|
||
$ irb -f --inspect marshal | ||
>> 42 | ||
=> i/ | ||
|
||
But you can also define *your own inspectors on the fly*: | ||
|
||
$ irb -f --inspect "{ |r| r.to_s.reverse }" | ||
>> [1,2,3] | ||
=> ]3 ,2 ,1[ | ||
|
||
It will be eval'd (!) as the block part of a new `proc`. | ||
|
||
|
||
## Resources | ||
|
||
- `man irb` | ||
- [Source: irb/context](https://github.com/ruby/ruby/blame/trunk/lib/irb/context.rb) | ||
- [Source: irb/inspectors](https://github.com/ruby/ruby/blob/trunk/lib/irb/inspector.rb) |