Skip to content

Instantly share code, notes, and snippets.

@ConradIrwin
Created November 13, 2010 11:46
Show Gist options
  • Save ConradIrwin/675266 to your computer and use it in GitHub Desktop.
Save ConradIrwin/675266 to your computer and use it in GitHub Desktop.
module URI
# When given a string, returns true if the string represents an http or https URL
# When given no arguments, returns a lambda with the same properties.
#
# URI.valid_link?("http://rapportive.com")
# # => true
# ["httq://rapportive.com", "http://rapportive.com"].select(&URI.valid_link?)
# # => ["http://rapportive.com"]
def self.valid_link?(*args)
if args.present?
!!(URI.parse(*args).is_a?(URI::HTTP) rescue nil)
else
URI.method(:valid_link?)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment