Eigen-Caltrops
Ruby has a nice feature where you can override methods on a per-object basis (singleton methods). For example:
foo = "spleen"
p foo.upcase #=> "SPLEEN"
def foo.upcase
"BREAD"
end
p foo.upcase #=> "BREAD"
# other objects not affected
p foo.dup.upcase #=> "SPLEEN"
p "bump".upcase #=> "BUMP"
# but cloned objects also get the override
p foo.clone.upcase #=> "BREAD"
Maybe, though, sometimes you don’t want an object’s methods to be overridable in this way. Maybe you want the class and only the class to decide. I don’t know why, but let’s say you do.
It’s possible to disable this feature on a per-object basis.
foo = "lung"
class << foo ; freeze ; end
# DEATH!
def foo.upcase
"CHEESE"
end
Attempting to override a method on foo will now throw an exception. Its singleton class is untouchable. It is un-meta-able. Eigen-caltrops, is what this is.