Created
November 13, 2010 11:46
-
-
Save ConradIrwin/675266 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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