Imports

It’s sometimes easy to think everything is just an import or require away.

I have two examples where it’s actually not beneficial to import a library and use the API.

launchy Link to heading

Launchy launches a webpage into your browser. It works hard to detect what operative system you are on; what browser is the default; what browsers are available; whats in your ENV..

But you have no plans on distributing your code all over the place and have it be running on different OS:s, using Safari or NetscapeNavigator 4.

All you need is: system %(firefox --new-tab URL)

user argument parsing Link to heading

Why not just check ARGV? Instead of importing a library with bells and whistles you don’t need..

ARGV.empty? ?
  abort('Supply a filename') :
  File.file?(ARGV[0]) ?
    (p 'got a file!') :
    abort('File Error')

# or short:
File.file?(ARGV[0] || '') ? do_stuff : abort(:error)