gigasecond.rb

1
2
3
4
5
6
7
class Gigasecond
	ONE_GIGASECOND = 10**9

	def self.from(date)
		(date.to_time + ONE_GIGASECOND).to_date
	end
end

@lee-jon thinks this looks great

Comments

didn't need to require 'date' as it was in the test

glamouracademy commented 29 October 2014 at 19:02 UTC

removed require 'time' from test

glamouracademy commented 29 October 2014 at 19:24 UTC

Looks good! Did you know that Ruby is pretty good at using convention, meaning you only need to specify unconventional aspects. See what happens when you just add a number to a Date.

sprunger commented 29 October 2014 at 19:38 UTC

@sprunger thanks so I tried removing to_time and to_date, thinking that when I added ONE_GIGASECOND to date, ruby might stick with the date convention but this didn't work. Could you elaborate?

here's what didn't work:

(date + ONE_GIGASECOND)

glamouracademy commented 22 December 2014 at 21:55 UTC

You're not logged in right now. Please login via GitHub to comment