Cute method_missing hack
March 6th, 2008
I love abusing method_missing in Ruby, it is great fun. module IsDoesIsntDoesnt def method_missing(method, *args) m = method.to_s if (m =~ /^is_(\w*?\?)$/) || (m =~ /^does_(\w*?\?)$/) real_method = $1.to_sym return send(real_method, *args) if respond_to?(real_method) elsif (m =~ /^isnt_(\w*?\?)$/) || (m =~ /^doesnt_(\w*?\?)$/) real_method = $1.to_sym return !send(real_method, *args) if respond_to?(real_method) elsif (m =~ /^(\w*?)s\?$/) real_method [...]
[ Back to top ]







