Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixing arity2 test

  • Loading branch information...
commit dbee8c32588083f54857e01b20479229b2f49498 1 parent c718256
@tenderlove tenderlove authored
Showing with 8 additions and 3 deletions.
  1. +8 −3 activesupport/lib/active_support/callbacks.rb
View
11 activesupport/lib/active_support/callbacks.rb
@@ -109,10 +109,10 @@ def call(env)
class Before
def self.build(next_callback, user_callback, user_conditions, chain_config, filter)
def self.build(next_callback, user_callback, user_conditions, chain_config, filter)
  if chain_config.key? :terminator
    halted_lambda = class_eval "lambda { |result| #{chain_config[:terminator]} }", __FILE__, __LINE__

    if user_conditions.any?
      halting_and_conditional(next_callback, user_callback, user_conditions, halted_lambda, filter)
    else
      halting(next_callback, user_callback, halted_lambda, filter)
    end
  elsif user_conditions.any?
    conditional(next_callback, user_callback, user_conditions)
  else
    simple(next_callback, user_callback)
  end
end

Also wonder if the class_eval can be done using an exec and plain ruby code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
if chain_config.key?(:terminator) && user_conditions.any?
- halted_lambda = eval "lambda { |result| #{chain_config[:terminator]} }"
+ halted_lambda = class_eval "lambda { |result| #{chain_config[:terminator]} }", __FILE__, __LINE__
halting_and_conditional(next_callback, user_callback, user_conditions, halted_lambda, filter)
elsif chain_config.key? :terminator
- halted_lambda = eval "lambda { |result| #{chain_config[:terminator]} }"
+ halted_lambda = class_eval "lambda { |result| #{chain_config[:terminator]} }", __FILE__, __LINE__
halting(next_callback, user_callback, halted_lambda, filter)
elsif user_conditions.any?
conditional(next_callback, user_callback, user_conditions)
@@ -431,7 +431,12 @@ def make_lambda(filter)
l = eval "lambda { |value| #{filter} }"
lambda { |target, value| target.instance_exec(value, &l) }
when ::Proc
- raise ArgumentError if filter.arity > 1
+ if filter.arity > 1
+ return lambda { |target, _, &block|
+ raise ArgumentError unless block
+ target.instance_exec(target, block, &filter)
+ }
+ end
if filter.arity <= 0
lambda { |target, _| target.instance_exec(&filter) }
Please sign in to comment.
Something went wrong with that request. Please try again.