Return to Snippet

Revision: 12624
at March 21, 2009 19:27 by narkisr


Initial Code
lass BlankSlate
    instance_methods.each { |m| undef_method m unless m =~ /^__/ }
end

# All methods will be passed to method_missing
class Proxy < BlankSlate
  def initialize(obj)
    @obj = obj
  end

  def method_missing(sym, *args, &block)
      puts "Sending #{sym}(#{args.join(',')}) to obj"
      @obj.__send__(sym, *args, &block)
    end
end

Initial URL


Initial Description
Creating a object that doesn't have any methods in Ruby (regular objects inherit methods from Object class), useful for Proxies that use method missing (http://onestepback.org/index.cgi/Tech/Ruby/BlankSlate.rdoc).

Initial Title
Blank slate objects in Ruby

Initial Tags
ruby

Initial Language
Ruby