Skip to content

Instantly share code, notes, and snippets.

@zzak
Forked from nusco/blank_slate.rb
Created September 13, 2010 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zzak/577618 to your computer and use it in GitHub Desktop.
Save zzak/577618 to your computer and use it in GitHub Desktop.
# ===================
# Spell: Blank Slate
# ===================
# Remove methods from an object to turn them into Ghost Methods (http://gist.github.com/534776).
class C
def method_missing(name, *args)
"a Ghost Method"
end
end
obj = C.new obj.to_s # => "#<C:0x357258>"
class C
instance_methods.each do |m|
undef_method m unless m.to_s =~ /method_missing|respond_to?|^__/
end
end
obj.to_s # => "a Ghost Method" For more information, see page 84.
# For more information: http://www.pragprog.com/titles/ppmetr/metaprogramming-ruby
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment