Correct BlankSlate in Ruby
class BlankSlate
class <<self; alias __undef_method undef_method; end
alias __instance_eval instance_eval
ancestors.inject([]){|m,a| m + a.methods }.uniq.
each { |m| (__undef_method(m) rescue nil) unless m =~ /^__/ }
end
class MyProxy < BlankSlate; end
Note 1: ancestors.inject{…} ensures that all Kernel methods like :p are properly removed.
Note 2: alias __instance_eval could be safely removed if you don’t need this method.
