Scrayz

Work has finally slowed down enough that I have inched my Scala based ray tracer along, just a tiny bit. I'm keeping the code on gitla...

January 16, 2014

Ruby's Data::Dumper

I was poking around a bit trying to find the Ruby equivalent of Perls Data::Dumper or Data::Printer.  At first, I didn't think anything like those existed.

Upon further research, it seems that the "normal" way of doing this is to use Marshal or YAML.

These are ok, and I'll probably play with them, but I got more excited when I subsequently discovered Awesome Print.

After installing...

gem install awesome_print

First run:

ctreptow@vm-0:~$ cat 1.rb                                                                                                                                                 
#!/usr/bin/env ruby
require "awesome_print"
data = [ false, 42, %w(forty two), { :now => Time.now,
 :class => Time.now.class, :distance => 42e42 } ]
ap data


ctreptow@vm-0:~$ ./1.rb                                                                                                                                                   
[
    [0] false,
    [1] 42,
    [2] [
        [0] "forty",
        [1] "two"
    ],
    [3] {
             :now => 2014-01-15 22:49:02 +0000,
           :class => Time < Object,
        :distance => 4.2e+43
    }
]
ctreptow@vm-0:~$  

I like that.  I think it will come in handy when I get around to actually making something.


No comments:

Post a Comment