Wednesday, September 3, 2008

Singleton class magic without using singleton classes

Excellent posts here and here by Jay Fields where he gives an alternative to use singleton classes.

Instead of doing this:

class << self
def hi
puts 'Hi'
end
end
You do this:

mod = Module.new do
def hi
puts 'Hi'
end
end
extend mod

0 comments: