Class: BlankSlate

Inherits:
Object show all
Defined in:
lib/configuratron/blank_slate.rb

Direct Known Subclasses

Configuratron, Configuratron::ConfigHash

Class Method Summary collapse

Class Method Details

.find_hidden_method(name) ⇒ Object



14
15
16
17
# File 'lib/configuratron/blank_slate.rb', line 14

def find_hidden_method(name)
  @hidden_methods ||= {}
  @hidden_methods[name] || (superclass.find_hidden_method(name) if superclass.respond_to?(:find_hidden_method))
end

.hide(name) ⇒ Object

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



6
7
8
9
10
11
12
# File 'lib/configuratron/blank_slate.rb', line 6

def hide(name)
  if instance_methods.include?(name) and name.to_s !~ /^(__|instance_eval|object_id)/
    @hidden_methods ||= {}
    @hidden_methods[name] = instance_method(name)
    undef_method name
  end
end

.reveal(name) ⇒ Object

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



21
22
23
24
25
# File 'lib/configuratron/blank_slate.rb', line 21

def reveal(name)
  unbound_method = find_hidden_method(name)
  fail "Don't know how to reveal method '#{name}'" unless unbound_method
  define_method(name, unbound_method)
end