Module: Ruby::Mn

Defined in:
lib/ruby/mn.rb,
lib/ruby/mn/version.rb

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.last_monday_of_the_month(current_date) ⇒ Object



17
18
19
20
21
# File 'lib/ruby/mn.rb', line 17

def self.last_monday_of_the_month(current_date)
  last_day_of_the_month = Date.new current_date.year, current_date.month, -1
  difference = (last_day_of_the_month.wday - 1) % 7
  Date.new last_day_of_the_month.year, last_day_of_the_month.month, last_day_of_the_month.mday - difference
end

.next_meetup(current_date) ⇒ Object



10
11
12
13
14
15
# File 'lib/ruby/mn.rb', line 10

def self.next_meetup(current_date)
  last_monday_of_this_month = last_monday_of_the_month current_date
  return last_monday_of_this_month if last_monday_of_this_month > current_date

  last_monday_of_the_month Date.new current_date.year, current_date.month + 1, 1
end

.run(current_date = Date.today) ⇒ Object



6
7
8
# File 'lib/ruby/mn.rb', line 6

def self.run(current_date = Date.today)
  puts "The next meetup is on #{next_meetup(current_date)}, hope to see you there!"
end