Cliff Matthews
2011-Jul-31 22:03 UTC
Proc#bind implementation (active_support/core_ext/proc.rb)
Would it be a good idea to replace the implementation of Proc#bind in
active_support/core_ext/proc.rb with:
class Proc #:nodoc:
def bind(object)
lambda { |*args| object.instance_exec *args, &self }
end
end
I''m quite possibly overlooking something, but in my tests the above
implementation respects arity restrictions under Ruby 1.9.2 better
than the convoluted implementation in ActiveSupport.
In 1.8.7 the above implementation and the ActiveSupport implementation
both return a bound Proc that can have different arity restrictions
than what is passed in. Specifically, if you pass in a lambda, the
above implementation will not raise an ArgumentException if you call
the output with the wrong number of arguments. OTOH, the
ActiveSupport version will raise an ArgumentException if you call the
output with the wrong number of arguments even if you pass in a Proc
created with Proc.new (where the actual number of arguments shouldn''t
matter).
What am I overlooking?
--
Cliff Matthews <clifford.t.matthews@gmail.com>
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Core" group.
To post to this group, send email to rubyonrails-core@googlegroups.com.
To unsubscribe from this group, send email to
rubyonrails-core+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en.