* 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}" })

Where c.attributes is a hash.

Thanks,
T.

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.

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.

···

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.

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}" }

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

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

Thanks,
T.

···

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}" }