Skip to content

Instantly share code, notes, and snippets.

class Date
def to_words
if self == Date.today
"Today"
elsif self <= Date.today - 1
if self == Date.today - 1
"Yesterday"
elsif ((Date.today - 7)..(Date.today - 1)).include?(self)
"Last #{self.strftime("%A")}"
elsif ((Date.today - 14)..(Date.today - 8)).include?(self)
class Hash
# Accept a hash of values, changes the value in self
# from the key in the param to be indexed at the value of param
# and returns the new hash. Does not modify self.
#
# >> a = {"dog" => "meow", "bird" => "tweet" }
# => {"bird"=>"tweet", "dog"=>"meow"}
# >> a.rename_keys "dog" => "cat"
# => {"cat"=>"meow", "bird"=>"tweet"}
# >> a