Skid Keywords

Ruby has a few interesting old keywords that use the underscore, or ‘skid’, to convey meta information about the file. Here they are in action: # test.rb puts __ENCODING__ puts __FILE__ puts __LINE__ __END__ Because this is after 'end', it should not be executed Running this file produces: $ ruby test.rb UTF-8 test.rb 3 Pretty cool!

July 2, 2015

Puts Multiple Lines

Ruby’s puts can take multiple arguments! 2.2.0 :002 > puts 'so', 'many', 'statements', 'to', 'puts' so many statements to puts => nil

May 26, 2015

Truthy Strings

Ruby strings are truthy, and they evaluate to zero, unless they start with a number. > 'nine to five'.to_i => 0 > '9 to 5'.to_i => 9

May 26, 2015

Minmax

Ruby’s Enumerable class includes minmax, which returns a two element array with the minimum and maximum values of an enumerable. > [1, 5, 10].minmax => [1, 10] > ['alpha', 'bravo', 'zulu'].minmax => ["alpha", "zulu"]

May 18, 2015

Case Insensitive Matchers

You can make Ruby regex matchers case insensitive with an i. 2.1.0 :001 > 'Expected output' =~ /expected/ => nil 2.1.0 :002 > 'Expected output' =~ /expected/i => 0 This is useful when writing tests, when you care about a message, but are not interested in its exact format.

May 15, 2015

Ruby Symbol#to_proc

What does &: mean in Ruby? In this post, I’ll explain. ...

October 31, 2014

Code Club: Rack and Rails Server

This week in Code Club we explored Rack, the middleware of the Rails stack. Rack is newsworthy of late due to a change in ownership, prompting inevitable questions about the future. As Rails developers, we wanted to know what Rack really does. ...

August 27, 2014

Don’t miss my next essay

Hear from me immediately when I post: no ads, unsubscribe anytime.