How does ruby allow a method and a Class with the same name?
- by Daniel Beardsley
I happened to be working on a Singleton class in ruby and just remembered the way it works in factory_girl. They worked it out so you can use both the long way Factory.create(...) and the short way Factory(...) I thought about it and was curious to see how they made the class Factory also behave like a method.
They simply used Factory twice like so:
def Factory (args)
...
end
class Factory
...
end
My Question is: How does ruby accomplish this? and Is there danger in using this seemingly quirky pattern?