Skip to content

Instantly share code, notes, and snippets.

@softwaregravy
Created October 11, 2011 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save softwaregravy/1279822 to your computer and use it in GitHub Desktop.
Save softwaregravy/1279822 to your computer and use it in GitHub Desktop.
Day Map
module DayMap
day_array = []
Date::DAYNAMES.each_with_index{|d, i| day_array << [d, i]}
reverse_day_array = []
Date::DAYNAMES.each_with_index{|d, i| reverse_day_array << [i, d]}
DAY_MAP = Hash[day_array]
REVERSE_MAP = Hash[reverse_day_array]
class << self
def day_for_int(i)
REVERSE_MAP[i.to_i]
end
def int_for_day(day)
DAY_MAP[day.to_s.capitalize]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment