Home>
I want to create a program that calls the calendar month with OptionParser specified with -y, -m.
Error messageI want to call it by specifying year and month, but I'm at a loss as to how to specify it.
Could anyone please professor?
Source code
require "date"
require "optparse"
def calender_month (year: Date.today.year, month: Date.today.month)
firstday = Date.new (year, month, 1)
lastday = Date.new (year, month, -1)
first_wday = firstday.wday
lastday_date = lastday.day
puts firstday.strftime ("% m month% Y"). center (20)
puts "Sun Mon Tue Wed Thu Fri Sat"
wday = firstday.wday
print "" * wday
days = (1..lastday_date) .map {| n | n.to_s.rjust (2)}
days = Array.new (first_wday, '') .push (days) .flatten.each_slice (7) .to_a
days.each do | week |
puts week.join ('')
end
print "\ n"
end
I checked how to use OptionParser, but I didn't understand it.
Supplemental information (FW/tool version etc.)Ruby2.6.5
-
Answer # 1
Related articles
- ruby on rails - i want to display the details page
- ruby on rails - i want to move to the product purchase page
- ruby - i want to save the prototype and move the page
- ruby - i want to display the name of the poster
- i want to get the css name of ruby selenium div class as it is
- ruby on rails - i want to sort the search results
- ruby on rails - i want to save the purchase information in the db
- javascript - what do you call the mechanism of articles that pop up?
- ruby - i want to display monthly data in one
- python - i want to get the server id with discordpy
- python - i want to save all the contents in a csv file
- ruby - i want to hide a specific record
- ruby on rails - i want to launch rails with a new file
- ruby - i want to register as a user
- html - i want to arrange the text boxes side by side
- [gas] i want to use the date acquired in the gs file for the html body
- python - i want to modify the program
- i want you to see the error contents of php
- i want to change the layout with pyqt
- ruby - i want to reflect css
Trends
I wrote while referring to the document. It might work with the following code
I hope you find something helpful
LinkClass: OptionParser (Ruby 2.6.5)