Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #2286

Re: pipe question

From 7stud -- <bbxx789_05ss@yahoo.com>
Newsgroups comp.lang.ruby
Subject Re: pipe question
Date Mon, 4 Apr 2011 19:12:07 -0500
Organization Service de news de lacave.net
Lines 35
Message-ID <b6f24ad6461fa5fa75f8c1fe78d9f727@ruby-forum.com> (permalink)
References <6351ecc5d2ac52f4b4c9d06ad2930f2c@ruby-forum.com> <BANLkTimcgE-BpQ22=knOoRM_78KfFD2-rQ@mail.gmail.com>
NNTP-Posting-Host bristol.highgroove.com
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-Trace talisker.lacave.net 1301962350 49603 65.111.164.187 (5 Apr 2011 00:12:30 GMT)
X-Complaints-To abuse@lacave.net
NNTP-Posting-Date Tue, 5 Apr 2011 00:12:30 +0000 (UTC)
In-Reply-To <BANLkTimcgE-BpQ22=knOoRM_78KfFD2-rQ@mail.gmail.com>
X-Received-From This message has been automatically forwarded from the ruby-talk mailing list by a gateway at comp.lang.ruby. If it is SPAM, it did not originate at comp.lang.ruby. Please report the original sender, and not us. Thanks! For more details about this gateway, please visit: http://blog.grayproductions.net/categories/the_gateway
X-Mail-Count 380947
X-Ml-Name ruby-talk
X-Rubymirror Yes
X-Ruby-Talk <b6f24ad6461fa5fa75f8c1fe78d9f727@ruby-forum.com>
Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.stben.net!talisker.lacave.net!lacave.net!not-for-mail
Xref x330-a1.tempe.blueboxinc.net comp.lang.ruby:2286

Show key headers only | View raw


Josh Cheek wrote in post #990762:
>
> 3) For some reason that I don't know (probably interpreter magic) an
> uninitialized variable can be referenced in a boolean equation and it
> will
> evaluate to nil.
>
> first_name = first_name || "" # => ""
> first_name = "josh"
> first_name = first_name || "" # => "josh"
>
>
> So, it will set the variable to the empty string, if the variable is
> undeclared, or false , or nil.

I think the story goes something like this:  when the parser sees any 
'name =' expression, name gets entered into the symbol table. 
Thereafter, you will no longer get an exception when referencing the 
variable.  In your code, the parser sees 'first_name =', so first_name 
is entered into the symbol table, and then when ruby executes your code, 
the expression on the right hand side of the equals sign is executed.

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)

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

Back to comp.lang.ruby | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

pipe question wolf volpi <wolf_volpi@yahoo.com> - 2011-04-03 21:58 -0500
  Re: pipe question John Feminella <johnf@bitsbuilder.com> - 2011-04-03 22:08 -0500
    Re: pipe question Robert Klemme <shortcutter@googlemail.com> - 2011-04-04 02:36 -0500
  Re: pipe question Josh Cheek <josh.cheek@gmail.com> - 2011-04-03 22:42 -0500
    Re: pipe question Josh Cheek <josh.cheek@gmail.com> - 2011-04-04 04:58 -0500
      Re: pipe question Brian Candler <b.candler@pobox.com> - 2011-04-05 04:01 -0500
    Re: pipe question 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-04 19:12 -0500
      Re: pipe question Josh Cheek <josh.cheek@gmail.com> - 2011-04-04 22:30 -0500
        Re: pipe question Robert Klemme <shortcutter@googlemail.com> - 2011-04-05 10:27 -0500
        Re: pipe question 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-05 21:06 -0500
        Re: pipe question Jesús Gabriel y Galán <jgabrielygalan@gmail.com> - 2011-04-06 02:00 -0500
      Re: pipe question Josh Cheek <josh.cheek@gmail.com> - 2011-04-05 21:23 -0500
  Re: pipe question wolf volpi <wolf_volpi@yahoo.com> - 2011-04-03 23:55 -0500

csiph-web