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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:56:51+00:00 2026-05-27T10:56:51+00:00

On testing with ruby debugger block_given? gives false but still executes, can someone explain

  • 0

On testing with ruby debugger block_given? gives false but still executes, can someone explain me how its executed?.It is anything related to context(Is debugger changing context)?
if yes then how to find current context.

Now instead of ruby-debug when used pry then block_given? returns true.

def test
  debugger
  if block_given?
    yield(4)
  else
    puts "ss"
  end
end
test {|el| puts "#{el}" }
  • 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-27T10:56:51+00:00Added an answer on May 27, 2026 at 10:56 am

    This looks like a bug in ruby-debug, specifically Kernel#binding_n which is what is getting used by the debugger.

    You don’t need to go into the debugger read/eval/print loop to see the bug. Here is a non-interactive example example replacing the debugger() call with binding_n(0):

    require 'rubygems'; require 'ruby-debug'
    Debugger.start
    def test
      puts eval("block_given?", binding_n(0))
      if block_given?
        yield(4)
      else
        puts "ss"
     end
    end
    test {|el| puts "#{el}" }
    

    Pry doesn’t have this problem probably because it uses Ruby’s binding() rather than binding_n(). Of course that is the most reliable.

    In the case above this is clearly a win here since binding() is what is exactly wanted. But as awesome as Pry is, it can’t evaluate expressions in any stack frame context except the current (or most recent) stack frame.

    See also http://banisterfiend.wordpress.com/2011/01/27/turning-irb-on-its-head-with-pry/#comment-274 for differences between Pry and a debugger such as ruby-debug.

    Lastly, I’ll note that I tried this both in the patched MRI 1.9.2 trepanning debugger as well as rbx-trepanning for Rubinius 1.2-ish.

    Both of them work as expected. In both, the equivalent of binding_n is done differently with more help from the Ruby runtime. That leaves rb8-trepanning which has the bug because it uses binding_n as well.

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

Sidebar

Related Questions

Ruby's unit testing framework executes unit tests even though nobody creates unit test object.
I have started the book Continuous Testing with Ruby (B2.0 printing), but am running
Does someone know of a good ruby testing library for generating English (or maybe
Is there anywhere online where you can test Ruby on Rails? Mainly testing getting
I'm confused about what the various testing appliances in Ruby on Rails are for.
We're starting to standardise on a Ruby-based testing framework, having had some very good
Testing out someone elses code, I noticed a few JSP pages printing funky non-ASCII
Unit testing sounds great to me, but I'm not sure I should spend any
All, I'm using Cucumber for acceptance testing a Ruby command line utility. This utility
I'm testing Rails 3 beta 4 on Ruby 1.9.2-head, and when I start a

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.