[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

what is mean by scope in ruby?

Vellingiri Arul

10/16/2007 4:03:00 AM

Hai friends,
Please anybody can answer this question.
What is mean by scope in ruby.


Thank you.
--
Posted via http://www.ruby-....

2 Answers

7stud --

10/16/2007 4:52:00 AM

0

Vellingiri Arul wrote:
> Hai friends,
> Please anybody can answer this question.
> What is mean by scope in ruby.
>
>

A scope is the portion of your code in which a variable can be given a
value and then retrieved.

num = 10

puts num + 1 #11

def func
puts num + 2
end

puts num + 3 #13

func #Error


The variable num is defined within a scope that includes all the areas
outside of the method definition func. However, inside the func method,
num is not "in scope" because the method definition creates a new scope:

def func
num = 10
puts num + 5
end

func #15
puts num + 6 #error


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

John Joyce

10/16/2007 6:18:00 AM

0

scope is a common idea in programming languages.
If a variable is "in scope" it can be accessed from that part of a
program.
If it is "out of scope" it is invisible in that part of the program.

Everything in your neighbor's house is out of scope to you!
Everything in your house is out of scope to your neighbor!
Everything in the street in front of your house might be in scope for
you and your neighbor.