Syntax error, unexpected ',' , expecting ')'

Hello people, i am new at ruby and ror developing and i need your help
with this:

i got this code

class Trabajo

  def saludar(nombre)

    puts "Hola #{nombre}"
    yield (("Fulano,32", "lol"))

  end

end

class Trabajo2 < Trabajo

end

tr=Trabajo2.new
tr.saludar("David"){ |nombre2, edad| puts "algo raro #{nombre2}, tu edad
es: #{edad}" }

ok, it is easy but i always got the same error: syntax error, unexpected
',' , expecting ')' could some of you help me, i think the code it's
ok.

I would be glad for your help..

···

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

use:

yield ["Fulano,32", "lol"]

yield wants only one object

···

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

its the " " ...

    yield("Fulano,32", "lol") # works

    yield ("Fulano,32", "lol") # works not

···

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

Hi,

David Acosta wrote in post #1060379:

Hello people, i am new at ruby and ror developing and i need your help
with this:

i got this code

class Trabajo

  def saludar(nombre)

    puts "Hola #{nombre}"
    yield (("Fulano,32", "lol"))

  end

[...]

ok, it is easy but i always got the same error: syntax error, unexpected
',' , expecting ')' could some of you help me, i think the code it's
ok.

I would be glad for your help..

The expression (("Fulano,32", "lol")) isn't valid Ruby. What did you
want to do?

If you wanted to put the block arguments in paranthesis, you need
*single* paranthesis directly after the "yield" (without any space):

yield("Fulano,32", "lol")

But you can actually leave out the paranthesis.

···

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

Hans Mackowiak wrote in post #1060382:

use:

yield ["Fulano,32", "lol"]

yield wants only one object

OMG, it was so easy, thank you very much

···

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

but why these codes work?

def a_method(a, b)
  a + yield(a, b)
end

a_method(1, 2) { |a, b| (a + b) * 3 }

···

On Fri, May 11, 2012 at 2:37 PM, Hans Mackowiak <lists@ruby-forum.com>wrote:

use:

yield ["Fulano,32", "lol"]

yield wants only one object

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

--
Best Regards,

*Larry Lv
*

Sorry but this is plain wrong.

irb(main):001:0> def f; yield 1; yield 11,22; yield 111,222,333; end
=> nil
irb(main):002:0> f {|*a| p a}
[1]
[11, 22]
[111, 222, 333]
=> [111, 222, 333]
irb(main):003:0> f {|a| p a}
1
11
111
=> 111
irb(main):004:0> f {|a,b,c| printf "a=%p b=%p c=%p\n", a, b, c}
a=1 b=nil c=nil
a=11 b=22 c=nil
a=111 b=222 c=333
=> nil

yield is like a method call (apart from the block you cannot pass).

Kind regards

robert

···

On Fri, May 11, 2012 at 8:37 AM, Hans Mackowiak <lists@ruby-forum.com> wrote:

use:

yield ["Fulano,32", "lol"]

yield wants only one object

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/