Skip to content

Commit

Permalink
Give an original method a unique name
Browse files Browse the repository at this point in the history
  • Loading branch information
k-tsj committed Jul 18, 2015
1 parent b30dfaf commit fe82fa8
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/pattern-match/disable_refinements.rb
@@ -1,10 +1,12 @@
class Module
refine_orig = "__refine_orig_#{Time.now.to_i}".to_sym

methods = instance_methods(false) + private_instance_methods(false)
if methods.include?(:refine)
if methods.include?(:__refine_orig)
if methods.include?(refine_orig)
raise LoadError, "can't re-define Module#refine"
end
alias_method :__refine_orig, :refine
alias_method refine_orig, :refine
remove_method :refine
end

Expand All @@ -17,9 +19,9 @@ def refine(klass, &blk)
ensure
remove_method :refine

if Kernel.respond_to?(:__refine_orig, true)
alias_method :refine, :__refine_orig
remove_method :__refine_orig
if Kernel.respond_to?(refine_orig, true)
alias_method :refine, refine_orig
remove_method refine_orig
end
end
end

0 comments on commit fe82fa8

Please sign in to comment.