This is a multi-part message in MIME format.
--Boundary_(ID_0Z5tPB9IEfRmxsNUMLt8FQ)
Content-type: text/plain; charset=UTF-8
Content-transfer-encoding: 7BIT
Diogo Lisboa wrote:
> On Wed, Nov 26, 2008 at 4:32 PM, Francoys <francois.pr / videotron.ca> wrote:
>
>> declaring variables inside a method that are accessibles to all the
>> nested methods.
>>
>
> This isn't possible though.
>
> def foo
> bar 0
> def gazonk
> p bar
> end
> end
>
>
>>> gazonk # undefined local variable or method `gazonk'
>>> foo # nil
>>> gazonk # undefined local variable or method `bar'
>>>
>
>
> This doesn't work because the chained method is in a whole new scope
> which doesn't know anything about the outer method's local variables.
>
> But, however odd this functionality is, I think it would be useful for
> the enclosing method to inherit the outer scope. You'd get something
> like named closures, and calling `gazonk' after `foo' would be able to
> print 10.
>
> However, this wouldn't be consistent, meaning, it should have to work
> if you declared a local variable in a class definition and all the
> methods would be aware of that; at this point, things get ugly.
>
> I think the idea of 'named closure' could be interesting (I don't know
> what consequences this would have, but sounds like a feature more than
> a bug). It beats returning lambdas in an array.
>
> Would you, enlightened ones, share your opinions on this? On the idea
> of the local methods being a bug or feature, I don't think they count
> much as a feature the way they currently are.
>
>
> Diogo
>
>
>
Try this one:
def foo
@bar 0
def gazonk
print @bar
end
gazonk
end
foo
Everything is an object in Ruby ...
--Boundary_(ID_0Z5tPB9IEfRmxsNUMLt8FQ)
Content-type: text/html; charset=UTF-8
Content-transfer-encoding: 8BIT
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content ext/html;charset F-8" http-equiv
ontent-Type">
<title></title>
</head>
<body bgcolor ffffff" text 000000">
Diogo Lisboa wrote:
<blockquote
cite ida07a01900811271702p2b80e3earcb846965037bea9f / mail.gmail.com"
type
ite">
<pre wrap >On Wed, Nov 26, 2008 at 4:32 PM, Francoys <a class oz-txt-link-rfc2396E" href ailto:francois.pr / videotron.ca"><francois.pr / videotron.ca></a> wrote:
</pre>
<blockquote type
ite">
<pre wrap >declaring variables inside a method that are accessibles to all the
nested methods.
</pre>
</blockquote>
<pre wrap ><!---->
This isn't possible though.
def foo
bar 0
def gazonk
p bar
end
end
</pre>
<blockquote type
ite">
<blockquote type
ite">
<pre wrap >gazonk # t; undefined local variable or method `gazonk'
foo # t; nil
gazonk # t; undefined local variable or method `bar'
</pre>
</blockquote>
</blockquote>
<pre wrap ><!---->
This doesn't work because the chained method is in a whole new scope
which doesn't know anything about the outer method's local variables.
But, however odd this functionality is, I think it would be useful for
the enclosing method to inherit the outer scope. You'd get something
like named closures, and calling `gazonk' after `foo' would be able to
print 10.
However, this wouldn't be consistent, meaning, it should have to work
if you declared a local variable in a class definition and all the
methods would be aware of that; at this point, things get ugly.
I think the idea of 'named closure' could be interesting (I don't know
what consequences this would have, but sounds like a feature more than
a bug). It beats returning lambdas in an array.
Would you, enlightened ones, share your opinions on this? On the idea
of the local methods being a bug or feature, I don't think they count
much as a feature the way they currently are.
Diogo
</pre>
</blockquote>
Try this one:<br>
<br>
def foo<br>
@bar 0<br>
def gazonk<br>
print @bar<br>
end<br>
gazonk<br>
end<br>
<br>
foo<br>
<br>
<br>
Everything is an object in Ruby ...<br>
</body>
</html>
--Boundary_(ID_0Z5tPB9IEfRmxsNUMLt8FQ)--