Hidden Gems of Ruby 1.9
At GoGaRuco (Golden Gate RubyConf) in San Francisco, CA today…
Talk by Aaron Patterson
minitest
require ‘minitest/autorun’
refute_equal (same as assert_not in TestUnit)
inherit from MiniTest::Unit::TestCase
Test Performance
Run test with -verbose, you can see how long each test takes.
minitest/spec (similar to rspec)
———
ObjectSpace
ObjectSpace.each_object do |obj|
p obj
end
count_object_size (to see how much memory a particular object is taking in total
memsize_of (returns size in bytes)
count_nodes
count_tdata_objects (counts native objects)
——
Fiddle
A libffi wrapper that’s in Ruby 1.9
Fiddle allows your Ruby code to call native functions (Dynamic Libraries) and allocate closures.
ruby-ffi
——
Psych (YAML Parser)
JSON is a subset of YAML. So Psych will load JSON.
Psych supports Evented Parsing (similar to SAX XML Parsers which call events when certain xml elements are seen)
Event Emitting (emit YAML)
Streamed Emitting (an easy way for Evented Emitting. It emits immediately. There’s no buffering)
Each calls to push method emits multiple documents.
Streaming JSON Emitter (Psych::JSON::Stream)
—-
How to Figure Out Code Coverage in Ruby 1.9
Writing a Code Coverage Tool with Ruby 1.9