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

  • Home
  • SEARCH
  • 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 6046275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:13:13+00:00 2026-05-23T07:13:13+00:00

I am writing an internal DSL in Ruby. Currently, the basic structure in this

  • 0

I am writing an internal DSL in Ruby. Currently, the basic structure in this mini language is a block that must include the method during, and optionally some other methods. E.g.:

do
  something...
  during do ... end
  something else ...
end

I would like to simplify the language by treating blocks differently if they do not include the during keyword. In this case I can just treat them like any other Ruby block.

Is it possible to detect if a block includes a specific method without running it? It is ok to assume that the method is not nested within an inner scope, like an if or while statement. I assume that if possible, this will involve reflection, which is ok.

Refinement and explanations

I am not trying to solve the halting problem or overcome any trick that a Ruby hacker might think of. The solution may apply only to the most naive case.

In several languages it is possible to get some reflection on the source code at runtime. In Python method objects have fields like bindings and bytecode. In Java, it is possible, although not trivial, to read the bytecode of a method and look for invokevirtual commands.

I am not very familiar with Ruby. I don’t know if Ruby objects that represent control elements, like procs and blocks, have similar fields. If my memory serves, Ruby has some framework for accessing its AST on runtime. However, I don’t know if and how this framework can access specific blocks. A solution based on runtime AST parsing that works only for simple cases is perfectly acceptable.

  • 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-23T07:13:14+00:00Added an answer on May 23, 2026 at 7:13 am

    Spontaneously the only way that comes to mind is using the to_source method from the sourcify gem and then matching against the resulting string:

    https://github.com/ngty/sourcify

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

Sidebar

Related Questions

I am writing an internal DSL in Ruby. For this, I need to programmatically
I'm writing an internal service that needs to touch a mod_perl2 instance for a
I'm writing an internal-tools webapp; one of the central pages in this tool has
I'm writing an internal business application that needs to access a number of different
I use this LINQ query in an app I am writing: internal int GetNoteCount(DateTime
I am involved in writing a little internal SharePoint portal for our company. I
Writing a JSP page, what exactly does the <c:out> do? I've noticed that the
Writing something like this using the loki library , typedef Functor<void> BitButtonPushHandler; throws a
I writing a report in Visual Studio that takes a user input parameter and
I have a lot of experience writing internal Intranet applications, but very little when

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.