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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:45:36+00:00 2026-05-23T12:45:36+00:00

I have just started learning ruby reading from different resources. One of them is

  • 0

I have just started learning ruby reading from different resources. One of them is rubylearning.com, and I was just reading the blocks section and doing the exercises. For some reason, this example’s scope is working differently in my case:

x = 10  
5.times do |x|  
  puts "x inside the block: #{x}"  
end  

puts "x outside the block: #{x}"  

The output should be ( according to the site):

x inside the block: 0  
x inside the block: 1  
x inside the block: 2  
x inside the block: 3  
x inside the block: 4  
x outside the block: 10  

But my output is:

x inside the block: 0
x inside the block: 1
x inside the block: 2
x inside the block: 3
x inside the block: 4
x outside the block: 4

Any idea why? This section is supposed to be about the scope in ruby blocks, but I am totally confused now…

EDIT:

Ok I just realized something: I was executing my code from textmate. If i run it from the command line i get the expected result, plus 1.9.2 RUBY_VERSION. But I get 1.8.7 running it from Textmate. Has textmate its own version of ruby installed or something? – 0al0 0 secs ago edit

  • 1 1 Answer
  • 3 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-23T12:45:37+00:00Added an answer on May 23, 2026 at 12:45 pm

    Your example works since ruby 1.9.1 as the article explain:

    In Ruby 1.9.1, blocks introduce their
    own scope for the block parameters
    only.

    So you are working with another ruby version, try this:

    ruby -v
    

    I recommend to install rvm to manage different ruby versions.

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

Sidebar

Related Questions

I have just started learning Ruby on Rails. I happened to look for prevention
I have just started learning Ruby. Very cool language, liking it a lot. I
I have just started learning ruby on rails. I have a doubt wrt routing.
I have started learning Ruby and just tried out my first hello world program
I have just started learning C# and would have one question that I cannot
I have just started out learning rails and ruby, so please bear with me
I have just started learning MVVM. I've made the application from scratch by following
I have just started learning Erlang and am trying out some Project Euler problems
I have just started writing my own JavaScript Framework (just for the learning experience),
I've only just started learning ruby on rails and I would like to create

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.