Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6054015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:06:18+00:00 2026-05-23T08:06:18+00:00

The date_validator in its examples has a comment: Using Proc.new prevents production cache issues

  • 0

The date_validator in its examples has a comment:

Using Proc.new prevents production cache issues

Does it mean, that everywhere in my code, where I use current time related methods (Time.now, 1.day.since(Time.zone.now), etc.) I should surround them with Proc.new { }?

I don’t completely understand this, since replacing

time_now = Time.now.utc

with

time_now = Proc.new { Time.now.utc }

just doesn’t make sense to me (new type of object is returned).

So, the question is, when and how should I use Proc.new with time related methods? And does that still apply to the latest versions of Ruby (1.92) and Rails (3.1)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:06:18+00:00Added an answer on May 23, 2026 at 8:06 am

    What Proc.new (and lambda) does is, save all your statements in their original form (in an anonymous function), and doesn’t evaluate them.

    Date Validator gem must have some kind of test to check if a Proc was passed, and it evaluates it when it’s actually validating the stuff.

    Edit: It does this here – https://github.com/codegram/date_validator/blob/master/lib/active_model/validations/date_validator.rb#L47

    option_value = option_value.call(record) if option_value.is_a?(Proc)
    

    A quick example :

    pry(main)> time_now = Time.now
    => 2011-06-19 21:07:07 +0530
    pry(main)> time_proc = Proc.new { Time.now }
    => #<Proc:0x9710cc4@(pry):1>
    pry(main)> time_proc.call
    => 2011-06-19 21:07:28 +0530
    pry(main)> time_proc.call
    => 2011-06-19 21:07:31 +0530
    pry(main)> 
    

    Note that this will only work with libraries that do implement this kind of check, and not every function accepting a Time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Looking for some implementation advice: I have a page that has a 3-tab ajaxToolkit:TabContainer.
I'm having trouble formulating HTTP cache headers for the following situation. Our server has
I have a form page that has an inputText field that accepts a date.
I am using org.apache.commons.validator.routines.DateValidator to validate a date with a simple date pattern dd/mm/yyyy
What would the regex expression that would go into preg_split function to validate date
how i do validate two date textboxes using jquery. i came across this snippet
I'm trying to write a regular expression that validates a date. The regex needs
I have an automatically binded DataGridView that obtains data and update data directly from
I have a very large Form with many date fields that need to be
I need a bit of help using symfony to calculate an end date. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.