Skip to content

Instantly share code, notes, and snippets.

@hovsater
Last active December 13, 2015 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hovsater/4984060 to your computer and use it in GitHub Desktop.
Save hovsater/4984060 to your computer and use it in GitHub Desktop.
Regular expressions with RubyGems

Very often, I want to check the latest version of a particular gem on RubyGems.org.

This can be accomplished by doing gem list -r GEM_NAME.

Unfortunatley, this doesn't always work out well. If I would run gem list -r capistrano to get the latest version of Capistrano, the list of matches would be quite large.

....
capistrano-zen (0.0.2)
capistrano_auto_multi_install (1.0.6)
capistrano_banner (0.0.4)
capistrano_chef_solo (0.1.0)
capistrano_colors (0.5.5)
capistrano_confirm_branch (0.0.2)
capistrano_copy_with_remote_cache_strategy (0.1)
capistrano_database_yml (1.1.3)
capistrano_deploy_lock (1.1.0)
capistrano_evrone_recipes (0.1.10)
capistrano_kvm_git (1.0.0)
capistrano_mailer (4.0.2)
capistrano_mailer_railsless (3.2.11)
capistrano_mongo (0.1.0)
capistrano_rails_console (0.5.3)
capistrano_recia (0.0.2)
capistrano_rsync_with_remote_cache (2.4.0)
capistrano_s3 (0.2.1)
capistrano_ssh (0.3.0)
capistrano_transmit (1.0.0)
capistrano_winrm (1.0.0)
CapistranoTrac (0.5.0)

As you can see, the Capistrano gem isn't even listed because it's in the beginning of the list.

We can prevent this by typing gem list -r capistrano$ instead. This is possible due to GEM_NAME being evaluated as a regular expression.

The list of matches is now reduced to the gem we were asking for.

capistrano (2.14.2)

Happy hacking!

GitHub: KevinSjoberg | Twitter: KevinSjoberg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment