Class: ContextR::InnerClass
Overview
:nodoc:
Class Method Summary collapse
- .find_hidden_method(name) ⇒ Object
-
.hide(name) ⇒ Object
Hide the method named
name
in the BlankSlate class. -
.reveal(name) ⇒ Object
Redefine a previously hidden method so that it may be called on a blank slate object.
Instance Method Summary collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*rest_args) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/contextr/inner_class.rb', line 43 def method_missing(*rest_args) if block_given? yield(:next, *rest_args) else super end end |
Class Method Details
.find_hidden_method(name) ⇒ Object
23 24 25 26 |
# File 'lib/contextr/inner_class.rb', line 23 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 “__”.
14 15 16 17 18 19 20 21 |
# File 'lib/contextr/inner_class.rb', line 14 def hide(name) if instance_methods.include?(name.to_s) and name !~ /^(__)/ @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.
30 31 32 33 34 35 36 37 38 |
# File 'lib/contextr/inner_class.rb', line 30 def reveal(name) bound_method = nil unbound_method = find_hidden_method(name) fail "Don't know how to reveal method '#{name}'" unless unbound_method define_method(name) do |*args| bound_method ||= unbound_method.bind(self) bound_method.call(*args) end end |