[#863] RDtool-0.5.0 — Toshiro Kuwabara <toshirok@...3.so-net.ne.jp>
Hi,
18 messages
1999/10/23
[#864] Re: RDtool-0.5.0
— matz@... (Yukihiro Matsumoto)
1999/10/26
Hi,
[#865] Re: RDtool-0.5.0
— Toshiro Kuwabara <toshirok@...3.so-net.ne.jp>
1999/10/26
Hi,
[#866] Re: RDtool-0.5.0
— matz@... (Yukihiro Matsumoto)
1999/10/26
Hi,
[#892] Re: RDtool-0.5.0
— Toshiro Kuwabara <toshirok@...3.so-net.ne.jp>
1999/10/31
Hi,
[#894] Re: RDtool-0.5.0
— matz@... (Yukihiro Matsumoto)
1999/11/01
Hi,
[#905] Re: RDtool-0.5.0
— Toshiro Kuwabara <toshirok@...3.so-net.ne.jp>
1999/11/04
Hi,
[#906] Re: RDtool-0.5.0
— matz@... (Yukihiro Matsumoto)
1999/11/04
Hi,
[#907] Re: RDtool-0.5.0
— Kazuhiro HIWADA <hiwada@...>
1999/11/04
Hi,
[#908] Re: RDtool-0.5.0
— kjana@... (YANAGAWA Kazuhisa)
1999/11/05
In message <19991105025532K.hiwada@kuee.kyoto-u.ac.jp>
[#867] call with a Proc — ts <decoux@...>
11 messages
1999/10/28
[#868] Re: call with a Proc
— gotoken@... (GOTO Kentaro)
1999/10/28
Hi,
[#877] local / dynamic variables — ts <decoux@...>
11 messages
1999/10/29
[#878] Re: local / dynamic variables
— gotoken@... (GOTO Kentaro)
1999/10/29
Hi,
[ruby-talk:00878] Re: local / dynamic variables
From:
gotoken@... (GOTO Kentaro)
Date:
1999-10-29 20:31:40 UTC
List:
ruby-talk #878
Hi,
In message "[ruby-talk:00877] local / dynamic variables"
on 99/10/29, ts <decoux@moulon.inra.fr> writes:
> This is probably a stupid question, but why in a block a variable is not
> always dynamic when this variable is defined between | | ?
>
> i.e. :
>
> a = [1]; i = 0; a.each {|i| p i } # i is a local variable in the block
> # at end it erase the previous value of i
> a = [1]; a.each {|i| p i } # i is a dynamic variable
As you see, in the formar case, |i| is shared with the outer scope.
A significant use of this feature can be given:
a = [4,5,6,3]
sum = 0
a.each{|i| sum += i}
p sum
In the book ``Object oriented scripting language Ruby'' (in Japanese),
scopes of local variables are illustrated as follows:
foo = 25 #<-- scope of foo
#
class Foo #
bar = 55 # #<-- scope of bar
# #
def baz(local1) # #
local2 = 88 # # #<-- scope of local1,local2
# # #
loop do # # #
local3 = 99 # # # #<-- scope of local3
..... # # # #
# # # #
end # # #
# # #
end # #
..... # #
end #
..... #
See also a related thread:
http://blade.nagaokaut.ac.jp/ruby/ruby-talk/thr200-403.html#root_351
p.s. Your question is not stupid but good :-)
-- gotoken