How does this ruby error handling module code work
- by Michael Durrant
Trying to get a better handle on ruby exception handling.
I have this code (from a book):
def err_with_msg(pattern)
m = Module.new
(class << m; self; end).instance_eval do
define_method(:===) do |e|
pattern === e.msg
end
end
m
end
So ok this is a method.
We're creating a new Module. I think of module as mix-ins. Not sure what it's doing here.
Not we add the module to the class. Fair enough.
Then we have self on its own. What that for? I guess we have a little anonymouse method this is just about self. hmmm
ok, now for each of the above, check the pattern match. but for each, I thought the above for for a new Module, did the module get to use instance's by being included?
A better explanation of what's going on here would be most helpful.