Reputation: 5728
How can I design a module which will behave similar to URI module? I mean something like this:
1.9.3-p125 :001 > require 'uri'
=> true
1.9.3-p125 :002 > URI.class
=> Module
1.9.3-p125 :003 > URI("http://google.com")
=> #<URI::HTTP:0x0000010d8f6bd8 URL:http://google.com>
Upvotes: 1
Views: 110
Reputation: 138032
It's possible to have a method and a class/module with the same name:
1.8.7 > class Foo; end
=> nil
1.8.7 > def Foo; 42; end
=> nil
1.8.7 > Foo
=> Foo
1.8.7 > Foo()
=> 42
Upvotes: 1