20 karma · joined Jul 17, 2011 (15y ago) · 11 submissions
comment 13y ago · link · parent
For example, say I have a class that can process stuff, and a mixin that attempts to log calls to the #process method:
class Processor
def process
puts "Very important stuff here"
end
end
module Logger
def process
puts "Entering process."
super
puts "Leaving process."
end
end
If you just ``include Logger`` in Processor it won't work: Processor#process is looked up before Logger#process. However, if you use Module#prepend, the ancestry chain will change and calls to Process#process will be decorated as expected.comment 13y ago · link · parent
[1, 2, 3].inject(:+)
[1, 2, 3].inject(0, :+)
[1, 2, 3].inject(nil, :+) # doesn't work
Rubinius uses a magic ``undefined`` value for this: def inject(initial=undefined, sym=undefined, &block)comment 14y ago · link · parent
comment 14y ago · link · parent
He would rarely come up with some theorem, ask us to solve a few exercises, and go on to the next chapter. When he wanted to introduce a new concept, he'd usually ask us to solve an equation or a more concrete probleme (I can remember something like the fence problem mentioned in the article, which was used to introduce us to finding the maximal output of a 2nd degree expression). After that, we would either find a solution through some struggle — and then try to figure out a more efficient approach — or we'd stumble on a problem by trying to use approaches we'd been taught before — and therefore try to find a better way to represent the problem.
On an amusing sidenote, while we were each working individually, he'd walk around in the class, looking at what we were doing, and crossing out with a red marker pen mistakes we'd made.
comment 15y ago · link · parent
[1] Codify: http://itunes.apple.com/us/app/codify/id439571171?mt=8