Skip to content

Instantly share code, notes, and snippets.

@alanjcfs
Created September 5, 2011 04:48
Show Gist options
  • Save alanjcfs/1194114 to your computer and use it in GitHub Desktop.
Save alanjcfs/1194114 to your computer and use it in GitHub Desktop.
Will return the day of the year in a sentence form
t = Time.now
dayth = t.yday
last_digit = dayth.to_s.slice(-1, 1).to_i
def ordinal(last_digit)
case last_digit
when 1
"st"
when 2
"nd"
when 3
"rd"
else
"th"
end
end
puts "It is the #{dayth}#{ordinal(last_digit)} day of the year."
t = Time.now
dayth = t.yday
last_digit = dayth.to_s.slice(-1, 1).to_i
def ordinal(last_digit)
case last_digit
when 1
"st"
when 2
"nd"
when 3
"rd"
else
"th"
end
end
puts "It is the #{dayth}#{ordinal(last_digit)} day of the year."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment