Skip to content

Instantly share code, notes, and snippets.

@ELLIOTTCABLE
Created August 15, 2008 23:06
Show Gist options
  • Save ELLIOTTCABLE/5673 to your computer and use it in GitHub Desktop.
Save ELLIOTTCABLE/5673 to your computer and use it in GitHub Desktop.
# Objects of this class are *almost* a URI!
class AlmostURI < String; end
[AlmostURI, String, Symbol].each do |klass|
klass.class_eval do
def / urlpart
AlmostURI.new [self, urlpart].join('/')
end
def method_missing meth, *args
AlmostURI.new [self, urlpart].join('.')
end
end
end
def method_missing meth, *args
if args.size == 1 and args.first == :/
return AlmostURI.new [self, ':/'].join('.')
else
super
end
end
p((http://:google.com/:test.rb).to_s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment