Skip to content

Instantly share code, notes, and snippets.

@allolex
Created September 30, 2015 18:02
Show Gist options
  • Select an option

  • Save allolex/8b813111daa99d0cce2d to your computer and use it in GitHub Desktop.

Select an option

Save allolex/8b813111daa99d0cce2d to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
#
# Checks to see if the wirble gem is installed and
# installs it for you if it is not already installed.
def gem_list
@gem_list ||= `gem list`
end
def gem_name_re
/\A[^\w_-]+\z/
end
def validate(name)
if gem_name_re === name
raise "Did you use the correct gem name?"
end
end
def check_install(gem_name)
validate(gem_name)
unless /#{gem_name}/ === gem_list
if exec "gem install #{gem_name}"
@gem_list << gem_name
end
end
end
check_install("wirble")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment