Module: CMDx::Coercions::Complex
Overview
Coerces to ‘Complex`. Supply `imaginary:` to provide the imaginary component when `value` is a real-only input.
Instance Method Summary collapse
Instance Method Details
#call(value, options = EMPTY_HASH) ⇒ Complex, Coercions::Failure
15 16 17 18 19 20 21 22 |
# File 'lib/cmdx/coercions/complex.rb', line 15 def call(value, = EMPTY_HASH) return value if value.is_a?(::Complex) Complex(value, [:imaginary] || 0) rescue ArgumentError, TypeError type = I18nProxy.t("cmdx.types.complex") Failure.new(I18nProxy.t("cmdx.coercions.into_a", type:)) end |