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 7887069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:29:05+00:00 2026-06-03T05:29:05+00:00

In my Rails app I need to get the dates for the next occurrence

  • 0

In my Rails app I need to get the dates for the next occurrence of a particular weekday starting from some other date. So basically I need date.next_monday, date.next_wednesday type functions. I don’t think these exist in standard Ruby libraries so I decided to monkey patch the Date class like so:

class Date
  weekdays = [:sunday, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday]
  weekdays.each do |weekday|
    method_name = "next_" + weekday.to_s
    send :define_method, method_name do
      tmp_date = self + 1
      until tmp_date.send((weekday.to_s + "?").to_sym)
        tmp_date = tmp_date + 1
      end
      tmp_date
    end
  end
end

This seems to work fine.
My questions are:

  1. Did I not need to do all that? (Is there some way to get next_ that I’m not thinking of?
  2. If what I did is necessary, is there a better way to get the weekdays array?

Thanks!

  • 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-06-03T05:29:06+00:00Added an answer on June 3, 2026 at 5:29 am

    The Date class defines a DAYNAMES constant (as well as a number of other useful constants) that you could use to replace your array.

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

Sidebar

Related Questions

So I need to access this service from my rails app. I'm using soap4r
I need to produce somewhat complicated PDFs from a Rails app - tables with
I need to start a copy of a Rails app from within Java. I
We have the rails app, content served from the database. Now we need to
How to access MongoHQ db in my rails app, I need to get perform
I want to make some request from iPhone app to my web service (Rails)
I need to parse a simple json response (from my rails app): [ {
I am building a small rails app and I need a way to generate
I need to implement fine-grained access control in a Ruby on Rails app. The
I have an XML view in a rails app, and need to insert in

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.