Skip to content

Instantly share code, notes, and snippets.

@koleksiuk
Created October 1, 2012 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koleksiuk/3813554 to your computer and use it in GitHub Desktop.
Save koleksiuk/3813554 to your computer and use it in GitHub Desktop.
class Complex
def initialize(_re = 0.0, _im = 0.0)
self.re = _re
self.im = _im
end
def +(val)
Complex.new(self.re + val.re, self.im + val.im)
end
attr_accessor :re, :im
end
a = Complex.new(2.1, 3.3)
b = Complex.new(1,1.2)
c = a + b
puts "#{c.re} + #{c.im}i" #==> 3.1 + 4.5i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment