Sha256: 73218c27f55c5214ade95c8f8173cfb91eb2ecef1e1abb27927b3e62c311fad8

Contents?: true

Size: 1.83 KB

Versions: 21

Compression:

Stored size: 1.83 KB

Contents

#!/usr/bin/env ruby
#--
# Copyright 2004 by Jim Weirich (jim@weirichhouse.org).
# All rights reserved.

# Permission is granted for use, copying, modification, distribution,
# and distribution of modified versions of this work as long as the
# above copyright notice is included.
#++

module Builder #:nodoc:

  # BlankSlate provides an abstract base class with no predefined
  # methods (except for <tt>\_\_send__</tt> and <tt>\_\_id__</tt>).
  # BlankSlate is useful as a base class when writing classes that
  # depend upon <tt>method_missing</tt> (e.g. dynamic proxies).
  class BlankSlate
    class << self

      # Hide the method named +name+ in the BlankSlate class.  Don't
      # hide +instance_eval+ or any method beginning with "__".
      def hide(name)
	undef_method name if
	  instance_methods.include?(name.to_s) and
	  name !~ /^(__|instance_eval)/
      end
    end

    instance_methods.each { |m| hide(m) }
  end
end

# Since Ruby is very dynamic, methods added to the ancestors of
# BlankSlate <em>after BlankSlate is defined</em> will show up in the
# list of available BlankSlate methods.  We handle this by defining a
# hook in the Object and Kernel classes that will hide any defined
module Kernel #:nodoc:
  class << self
    alias_method :blank_slate_method_added, :method_added

    # Detect method additions to Kernel and remove them in the
    # BlankSlate class.
    def method_added(name)
      blank_slate_method_added(name)
      return if self != Kernel
      Builder::BlankSlate.hide(name)
    end
  end
end

class Object #:nodoc:
  class << self
    alias_method :blank_slate_method_added, :method_added

    # Detect method additions to Object and remove them in the
    # BlankSlate class.
    def method_added(name)
      blank_slate_method_added(name)
      return if self != Object
      Builder::BlankSlate.hide(name)
    end
  end
end

Version data entries

21 entries across 21 versions & 5 rubygems

Version Path
jstorimer-deep-test-2.0.0 sample_rails_project/vendor/rails/activesupport/lib/active_support/vendor/builder/blankslate.rb
jstorimer-deep-test-1.4.0 sample_rails_project/vendor/rails/activesupport/lib/active_support/vendor/builder/blankslate.rb
jstorimer-deep-test-1.3.0 sample_rails_project/vendor/rails/activesupport/lib/active_support/vendor/builder/blankslate.rb
jstorimer-deep-test-1.2.0 sample_rails_project/vendor/rails/activesupport/lib/active_support/vendor/builder/blankslate.rb
jstorimer-deep-test-1.1.0 sample_rails_project/vendor/rails/activesupport/lib/active_support/vendor/builder/blankslate.rb
jstorimer-deep-test-1.0.0 sample_rails_project/vendor/rails/activesupport/lib/active_support/vendor/builder/blankslate.rb
jstorimer-deep-test-0.2.0 sample_rails_project/vendor/rails/activesupport/lib/active_support/vendor/builder/blankslate.rb
jstorimer-deep-test-0.1.0 sample_rails_project/vendor/rails/activesupport/lib/active_support/vendor/builder/blankslate.rb
activesupport-1.4.4 lib/active_support/vendor/builder/blankslate.rb
activesupport-1.4.1 lib/active_support/vendor/builder/blankslate.rb
activesupport-1.4.0 lib/active_support/vendor/builder/blankslate.rb
activesupport-1.4.3 lib/active_support/vendor/builder/blankslate.rb
activesupport-1.4.2 lib/active_support/vendor/builder/blankslate.rb
monetra-ruby-0.0.6 lib/monetra/active_support/vendor/builder/blankslate.rb
radiant-0.6.1 vendor/rails/activesupport/lib/active_support/vendor/builder/blankslate.rb
radiant-0.6.0 vendor/rails/activesupport/lib/active_support/vendor/builder/blankslate.rb
radiant-0.6.3 vendor/rails/activesupport/lib/active_support/vendor/builder/blankslate.rb
radiant-0.6.2 vendor/rails/activesupport/lib/active_support/vendor/builder/blankslate.rb
radiant-0.6.4 vendor/rails/activesupport/lib/active_support/vendor/builder/blankslate.rb
rq-3.3.0 rails/vendor/rails/activesupport/lib/active_support/vendor/builder/blankslate.rb