I wrote this code:
[1,2,3,4].each do |f|
@date = Date.new(2014,f * 3,1)
@begin = @date.beginning_of_quarter
@end = @date.end_of_quarter
puts f + " Quartal von " + @begin + " bis " + @end
end
Somehow i get the error:
DateTest.rb:2:in `initialize': wrong number of arguments (3 for 0) (ArgumentError)
from DateTest.rb:2:in `new'
from DateTest.rb:2:in `block in <main>'
from DateTest.rb:1:in `each'
from DateTest.rb:1:in `<main>'
What did i wrong? Thanks!
You passed three arguments to the original Date.new
, which does not take any argument. The one that takes arguments is the one overwritten by the "date"
library. In order to use it, you need to do
require "date"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.