Class Expectations::BlankSlate
In: lib/expectations/blank_slate.rb
Parent: Object

BlankSlate provides an abstract base class with no predefined methods (except for __send__ and __id__). BlankSlate is useful as a base class when writing classes that depend upon method_missing (e.g. dynamic proxies).

Methods

Public Class methods

[Source]

    # File lib/expectations/blank_slate.rb, line 32
32:     def find_hidden_method(name)
33:       @hidden_methods ||= {}
34:       @hidden_methods[name] || superclass.find_hidden_method(name)
35:     end

Hide the method named name in the BlankSlate class. Don’t hide instance_eval or any method beginning with “__”.

[Source]

    # File lib/expectations/blank_slate.rb, line 22
22:     def hide(name)
23:       method_name = RUBY_VERSION < '1.9' ? name.to_s : name.to_sym
24:       if instance_methods.include?(method_name) and
25:         name !~ /^(__|instance_eval|extend|is_a?|object_id)/
26:         @hidden_methods ||= {}
27:         @hidden_methods[name.to_sym] = instance_method(method_name)
28:         undef_method name
29:       end
30:     end

Redefine a previously hidden method so that it may be called on a blank slate object.

[Source]

    # File lib/expectations/blank_slate.rb, line 39
39:     def reveal(name)
40:       bound_method = nil
41:       unbound_method = find_hidden_method(name)
42:       fail "Don't know how to reveal method '#{name}'" unless unbound_method
43:       define_method(name) do |*args|
44:         bound_method ||= unbound_method.bind(self)
45:         bound_method.call(*args)
46:       end
47:     end

[Validate]