TimeExtensions Plugin
2006-11-14
A minor plugin for all of you. This plugin merely adds two new methods to Time and Date:
test/time_extensions_test.rb
1 class TimeExtensionsTest < Test::Unit::TestCase 2 def test_really_in_future 3 assert 1.second.from_now.in_future? 4 end 5 6 def test_in_future_but_past 7 assert !1.second.ago.in_future? 8 end 9 10 def test_really_in_past 11 assert 1.second.ago.in_past? 12 end 13 14 def test_in_past_but_future 15 assert !1.second.from_now.in_future? 16 end 17 end
This makes for much more readable code:
1 if @post.published_at.in_future? then 2 # do something 3 else 4 # do something else 5 end
Installation:
1 $ script/plugin install \ 2 svn://svn.teksol.info/svn/rails/plugins/time_extensions \ 3 vendor/plugins/time_extensions
blog comments powered by Disqus