Complex是一个内置的类.为了制作一个Complex物体,我写道:
Complex(10, 5)
Run Code Online (Sandbox Code Playgroud)
但是如果我创建自己的类Thing:
class Thing
def initalize()
end
end
Run Code Online (Sandbox Code Playgroud)
要创建一个新的Thing,我必须写:
Thing.new(...)
Run Code Online (Sandbox Code Playgroud)
有可能创建一个构造函数,Thing所以我可以写:
Thing(...)
Run Code Online (Sandbox Code Playgroud)
并让它像一个内置的类,如Complex(1,1)?