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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:12:15+00:00 2026-05-27T05:12:15+00:00

Specifically in ruby, I’m wondering if I am able to do something. Let’s say

  • 0

Specifically in ruby, I’m wondering if I am able to do something.

Let’s say I have a while loop that does something until a condition is no longer met.
I will be needing this same while loop for multiple purposes but the condition changes every time. Thus I want change it to a function for re-usability purposes.

Is it possible for me to pass (what condition I’m checking for) as an argument?

Something like:

def wait(condition)
  while condition
    do something
  end
end

To clarify, I want to pass the condition (or statement) itself, not the evaluation of the statement at the time of running the function.
Also I’m pretty sure I’m giving these the wrong names (statement/condition/evaluation) so please correct me if I’m mistaken.

  • 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-27T05:12:16+00:00Added an answer on May 27, 2026 at 5:12 am

    You could do that with blocks:

    def wait(&condition)
        while condition.call()
            # do something
        end
    end
    
    ...
    
    wait {true} # never returns
    

    See http://www.robertsosinski.com/2008/12/21/understanding-ruby-blocks-procs-and-lambdas/ for some useful information.

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

Sidebar

Related Questions

Specifically I have a PHP command-line script that at a certain point requires input
Is there anything better than the Disqus Ruby Gem ? Perhaps something geared specifically
I have been learning Ruby & more specifically the rails framework the past few
I have a desktop application written in Ruby that is using GTK2. It's just
Specifically, in VS 2008, I want to connect to a data source that you
How do you download files, specifically .zip and .tar.gz, with Ruby and write them
I'm playing around with Ruby's .object_id and noticed that, in several sequential sessions of
First of all you have to know I'm total Ruby noob :) I installed
I am wondering if there's anything out there for ASP.NET that is similar to
I am getting started with a non-SQL database (specifically, MongoDB) and Ruby on Rails

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.