* usage

  • Thread starter trans. (T. Onoma)
  • Start date
T

trans. (T. Onoma)

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.
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: * usage"

|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

trans. (T. Onoma)

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.
 
M

Michael Neumann

trans. (T. Onoma) said:
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
 
F

Florian Gross

trans. (T. Onoma) said:
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

trans. (T. Onoma)

| > 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,163
Messages
2,570,897
Members
47,434
Latest member
TobiasLoan

Latest Threads

Top