Re: pipe question
- From: Robert Klemme <shortcutter@xxxxxxxxxxxxxx>
- Date: Tue, 5 Apr 2011 10:27:07 -0500
On Tue, Apr 5, 2011 at 4:35 PM, Chad Perrin <code@xxxxxxxxxxxx> wrote:
On Tue, Apr 05, 2011 at 12:30:47PM +0900, Josh Cheek wrote:
On Mon, Apr 4, 2011 at 7:12 PM, 7stud -- <bbxx789_05ss@xxxxxxxxx>
wrote:
Here is an example that might prove illustrative:
if 1 > 10
x = 'hello' #never executes
end
puts x #=> nil
puts y #=> undefined local variable or method `y'
#for main:Object (NameError)
Good thought. I'm honestly surprised that works! I guess it must add x
to the symbol table at parse time.
Is that something we should be able to depend on, though -- or just an
accident of implementation?
I think it's a language feature. From the line where an assignment to
a identifier is found this identifier denotes a local variable -
whether the code is actually executed does not matter. This is only
about syntactical order. Consider
$ ruby19 -e 'puts(x) if x=1'
-e:1: warning: found = in conditional, should be ==
-e:1:in `<main>': undefined local variable or method `x' for
main:Object (NameError)
$ ruby19 -e 'x=1;puts(x) if x'
1
$
Kind regards
robert
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
.
- References:
- pipe question
- From: wolf volpi
- Re: pipe question
- From: Josh Cheek
- Re: pipe question
- From: 7stud --
- Re: pipe question
- From: Josh Cheek
- pipe question
- Prev by Date: Re: Seeking advice
- Next by Date: Re: ruby server 1.9.2
- Previous by thread: Re: pipe question
- Next by thread: Re: pipe question
- Index(es):
Relevant Pages
|