[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

T. Onoma

12/3/2004 6:31:00 AM

I've come across this a few times now and don't understand why its a syntax
error:

@f << *(c.attributes.collect{ |k,v| "#{k}=#{v}" })

Where c.attributes is a hash.

Thanks,
T.


5 Answers

Yukihiro Matsumoto

12/3/2004 6:44:00 AM

0

Hi,

In message "Re: * usage"
on Fri, 3 Dec 2004 15:30:30 +0900, "trans. (T. Onoma)" <transami@runbox.com> writes:

|I've come across this a few times now and don't understand why its a syntax
|error:
|
| @f << *(c.attributes.collect{ |k,v| "#{k}=#{v}" })

Because operators only take fixed number of arguments. If you want to
add an array, try

@f << [*(c.attributes.collect{ |k,v| "#{k}=#{v}" })]

which is legal.

matz.


T. Onoma

12/3/2004 6:45:00 AM

0

On Friday 03 December 2004 01:30 am, trans. (T. Onoma) wrote:
| I've come across this a few times now and don't understand why its a syntax
| error:
|
| @f << *(c.attributes.collect{ |k,v| "#{k}=#{v}" })
|
| Where c.attributes is a hash.

Sorry, that could be clearer since << doesn't take multiple arguments (too bad
for that!) Try simpler:

@f = []
c = [1]
@f << *c

or

@f = []
@f << *[1]

T.



Michael Neumann

12/3/2004 10:51:00 AM

0

trans. (T. Onoma) wrote:
> On Friday 03 December 2004 01:30 am, trans. (T. Onoma) wrote:
> | I've come across this a few times now and don't understand why its a syntax
> | error:
> |
> | @f << *(c.attributes.collect{ |k,v| "#{k}=#{v}" })
> |
> | Where c.attributes is a hash.
>
> Sorry, that could be clearer since << doesn't take multiple arguments (too bad
> for that!) Try simpler:

how about

@f.<<(*c.attributes......)

Regards,

Michael


Florian Gross

12/3/2004 7:55:00 PM

0

trans. (T. Onoma) wrote:

> I've come across this a few times now and don't understand why its a syntax
> error:
>
> @f << *(c.attributes.collect{ |k,v| "#{k}=#{v}" })

Are you sure you don't want to do this?

@f.push(*c.attributes.collect{ |k,v| "#{k}=#{v}" })

Or even:

@f += c.attributes.collect{ |k,v| "#{k}=#{v}" }

T. Onoma

12/3/2004 11:58:00 PM

0

On Friday 03 December 2004 02:57 pm, Florian Gross wrote:
| trans. (T. Onoma) wrote:
| > I've come across this a few times now and don't understand why its a
| > syntax error:
| >
| > @f << *(c.attributes.collect{ |k,v| "#{k}=#{v}" })
|
| Are you sure you don't want to do this?
|
| @f.push(*c.attributes.collect{ |k,v| "#{k}=#{v}" })
|
| Or even:
|
| @f += c.attributes.collect{ |k,v| "#{k}=#{v}" }

I'm sure I would ;) I was just pointing out that the other throws a syntax
error --even if it contains only one element.

Thanks,
T.