Ruby syntax question

24 views
Skip to first unread message

Aaron

unread,
Jan 20, 2014, 12:57:47 PM1/20/14
to atlrug-em...@googlegroups.com
Was playing around with Ruby. I got this program to run.

def call_block
   yield 'hello', 99
end

call_block {|strVar, numVar| puts strVar+numVar.to_s}

The output is:  hello99

However when I use the below syntax for the yield line, it fails with an "unexpected end of input" error

yield ('hello', 99)

Naturally, a search will show many examples where yield is used with parens. Since yield is a method, I

should be able to call it with parameters using parens or not using parens. Why is the second version failing?

Vineel Sonnathi

unread,
Jan 20, 2014, 1:07:50 PM1/20/14
to atlrug-em...@googlegroups.com
This yield ('hello', 99) should be yield('hello', 99) . No spaces before braces.

Warm Regards,
Vineel Sonnathi



--
You received this message because you are subscribed to the Google Groups "Emerald City" group.
To unsubscribe from this group and stop receiving emails from it, send an email to atlrug-emeraldc...@googlegroups.com.
To post to this group, send email to atlrug-em...@googlegroups.com.
Visit this group at http://groups.google.com/group/atlrug-emeraldcity.
For more options, visit https://groups.google.com/groups/opt_out.

Jason Noble

unread,
Jan 20, 2014, 1:18:33 PM1/20/14
to Emerald City

s/braces/parenthesis/ :)

From Matz: http://www.justskins.com/forums/ruby-1-8-space-122361.html

Jason
Reply all
Reply to author
Forward
0 new messages