Permalink
Browse files

Avoid setting a temporary class variable

  • Loading branch information...
1 parent 4e3e73e commit b8ff41487ce667000ea79bbd2ffae5d8c2cd1d1a @ConradIrwin ConradIrwin committed Dec 4, 2010
Showing with 5 additions and 7 deletions.
  1. +5 −7 lib/ampex.rb
View
@@ -58,19 +58,17 @@ def method_missing(name, *args, &block)
# too worried.
#
def self.temporarily_monkeypatch(klass, mv)
- klass.send :class_variable_set, :'@@metavariable', mv
klass.class_eval do
alias_method(:to_proc_without_metavariable, :to_proc) rescue nil
- def to_proc
- self.class.class_eval do
+ define_method(:to_proc) do
+ klass.class_eval do
- undef to_proc
+ undef :to_proc
alias_method(:to_proc, :to_proc_without_metavariable) rescue nil
- undef to_proc_without_metavariable rescue nil
+ undef :to_proc_without_metavariable rescue nil
- # Remove the metavariable from the class and return its proc
- remove_class_variable(:'@@metavariable').to_proc
+ mv.to_proc
end
end
end

0 comments on commit b8ff414

Please sign in to comment.