%w(foo) v.s. ['foo']

rubyists-

any idea why this:

year, month, day = [‘year’,‘month’,‘day’].map{|k| cgi[k]}

should yeild different results than this:

year, month, day = %w(year month day).map{|k| cgi[k]}

this first case, with identical form data, results in expected behavior, the
second results in all values being nil.

-a

···

Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ara.t.howard@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================

  • year, month, day = %w(year month day).map{|k| cgi[k]}
  • year, month, day = %w{year month day}.map{|k| cgi[k]}
···

On Wed, May 07, 2003 at 01:06:54AM +0900, ahoward wrote:

rubyists-

any idea why this:

year, month, day = [‘year’,‘month’,‘day’].map{|k| cgi[k]}

should yeild different results than this:

year, month, day = %w(year month day).map{|k| cgi[k]}

this first case, with identical form data, results in expected behavior, the
second results in all values being nil.

-a

Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ara.t.howard@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================


Daniel Carrera
Graduate Teaching Assistant. Math Dept.
University of Maryland. (301) 405-5137

Hi,

···

In message “%w(foo) v.s. [‘foo’]” on 03/05/07, ahoward ahoward@fsl.noaa.gov writes:

any idea why this:

year, month, day = [‘year’,‘month’,‘day’].map{|k| cgi[k]}

should yeild different results than this:

year, month, day = %w(year month day).map{|k| cgi[k]}

No idea. Could you show us problem reproducing code snippet?

						matz.

%w{year month day} and %w(year month day) are the same thing, you can use
even %w%year month day% if you want.

Gennady.

···

----- Original Message -----
From: “Daniel Carrera” dcarrera@math.umd.edu
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Tuesday, May 06, 2003 9:21 AM
Subject: Re: %w(foo) v.s. [‘foo’]

  • year, month, day = %w(year month day).map{|k| cgi[k]}
  • year, month, day = %w{year month day}.map{|k| cgi[k]}

On Wed, May 07, 2003 at 01:06:54AM +0900, ahoward wrote:

rubyists-

any idea why this:

year, month, day = [‘year’,‘month’,‘day’].map{|k| cgi[k]}

should yeild different results than this:

year, month, day = %w(year month day).map{|k| cgi[k]}

this first case, with identical form data, results in expected behavior,
the
second results in all values being nil.

-a

Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ara.t.howard@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================


Daniel Carrera
Graduate Teaching Assistant. Math Dept.
University of Maryland. (301) 405-5137

this is the offending script - i’m sure the problem must be elsewhere, i just
can’t see it

http://eli.fsl.noaa.gov/ruby/eg/index_cgi.html

line 45, 46

-a

···

On Wed, 7 May 2003, Yukihiro Matsumoto wrote:

Hi,

In message “%w(foo) v.s. [‘foo’]” > on 03/05/07, ahoward ahoward@fsl.noaa.gov writes:

any idea why this:

year, month, day = [‘year’,‘month’,‘day’].map{|k| cgi[k]}

should yeild different results than this:

year, month, day = %w(year month day).map{|k| cgi[k]}

No idea. Could you show us problem reproducing code snippet?

Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ara.t.howard@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================

%w{year month day} and %w(year month day) are the same thing, you can use
even %w%year month day% if you want.

Gennady.

I didn’t know that. Ruby rocks.

But in that case, I can’t imagine what the problem with this code could
be.

···

On Wed, May 07, 2003 at 01:32:58AM +0900, Gennady wrote:

any idea why this:

year, month, day = [‘year’,‘month’,‘day’].map{|k| cgi[k]}

should yeild different results than this:

year, month, day = %w(year month day).map{|k| cgi[k]}


Daniel Carrera
Graduate Teaching Assistant. Math Dept.
University of Maryland. (301) 405-5137

Your script has “%(year month day)” instead of “%w(year month day)”. I
presume ‘w’ was somehow swallowed when rendering to html, and it IS actually
present in the script you test. Is it?

Gennady.

···

----- Original Message -----
From: “ahoward” ahoward@fsl.noaa.gov
Newsgroups: comp.lang.ruby
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Tuesday, May 06, 2003 11:49 AM
Subject: Re: %w(foo) v.s. [‘foo’]

