Use conditionals and implicit returns rather than explicit returns and postfix ifs (it's easier to read)

This commit is contained in:
Jon Leighton
2010-12-23 20:05:34 +00:00
parent 739ea1fbfe
commit ac67eee4e6

View File

@@ -21,9 +21,13 @@ module ActiveRecord
# have a size larger than zero, and you need to fetch that collection afterwards, it'll take one fewer
# SELECT query if you use #length.
def size
return @owner.send(:read_attribute, cached_counter_attribute_name) if has_cached_counter?
return @target.size if loaded?
return count
if has_cached_counter?
@owner.send(:read_attribute, cached_counter_attribute_name)
elsif loaded?
@target.size
else
count
end
end
protected