I'm getting "uninitialized constant Date (NameError)" with the following code:
class Test
  attr_accessor :reqs
  def initialize()
    @reqs = []
  end
end
class TestBuilder
  def test(&block)
    @current = Test.new
    block.call
    @current
  end
  def older_than_days(age)
    @current.reqs << lambda { |email| ::Date.parse(email[:date]) < ::Date.today - age }
  end
end
b = TestBuilder.new
x = b.test { b.older_than_days(1) }
p x.reqs[0].call( {:date => "Mon, 5 Apr 2010 03:17:46 -0400"} )
The double-colon was added after reading the answer to this problem: Uninitialized constant ... NameError because ruby was trying to find Date in TestBuilder. Is Date not in the global namespace? Or am I doing something else wrong here?
Try require 'date'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With