Permalink
Browse files

Clean up Attribute.determine_type with a case statement

  • Loading branch information...
1 parent 3b0df3b commit 14cc31dc644fc6bec46838b077f3502f52a8a503 @dkubb dkubb committed Jul 8, 2011
Showing with 6 additions and 7 deletions.
  1. +1 −1 config/flay.yml
  2. +5 −6 lib/virtus/attribute.rb
View
@@ -1,3 +1,3 @@
---
threshold: 19.0
-total_score: 198
+total_score: 200
View
@@ -22,12 +22,11 @@ class Attribute
#
# @api semipublic
def self.determine_type(class_or_name)
- if class_or_name.kind_of?(Class)
- if class_or_name < Attribute::Object
- determine_type_from_attribute(class_or_name)
- else
- determine_type_from_primitive(class_or_name)
- end
+ # first match on the Attribute singleton class first, then match
+ # any class, finally fallback to matching on the string
+ case class_or_name
+ when class << Attribute::Object; self end then determine_type_from_attribute(class_or_name)
+ when Class then determine_type_from_primitive(class_or_name)
else
determine_type_from_string(class_or_name.to_s)
end

0 comments on commit 14cc31d

Please sign in to comment.