[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

IRB output format in YAML

Martin Martinos

5/26/2008 2:07:00 PM

I there a way to configure IRB so that it always display the result of a
IRB command in YAML or PP format.

Example:

In YAML:

irb(main):011:0> ENV.keys
---
- ALLUSERSPROFILE
- APPDATA
- APR_ICONV_PATH
- ATI_PATH
- BERK_PATH
- CLASSPATH
- CLIENTNAME

Pretty print:

irb(main):015:0> ENV.key
["ALLUSERSPROFILE",
"APPDATA",
"APR_ICONV_PATH",
"THG_ICON_PATH",
"WINDOWS_PATH"]
--
Posted via http://www.ruby-....

3 Answers

Phlip

5/26/2008 2:24:00 PM

0

> I there a way to configure IRB so that it always display the result of a
> IRB command in YAML or PP format.

This might work:

Write a .rb file that overrides Object.inspect(). Put to_yaml inside it.

Test it to make sure you don't infinitely recurse, when to_yaml calls
inspect!

Configure IRB via ~/.irbrc to always require in this .rb file.


Joel VanderWerf

5/26/2008 7:40:00 PM

0

Martin Martinos wrote:
> I there a way to configure IRB so that it always display the result of a
> IRB command in YAML or PP format.

Put this in your .irbrc and play around a little:

require 'yaml'

class IRB::Irb
def output_value
if @context.inspect?
printf @context.return_format, @context.last_value.to_yaml
else
printf @context.return_format, @context.last_value
end
end
end


--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

Martin Martinos

5/26/2008 9:19:00 PM

0

Thanks Joel, it works perfectly.

Martinos
--
Posted via http://www.ruby-....