ruby - Why does this semantically identical class cause an undefined method 'new' error? -
why following code error:
class complex def initialize(real, imaginary) @imaginary = imaginary @real = real end end c = complex.new(5,3)
complex.rb:8:in
<main>': undefined method
new' complex:class (nomethoderror)
but semantically identical program below not:
class wat def initialize(a, b) @a = @b = b end end c = wat.new(5,3)
because complex
exists, , built in different way, e.g.,
complex(2, 3)
when re-open class (not defining own) operate under existing class's constraints.
new
removed somewhere around 1.9 iirc.
Comments
Post a Comment