Tuesday, October 14, 2008

Tuesday morning Ruby quiz

Last night, myself and the local Ruby group started down the path of preparation for the Ruby certification exam (after being inspired by Fabio Kung to go for it). One of the things we covered was here docs, a facility for creating multi-line strings in Ruby. We came across two funky cases (or at least I thought they were funky) that seemed good enough for quiz questions. Given the following here docs, what would you expect to print for the values of v1 & v2:

1 comment:

Weiqi Gao said...

v1 would contain "HAYNOW", and v2 would contain "#{A + B}".

The "<<Foo" vs. "<<'Foo'" distinction is present in Bash. The single quoted version disables interpolations in the string.

I'm guessing that the ".upcase" is a method call that applies to the resulting string.