Monthly Archives: December 2010

Getting to Know the Ruby Standard Library – Timeout

I asked for suggestions about what to cover next, and postmodern suggested the Timeout library among others. Timeout lets you run a block of code, and ensure it takes no longer than a specified amount of time. The most common … Continue reading

4 Comments

Filed under ruby, stdlib

Qwandry 0.1.0 – Now Supporting More Languages

I just finished updating Qwandry so that it can support any number of other languages or packaging systems. Want to use perl, python, or node with Qwandry? No problem: qw -r python numpy # opens python’s numpy library qw -r … Continue reading

2 Comments

Filed under development, ruby

Getting to Know the Ruby Standard Library – Pathname

Pathname is useful library that demonstrates a good refactoring: “Replace Data Value With Object”. In this case the data value is a String representing a path. Pathname wraps that String and provides a wide variety of methods for manipulating paths … Continue reading

5 Comments

Filed under ruby, stdlib

Getting to Know the Ruby Standard Library – Abbrev

We’re going to take a look at another little piece of ruby’s standard library, this time it is Abbrev, a tiny library that generates abbreviations for a set of words. We will expand ever so slightly on the one-liner from … Continue reading

5 Comments

Filed under ruby, stdlib

Finding Binaries with Ruby

Here’s a quick one liner in ruby that finds all of the binaries on your PATH: Dir[*ENV['PATH'].split(‘:’).map{|p| p+”/*”}].select{|f| File.executable? f}.map{|f| File.basename f}.uniq How does it work? Working in the order of execution, we get the PATH from your environment variables. … Continue reading

1 Comment

Filed under ruby

Hash Tricks

Ruby’s Hash can accept a block when you initialize it. The block is called any time you attempt to access a key that is not present. Hash’s initialization block expects the following format: Hash.new{|hash, key| … } The hash references … Continue reading

14 Comments

Filed under ruby

Getting to Know the Ruby Standard Library – TSort

TSort is an interesting part of the ruby standard library that performs topological sorting. Topological sorting is used in package management, analyzing source code, and evaluating prerequisites. RubyGems uses TSort to determine what order to install gems in when there … Continue reading

7 Comments

Filed under ruby, stdlib

Getting to Know the Ruby Standard Library – MiniTest::Mock

Recently we looked at MiniTest, this time around we’re going to dive into MiniTest::Mock, a tiny library that will let you test systems that would otherwise be very difficult to test. We will take a look at what MiniTest::Mock provides, … Continue reading

4 Comments

Filed under ruby, stdlib, testing

Getting Help Inside IRB

Here’s a quick tip, ruby’s ri utility will look up documentation about a method. For instance you can type ri String#split to see the documentation for String’s instance method split. If you have an irb session open you can tell … Continue reading

Leave a Comment

Filed under Uncategorized

Getting to Know the Ruby Standard Library – Shellwords

Previously we answered a few questions about Minitest, and learned a little about exit hooks and introspection in ruby. Now lets look at an often overlooked library, Shellwords. Shellwords lets you break up a string the same way the Bourne … Continue reading

5 Comments

Filed under ruby, stdlib