From: Love U Ruby Date: 2013-02-18T03:09:15+09:00 Subject: What is Ruby's default constructor? Hi, I wrote the below class : >> class Adder >> ?> def initialize(my_num) >> @my_num = my_num >> end >> ?> end => nil >> ob = Adder.new ArgumentError: wrong number of arguments (0 for 1) from (irb):3:in `initialize' from (irb):8:in `new' from (irb):8 from /usr/bin/irb:12:in `
' #~~~> Here it is not allowing the creation of object.Even does not allowing automatic call to its default constructor which it does when a class has been defined without "initialize" method. >> ob = Adder.new(10) => # #~~~> here it is OK. and it should be. #~~> then in the below class how object is created, what constructor it has called? >> class A >> p "hi" >> end "hi" => "hi" >> ob = A.new => # >> -- Posted via http://www.ruby-forum.com/.