Skip to content

Commit

Permalink
reducing comparisons in when statements
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Oct 12, 2010
1 parent 9852a72 commit 01893f4
Showing 1 changed file with 6 additions and 6 deletions.
Expand Up @@ -22,13 +22,13 @@ def quote(value, column = nil)
"'#{quote_string(value)}'" # ' (for ruby-mode)
end

when NilClass then "NULL"
when TrueClass then (column && column.type == :integer ? '1' : quoted_true)
when FalseClass then (column && column.type == :integer ? '0' : quoted_false)
when Float, Fixnum, Bignum then value.to_s
when nil then "NULL"
when true then (column && column.type == :integer ? '1' : quoted_true)
when false then (column && column.type == :integer ? '0' : quoted_false)
# BigDecimals need to be put in a non-normalized form and quoted.
when BigDecimal then value.to_s('F')
when Date, Time, DateTime then "'#{quoted_date(value)}'"
when BigDecimal then value.to_s('F')
when Numeric then value.to_s
when Date, Time then "'#{quoted_date(value)}'"
else
"'#{quote_string(value.to_s)}'"
end
Expand Down

2 comments on commit 01893f4

@nsinghonyx
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if it is intentional. Refactored code is changing handling of DateTime from "'#{quoted_date(value)}' to "'#{quote_string(value.to_s)}'" .

@tenderlove
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

Actually, there is a test case to make sure that DateTimes are handled properly. Also DateTime is a Date, so quoted_date() is used:

>> Date === DateTime.now
=> true
>>

Thanks for reviewing though. :-)

Please sign in to comment.