gouf
6/5/2015 - 2:07 PM

method, call による過剰な重複排除

method, call による過剰な重複排除

require 'date'

def date_method_call(*args)
  year, month = %i(year month).map { |x| Date.today.method(x).call }
  day, first_method, second_method = args
  Date.method(first_method).call(year, month, day).method(second_method).call
end

def last_day
  date_method_call(-1, :civil, :day)
end

def first_wday
  date_method_call(1, :new, :wday)
end

p Date.today.to_s # => "2015-06-05"
p last_day # => 30
p first_wday # => 1