Skip to content

Instantly share code, notes, and snippets.

@brianleroux
Created December 1, 2008 02:12
Show Gist options
  • Save brianleroux/30593 to your computer and use it in GitHub Desktop.
Save brianleroux/30593 to your computer and use it in GitHub Desktop.
# fucking around to hack together the most ghetto date_select known to man
require 'date'
def date_select( field, options={} )
# wraps content with a specified tag
def rapper(tag, options={})
"<#{ tag }>#{ yield if block_given? }</#{ tag }>"
end
# returns a correctly ordered array from a range
ranger = lambda do |from,to|
if from > to
c = "(#{ to }..#{ from }).to_a.reverse"
else
c = "(#{ from }..#{ to }).to_a"
end
return eval(c)
end
year = rapper(:select) do
ranger.call(DateTime.now.year, 1978).map { |x| rapper(:option){ x }}
end
month = rapper(:select) do
ranger.call(1,12).map { |x| rapper(:option){ x }}
end
day = rapper(:select) do
ranger.call(1,31).map { |x| rapper(:option){ x }}
end
"#{ year }#{ month }#{ day }"
end
puts date_select('foo')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment