Skip to content

Commit

Permalink
Refactor with pattern matching
Browse files Browse the repository at this point in the history
It's here since Ruby 2.7, 3.0 is EOL already, so it's aligned with our
maintenance policy: https://railseventstore.org/docs/v2/maintenance_policy/
  • Loading branch information
fidel committed Nov 14, 2024
1 parent a2885d4 commit 8f108b2
Showing 1 changed file with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,14 @@ def to_h

def sanitize_infinity_values(value)
case value
when Hash
value.transform_values { |v| sanitize_infinity_values(v) }
when Array
value.map { |v| sanitize_infinity_values(v) }
when Float
if value.infinite?
value.positive? ? "Infinity" : "-Infinity"
elsif value.nan?
"NaN"
else
value
end
in Hash => hash
hash.transform_values { |v| sanitize_infinity_values(v) }
in Array => array
array.map { |v| sanitize_infinity_values(v) }
in Float => f if f.infinite?
f.positive? ? "Infinity" : "-Infinity"
in Float => f if f.nan?
"NaN"
else
value
end
Expand Down

0 comments on commit 8f108b2

Please sign in to comment.