lib/dry/behaviour/cerberus.rb in dry-behaviour-0.5.0 vs lib/dry/behaviour/cerberus.rb in dry-behaviour-0.5.1
- old
+ new
@@ -91,13 +91,16 @@
when NilClass then m.arity < 0
when Integer then hash == args.size
end
next if hash.nil?
hash.all? do |param, condition|
- idx = m.parameters.index { |_type, var| var == param }
+ type_var, idx = m.parameters.each_with_index.detect { |(_type, var), idx| var == param }
# rubocop:disable Style/CaseEquality
# rubocop:disable Style/RescueModifier
- idx && condition === args[idx] rescue false # FIXME: more accurate
+ idx && (case type_var.first
+ when :req, :opt then condition === args[idx] rescue false
+ when :block then condition === cb
+ end)
# rubocop:enable Style/RescueModifier
# rubocop:enable Style/CaseEquality
end
end
raise ::Dry::Guards::NotMatched.new(*args, **params, &cb) unless found