Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #4973

"Local variable within code blocks do not interfere with those outside the block"

From Kaye Ng <sbstn26@yahoo.com>
Newsgroups comp.lang.ruby
Subject "Local variable within code blocks do not interfere with those outside the block"
Date 2011-05-24 04:45 -0500
Organization Service de news de lacave.net
Message-ID <973cac1dd063c9b58788432c1267c14e@ruby-forum.com> (permalink)

Show all headers | View raw


I read this in a book.

" In Ruby 1.9, however, local variables used within code blocks will not
interfere with local variables located outside of the block."

I don't know if my code is wrong, but it looks to me like the local
variable inside the code block DOES interfere with the local variable
(with the same name) outside the code block.

x = [1, 2, 3, 4, 5]
var = 1

x.each do
       |number| (var = 10)
     end

puts var

-----------------------------------------------------

Or do I not understand the concept? I'm using 1.9.2

-- 
Posted via http://www.ruby-forum.com/.

Back to comp.lang.ruby | Previous | NextNext in thread | Find similar | Unroll thread


Thread

"Local variable within code blocks do not interfere with those outside the block" Kaye Ng <sbstn26@yahoo.com> - 2011-05-24 04:45 -0500
  Re: "Local variable within code blocks do not interfere with those outside the block" Adam Prescott <adam@aprescott.com> - 2011-05-24 05:08 -0500
    Re: "Local variable within code blocks do not interfere with those outside the block" Adam Prescott <adam@aprescott.com> - 2011-05-24 05:16 -0500
  to Adam Prescott, Kaye Ng <sbstn26@yahoo.com> - 2011-05-26 02:42 -0500
    Re: to Adam Prescott, Adam Prescott <adam@aprescott.com> - 2011-05-26 04:17 -0500
  Re: "Local variable within code blocks do not interfere with those outside the block" Bala TS <bdeveloper01@yahoo.com> - 2011-05-26 04:20 -0500
    Re: "Local variable within code blocks do not interfere with those outside the block" Josh Cheek <josh.cheek@gmail.com> - 2011-05-26 04:57 -0500
    Re: "Local variable within code blocks do not interfere with those outside the block" Adam Prescott <adam@aprescott.com> - 2011-05-26 05:05 -0500
  Re: "Local variable within code blocks do not interfere with those outside the block" Bala TS <bdeveloper01@yahoo.com> - 2011-05-26 07:46 -0500
  Re: "Local variable within code blocks do not interfere with those outside the block" Bala TS <bdeveloper01@yahoo.com> - 2011-05-26 23:09 -0500
  Re: "Local variable within code blocks do not interfere with those outside the block" Bala TS <bdeveloper01@yahoo.com> - 2011-05-26 23:11 -0500
    Re: "Local variable within code blocks do not interfere with those outside the block" Josh Cheek <josh.cheek@gmail.com> - 2011-05-26 23:30 -0500
      Re: "Local variable within code blocks do not interfere with those outside the block" Bala TS <bdeveloper01@yahoo.com> - 2011-05-26 23:59 -0500

csiph-web