Guest User

Untitled

a guest
Jul 20th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. # demonstrate how to remove functionality
  2. String.class_eval do
  3. undef_method :length
  4. end
  5. "test".length # => NoMethodError: undefined method `length' for "test":String
  6.  
  7. # create a blank slate class
  8. class BlankSlate
  9. public_instance_methods.each do |method_name|
  10. undef_method(method_name) unless method_name =~ /^__|^(public_methods|method_missing|respond_to\?)$/
  11. end
  12. end
  13.  
  14. # see what methods are now available
  15. BlankSlate.new.public_methods # => ["public_methods", "__send__", "respond_to?", "__id__"]
Add Comment
Please, Sign In to add comment