I was reading Eloquent Ruby yesterday morning (buy a copy if you haven’t already), and it got me thinking about one of my “favorite” Ruby gotchas: defining #method_missing without a corresponding #respond_to?. E.g.:
"Oops, I lied"
l = Liar.new
l.respond_to?(:foo) # => false
l.foo # => "Oops, I lied"
The resulting code violates the Principle of Least Surprise, and often interacts in unexpected ways with other libraries. I started wondering […]