Permalink
Browse files

Don't override #to_proc on ==, !=, or ===.

  • Loading branch information...
1 parent 0de26bc commit a8a11d2ee6ecae3b1487e3fc69396008985b7932 @ConradIrwin ConradIrwin committed Dec 2, 2010
Showing with 6 additions and 1 deletion.
  1. +1 −1 lib/ampex.rb
  2. +5 −0 spec/ampex_spec.rb
View
@@ -28,7 +28,7 @@ def initialize(&block)
#
def method_missing(name, *args, &block)
mv = Metavariable.new { |x| @to_proc.call(x).send(name, *args, &block) }
- Metavariable.temporarily_monkeypatch(args.last.class, mv) if name.to_s =~ /=$/
+ Metavariable.temporarily_monkeypatch(args.last.class, mv) if name.to_s =~ /[^!=]=$/
mv
end
View
@@ -33,6 +33,11 @@
[{}].map(&X['a'] = 1).first.should_not respond_to :to_proc
end
+ it "should not leak #to_proc on comparison" do
+ [:a, :b, :c].map(&X == :to_i)
+ [1,2,3].map(&:to_i).should == [1,2,3]
+ end
+
it "should not be possible to intercept #to_proc" do
b = Object.new
def intercept(b)

0 comments on commit a8a11d2

Please sign in to comment.