Hi. I am travis and I work in a place long ago abandoned by the gods: New York City. By day, I am a Software Engineer at Blue Apron. By night, i am a normal person.

If it Barks Like a Dog

How many stupid, pointless ways can you do the same thing? Many!

In Ruby, trying to compare something to nil throws an exception. If you forget this, you're gonna have a bad time. The first instinct of most developers is to check if a value is present, i.e.

if dignity.present? && dignity > 0

This approach is natural, straightforward, and easy to read, but it's boring. There are plenty of fun and interesting ways to accomplish this that have absolutely no point to them! Let's examine a few.

# Using a hash
if { motivation: motivation }.fetch(:motivation, 0) > 0

# Using an array
if [remote_chance_of_success, 0].compact.first > 0

We can even monkey-patch NilClass to provide this functionality. This has the added benefit of obfuscating your code and endangering the stability of your application in the case of adding dependencies or upgrading. Oh boy!

NilClass.class_eval do
  def >(arg)

irb(main):001:0> nil.class
=> NilClass
irb(main):008:0> nil > 0
=> false

What's the point, you ask? You're missing the point. There is no point. Go home and write some dank code.

Counting is Hard

Scraping Websites: An Exercise in Futility