From 7fbf7e536dd223194933c32238bd9e72d39d3cc3 Mon Sep 17 00:00:00 2001 From: Chris Nixon Date: Sat, 9 Jan 2016 16:32:17 -0800 Subject: [PATCH] Use condition_type in case statement for included?. --- lib/active_model/serializer/field.rb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/active_model/serializer/field.rb b/lib/active_model/serializer/field.rb index 79f97e7b..1134bb35 100644 --- a/lib/active_model/serializer/field.rb +++ b/lib/active_model/serializer/field.rb @@ -25,7 +25,7 @@ module ActiveModel # @api private # def included?(serializer) - case condition + case condition_type when :if serializer.public_send(condition) when :unless @@ -38,13 +38,14 @@ module ActiveModel private def condition_type - if options.key?(:if) - :if - elsif options.key?(:unless) - :unless - else - :none - end + @condition_type ||= + if options.key?(:if) + :if + elsif options.key?(:unless) + :unless + else + :none + end end def condition