Possible parsing weirdness

4 views
Skip to first unread message

DGerton

unread,
Jun 30, 2009, 2:52:00 PM6/30/09
to Ruby on Rails: Core
I'm using rails 2.3.2 on MacOSX. This line throws an error:
logger.info 'request is an email (' + email.to_s +')'

However, this line does not:
logger.info 'request is an email (' + email.to_s + ')'

Notice the space in ...to_s + ')' The error is "syntax error,
unexpected tUPLUS, expecting '}'." Putting in the curly braces doesn't
help. As in...
logger.info { 'request is an email (' + email.to_s +')' }

In the words of Goldmember, "Izant zat zweirds?"

Am I missing something or should I file a bug, and, if so, where?

mynyml

unread,
Jun 30, 2009, 3:14:35 PM6/30/09
to Ruby on Rails: Core
In the spaceless version, it seems the + is being interpreted as a
unary plus (tUPLUS), the result of which will be passed as argument to
#to_s

With a simplified statement:

>> ''.to_s +''
NoMethodError: undefined method `+@' for "":String
>> ''.to_s + ''
=> ""
>> ''.to_s() +''
=> ""

This is strictly Ruby behaviour though, not a Rails concern.

mynyml

Rick DeNatale

unread,
Jun 30, 2009, 3:56:02 PM6/30/09
to rubyonra...@googlegroups.com
On Tue, Jun 30, 2009 at 3:14 PM, mynyml<martin...@gmail.com> wrote:
>
> In the spaceless version, it seems the + is being interpreted as a
> unary plus (tUPLUS), the result of which will be passed as argument to
> #to_s
>
> With a simplified statement:
>
>>> ''.to_s +''
> NoMethodError: undefined method `+@' for "":String
>>> ''.to_s + ''
> => ""
>>> ''.to_s() +''
> => ""
>
> This is strictly Ruby behaviour though, not a Rails concern.

And by the way, most rubyists would write this:

logger.info 'request is an email (' + email.to_s + ')'

using string interpolation:

logger.info "request is an email (#{email})"


--
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale

Reply all
Reply to author
Forward
0 new messages