提交 db63406c 编写于 作者: X Xavier Noria

apply case-in-assignment pattern

上级 810dff7c
...@@ -3,12 +3,13 @@ module Type ...@@ -3,12 +3,13 @@ module Type
module Helpers module Helpers
module Numeric # :nodoc: module Numeric # :nodoc:
def cast(value) def cast(value)
value = case value value = \
when true then 1 case value
when false then 0 when true then 1
when ::String then value.presence when false then 0
else value when ::String then value.presence
end else value
end
super(value) super(value)
end end
......
...@@ -17,11 +17,12 @@ def serialize(value) ...@@ -17,11 +17,12 @@ def serialize(value)
private private
def cast_value(value) def cast_value(value)
result = case value result = \
when true then "t" case value
when false then "f" when true then "t"
else value.to_s when false then "f"
end else value.to_s
end
result.freeze result.freeze
end end
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册