#!/usr/local/bin/ruby require 'pp' class AnondArchive attr_reader :url, :year, :month, :year_urls def initialize(url="https://anond.hatelabo.jp/archive/")#, year, month) @url = url;# @year = year; @month = month end def add_year @year_urls = [] (6..17).each do |n| n = "0" + n.to_s unless n.to_s =~ %r|^[1][0-7]$| @year = "20" + n.to_s @year_urls << @url + @year end return @year_urls end def add_month @year_month_urls = [] @year_urls.each do |year_url| (1..12).each do |n| # n = "0" + n.to_s unless n =~ %r|^[0-9][0-2]$| #integerオブジェクトは正規表現マッチできなかったから注意 n = "0" + n.to_s unless n.to_s =~ %r|^[0-9][0-2]$| @year_month_urls << year_url + n.to_s end end return @year_month_urls end end sample = AnondArchive.new("https://anond.hatelabo.jp/archive/") #puts sample.url #puts sample.year #puts sample.month #pp sample.add_year pp sample.add_month