From 5e9b6b4890dbba5c8a900de63820b8a8755a6bf7 Mon Sep 17 00:00:00 2001 From: KOTP Date: Tue, 19 Mar 2024 01:16:16 -0400 Subject: [PATCH] Alignment, redundant self, space around operators [no important files changed] --- .../practice/complex-numbers/.meta/example.rb | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/exercises/practice/complex-numbers/.meta/example.rb b/exercises/practice/complex-numbers/.meta/example.rb index dd337f127c..6f5eb3dbd4 100644 --- a/exercises/practice/complex-numbers/.meta/example.rb +++ b/exercises/practice/complex-numbers/.meta/example.rb @@ -1,4 +1,5 @@ class ComplexNumber + attr_reader :real, :imaginary def initialize(real, imaginary = 0) @@ -7,39 +8,39 @@ def initialize(real, imaginary = 0) end def ==(other) - (self - other).abs < 1e-15 + (self - other).abs < 1e-15 end def +(other) - self.class.new(@real + other.real, @imaginary + other.imaginary) + self.class.new(real + other.real, imaginary + other.imaginary) end def -(other) - self.class.new(@real - other.real, @imaginary - other.imaginary) + self.class.new(real - other.real, imaginary - other.imaginary) end def *(other) - self.class.new(@real * other.real - @imaginary * other.imaginary, - @real * other.imaginary + @imaginary * other.real) + self.class.new(real * other.real - imaginary * other.imaginary, + real * other.imaginary + imaginary * other.real) end def /(other) - self*other.inv + self * other.inv end def abs - Math.sqrt((self*self.conjugate).real) + Math.sqrt((self * conjugate).real) end def conjugate - self.class.new(@real, -@imaginary) + self.class.new(real, -imaginary) end def inv - self.class.new(@real / abs**2, -@imaginary / abs**2) + self.class.new(real / abs**2, -imaginary / abs**2) end def exp - self.class.new(Math.exp(@real)) * self.class.new(Math.cos(@imaginary), Math.sin(@imaginary)) + self.class.new(Math.exp(real)) * self.class.new(Math.cos(imaginary), Math.sin(imaginary)) end end