Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Improved respond_to? override implementation (overriding respond_to? …

…only once after extending an unextendable module)
  • Loading branch information...
commit e71fcfa85d2bbb4e53095579171e175ae7db1285 1 parent fbb08c0
Paul Engel authored
Showing with 14 additions and 8 deletions.
  1. +4 −0 CHANGELOG.rdoc
  2. +10 −8 lib/unextendable/object.rb
View
4 CHANGELOG.rdoc
@@ -1,5 +1,9 @@
= Unextendable CHANGELOG
+== Version 0.1.4 (May 4, 2011)
+
+* Improved respond_to? override implementation (overriding respond_to? only once after extending an unextendable module)
+
== Version 0.1.3 (May 2, 2011)
* Always returning boolean when calling object.meta_class?
View
18 lib/unextendable/object.rb
@@ -43,14 +43,6 @@ def unextend(*modules, &block)
end
end
- def respond_to?(symbol, include_private = false)
- if meta_class? && meta_class.extended_modules.any?{|mod| mod.unextendable?}
- meta_class.extended_modules.detect{|x| x.instance_methods.include? symbol.to_s} || meta_class.method_procs[symbol.to_s].class == Proc
- else
- !(meta_class? && meta_class.method_procs.key?(symbol.to_s) && meta_class.method_procs[symbol.to_s].nil?) && super
- end
- end
-
private
def unextend?(mod, &block)
@@ -63,6 +55,16 @@ def wrap_unextendable_module(mod)
mod.instance_methods.each do |method_name|
wrap_unextendable_method method_name
end
+
+ return if @wrapped_respond_to
+
+ instance_eval <<-CODE
+ def respond_to?(symbol, include_private = false)
+ meta_class.extended_modules.detect{|x| x.instance_methods.include? symbol.to_s} || meta_class.method_procs[symbol.to_s].class == Proc
+ end
+ CODE
+
+ @wrapped_respond_to = true
end
def wrap_unextendable_method(name)
Please sign in to comment.
Something went wrong with that request. Please try again.