Create a gist now

Instantly share code, notes, and snippets.

find and copy the latest version of a gem
$ latest haml
request: http://rubygems.org/api/v1/gems/haml.json
version: 3.0.25
# cmd+v
$ 3.0.25
#!/usr/bin/env ruby
require "net/http"
require "uri"
require "json"
if gem = ARGV.first
uri = URI.parse("http://rubygems.org/api/v1/gems/#{gem}.json")
puts "request: #{uri}"
begin
response = Net::HTTP.get_response(uri)
version = JSON.parse(response.body)["version"]
puts "version: #{version}"
`echo "#{version}" | pbcopy`
rescue => e
puts "oops ..."
puts e
end
else
puts "what?"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment