The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Ruby has variable scoping

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Dave Hoover

Posts: 93
Nickname: dsrhoov53
Registered: Mar, 2004

Dave Hoover is the Lead Consultant for Obtiva
Ruby has variable scoping Posted: Apr 19, 2007 11:04 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Dave Hoover.
Original Post: Ruby has variable scoping
Feed Title: Red Squirrel Reflections
Feed URL: http://redsquirrel.com/cgi-bin/dave/index.rss
Feed Description: Dave Hoover explores the psychology of software development
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Dave Hoover
Latest Posts From Red Squirrel Reflections

Advertisement
Gareth joined me in the d'oh! club today when I revealed to him the revelation that Ryan provided me back in January. Ruby has variable scoping, meaning that this code works just fine:
if false
  a = 1
end

puts a # nil
Up until Ryan revealed this to me, I had been merrily (and needlessly) declaring my variables outside the control structures that defined them. Maybe Gareth and I are the only ones who weren't aware of this aspect of Ruby (and many other dynamic languages), but just in case, I thought I'd share it with you.

Read: Ruby has variable scoping

Topic: A Scaling Complex Previous Topic   Next Topic Topic: Adding Properties to Ruby Metaprogramatically

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use