Ruby Classes are Open, Damnit
Published 2011-12-13 @ 16:44
Tagged ruby, thoughts
Ruby Classes are Open. Use it to your advantage. Ruby’s Date.parse
changed between 1.8 and 1.9 so that European date formats are
preferred over US date formats. I’ve seen a lot of American rubyists
whine about this. It took about 5 minutes looking at Date code to
figure out that the solution is trivial:
1 2 3 4 5 6 7 8 9 10 11 |
require 'date' class Date class << self alias :_temp_us :_parse_us alias :_parse_us :_parse_eu alias :_parse_eu :_temp_us end end if RUBY_VERSION =~ /1\.9/ puts Date.parse("10/4/2010") # => 2010-10-04 |
Recently, Jeremy Evans’ released ruby-american_date to address this issue. You should probably use his solution over mine. Mine is just here as an illustration that it really doesn’t take much time or effort to address your whining.