October 2006
Intermediate to advanced
888 pages
16h 55m
English
The standard library complex enables us to handle imaginary and complex numbers in Ruby. Much of it is self-explanatory.
Complex values can be created with this slightly unusual notation:
z = Complex(3,5) # 3+5i
What is unusual about this is that we have a method name that is the same as the class name. In this case, the presence of the parentheses indicates a method call rather than a reference to a constant. In general, method names do not look like constants, and I don’t recommend the practice of capitalizing method names except in special cases like this. (Note that there are also methods called Integer and Float; in general, the capitalized method names are for data conversion or something similar.)
The ...
Read now
Unlock full access