Thursday 27 March 2008, 23:04
ruby: url_to_constant
By Geoffrey - Coding - Permalink
A small bit of ruby to get a constant from an URL:
require 'uri'
def url_to_constant(url)
return URI.parse(url).host.gsub(/^www\./, '').capitalize.gsub(/[^a-z][a-z]/i) { |m| m.gsub(/[^a-z]/, '').upcase }.constantize
end
Nothing exceptionnal here, just a pretext to post something.
one comment
Blog early, blog often :-P
This post's comments feed