On Wed, 7 May 2003, Yukihiro Matsumoto wrote:

Hi,

In message “%w(foo) v.s. [‘foo’]” > > on 03/05/07, ahoward ahoward@fsl.noaa.gov writes:

any idea why this:

year, month, day = [‘year’,‘month’,‘day’].map{|k| cgi[k]}

should yeild different results than this:

year, month, day = %w(year month day).map{|k| cgi[k]}

No idea. Could you show us problem reproducing code snippet?

this is the offending script - i’m sure the problem must be elsewhere, i
just
can’t see it

http://eli.fsl.noaa.gov/ruby/eg/index_cgi.html

line 45, 46

-a

Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ara.t.howard@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================

By the way, I just verified in IRB that %(year month day) is actually “year
month day”. It is quite surprising to me.

Gennady.

···

----- Original Message -----
From: “ahoward” ahoward@fsl.noaa.gov
Newsgroups: comp.lang.ruby
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Tuesday, May 06, 2003 11:49 AM
Subject: Re: %w(foo) v.s. [‘foo’]

On Wed, 7 May 2003, Yukihiro Matsumoto wrote:

Hi,

In message “%w(foo) v.s. [‘foo’]” > > on 03/05/07, ahoward ahoward@fsl.noaa.gov writes:

any idea why this:

year, month, day = [‘year’,‘month’,‘day’].map{|k| cgi[k]}

should yeild different results than this:

year, month, day = %w(year month day).map{|k| cgi[k]}

No idea. Could you show us problem reproducing code snippet?

this is the offending script - i’m sure the problem must be elsewhere, i
just
can’t see it

http://eli.fsl.noaa.gov/ruby/eg/index_cgi.html

line 45, 46

-a

Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ara.t.howard@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================

I can’t imagine either. It must be the same.

ahoward, are you testing these 2 constructs in exactly same spot in the
code, or they are in different places? Is there a chance that something else
breaks in? Are you absolutely sure that the input is exactly the same in
both cases? What happens if you mock cgi and provide known values before the
statement?

Gennady.

···

----- Original Message -----
From: “Daniel Carrera” dcarrera@math.umd.edu
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Tuesday, May 06, 2003 9:35 AM
Subject: Re: %w(foo) v.s. [‘foo’]

On Wed, May 07, 2003 at 01:32:58AM +0900, Gennady wrote:

%w{year month day} and %w(year month day) are the same thing, you can
use
even %w%year month day% if you want.

Gennady.

I didn’t know that. Ruby rocks.

But in that case, I can’t imagine what the problem with this code could
be.

any idea why this:

year, month, day = [‘year’,‘month’,‘day’].map{|k| cgi[k]}

should yeild different results than this:

year, month, day = %w(year month day).map{|k| cgi[k]}


Daniel Carrera
Graduate Teaching Assistant. Math Dept.
University of Maryland. (301) 405-5137

By the way, I just verified in IRB that %(year month day) is actually
“year
month day”. It is quite surprising to me.

A pleasant surprise, right?

This is Ruby’s generalized string. You
can say things like:

%(He said, “She told me, ‘Hello.’”)

instead of escaping the usual quote characters.
In fact, the parens are not even required.
And I think if you use a non-doubled character
like -, you can open and close with the same
character:

%-He said, “She told me, ‘Hello.’”-

I’m saying this from memory. I’ll
be embarrassed if I am wrong. :slight_smile:

Hal

···

----- Original Message -----
From: “Gennady” gfb@tonesoft.com
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Tuesday, May 06, 2003 2:03 PM
Subject: Re: %w(foo) v.s. [‘foo’]

Hi –

···

On Wed, 7 May 2003, Gennady wrote:

By the way, I just verified in IRB that %(year month day) is actually “year
month day”. It is quite surprising to me.

That’s gotten quite a lot of play lately; you must have taken a
vacation during the “can you guess?” thread :slight_smile:
(http://www.ruby-talk.org/70204)

David


David Alan Black
home: dblack@superlink.net
work: blackdav@shu.edu
Web: http://pirate.shu.edu/~blackdav