Just do a gem install xkcd
And then :
require 'xkcd'
p XKCD.img # To get random comic image URL and title
p XKCD.comic # Get the random comic URL
p XKCD.search "classhole" #Does a Google search for comic containing the search phrase and returns first comic result