Class: AE::BasicObject

Inherits:
Object show all
Defined in:
lib/ae/basic_object.rb

Overview

BasicObject provides an abstract base class with no predefined methods (except for _\send_ and _\id_). BasicObject is useful as a base class when writing classes that depend upon method_missing (e.g. dynamic proxies).

BasicObject is based on BlankSlate by Jim Weirich.

Copyright 2004, 2006 by Jim Weirich ([email protected]). All rights reserved.

Direct Known Subclasses

Assertor, Kernel::Pry

Class Method Summary collapse

Class Method Details

.find_hidden_method(name) ⇒ Object



33
34
35
36
# File 'lib/ae/basic_object.rb', line 33

def self.find_hidden_method(name)
  @hidden_methods ||= {}
  @hidden_methods[name.to_sym] || superclass.find_hidden_method(name)
end

.hide(name) ⇒ Object

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



23
24
25
26
27
28
29
30
31
# File 'lib/ae/basic_object.rb', line 23

def self.hide(name)
  name = name.to_s
  if instance_methods.include?(name) and
    name !~ /^(__|instance_eval|instance_exec)/
    @hidden_methods ||= {}
    @hidden_methods[name.to_sym] = 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.



40
41
42
43
44
# File 'lib/ae/basic_object.rb', line 40

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