Class: BlankSlate

Inherits:
Object show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/lib/blankslate.rb

Overview

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).

Direct Known Subclasses

Builder::XmlBase

Class Method Summary collapse

Class Method Details

.find_hidden_method(name) ⇒ Object



60
61
62
63
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/lib/blankslate.rb', line 60

def find_hidden_method(name)
  @hidden_methods ||= {}
  @hidden_methods[name] || 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 “__”.



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/lib/blankslate.rb', line 47

def hide(name)
  warn_level = $VERBOSE
  $VERBOSE = nil
  if instance_methods.include?(name._blankslate_as_name) &&
      name !~ /^(__|instance_eval$)/
    @hidden_methods ||= {}
    @hidden_methods[name.to_sym] = instance_method(name)
    undef_method name
  end
ensure
  $VERBOSE = warn_level
end

.reveal(name) ⇒ Object

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



67
68
69
70
71
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/lib/blankslate.rb', line 67

def 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