You can create a complex number in Ruby with
c = Complex.new(1,2)
but it can be reduced to
c = Complex(1,2)
Is it possible to achieve the same functionality without having to define a function outside the class, as in the example below?
class Bits
def initialize(bits)
@bits = bits
end
end
def Bits(list)
Bits.new list
end
b = Bits([0,1])
I think Ruby should allow at least one of the suggested constructors below
class Bits
def initialize(bits)
@bits = bits
end
def self.Bits(list)
new list
end
def Bits(list)
new list
end
def Bits.Bits(list)
new list
end
end
source
share