Skip to content

Instantly share code, notes, and snippets.

@cktricky
Last active December 13, 2015 20:08
Show Gist options
  • Save cktricky/4967248 to your computer and use it in GitHub Desktop.
Save cktricky/4967248 to your computer and use it in GitHub Desktop.
crappy solution for parsing sources from a string
require 'uri'
a = %{rubygems repository http://blahblah.net/, https://rubygems.org/}
b = a.split().inject([]) {|array, string|
begin
x = URI.parse(string).absolute?
array << string if x
rescue
end
array
}
puts b
# ALTERNATIVELY, just use this line
b = a.split().select {|x| x if URI.parse(x).absolute?}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment