# Why does this comment create a compile error

**URL:** <https://www.ruby-forum.com/t/why-does-this-comment-create-a-compile-error/168714>\
**Category:** Rails\
**Created:** [May 24, 2009, 9:31pm UTC](https://www.ruby-forum.com/t/why-does-this-comment-create-a-compile-error/168714 "2009-05-24T21:31:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![winterheat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7993a0/32.png) [@winterheat](https://www.ruby-forum.com/u/winterheat)\
**Post date:** [May 24, 2009, 9:31pm UTC](https://www.ruby-forum.com/t/why-does-this-comment-create-a-compile-error/168714/1 "2009-05-24T21:31:25Z")

</div>

there is a line displayed within

```
\<%= h @stories.inspect %\>

and the output was too long, so i changed it to

\<%= #h @stories.inspect %\>

\<% @stories.each do |s| %\>  
\<%= h s.inspect %\>  
\<% end %\>

(commenting out the first line). now the code will fail to compile…  
saying

compile error  
/Users/winterheat/ror/shov2/app/views/stories/index.html.erb:13: syntax  
error, unexpected kENSURE, expecting ‘)’  
/Users/winterheat/ror/shov2/app/views/stories/index.html.erb:15: syntax  
error, unexpected kEND, expecting ‘)’

and if i remove that commented line altogether, the code will work. i  
thought in some book, it is said that you can comment out some code in  
ERB like that?

Update: funny if i change it to

\<% #h @stories.inspect %\>

then it will compile fine… so the displaying of result tag \<%= %\>  
doesn’t like comments, it seems.
```

---

<div class="post-metadata">

**Author:** ![winterheat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7993a0/32.png) [@winterheat](https://www.ruby-forum.com/u/winterheat)\
**Post date:** [May 24, 2009, 10:19pm UTC](https://www.ruby-forum.com/t/why-does-this-comment-create-a-compile-error/168714/2 "2009-05-24T22:19:42Z")

</div>

I believe that a comment in erb has to start \<%#  
Other similar sequences have worked in some versions, or may sometimes  
work  
but are not guaranteed.

Colin

2009/5/24 SpringFlowers AutumnMoon [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![winterheat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7993a0/32.png) [@winterheat](https://www.ruby-forum.com/u/winterheat)\
**Post date:** [May 28, 2009, 5:13am UTC](https://www.ruby-forum.com/t/why-does-this-comment-create-a-compile-error/168714/3 "2009-05-28T05:13:36Z")

</div>

I’ve run into the same problem several times before and never thought  
too much of it, just made the correct change to be able to compile and  
kept going. Now that I think about it I might have an answer.

The ruby code is just what it is between \<% and %\>. Those ‘delimiters’  
are just to tell the engine something like ‘ruby code coming’. The =  
sign is probably actually a method call equivalent to ‘puts’ (I might  
have read that somewhere in the AWDWR book). The rest of the line is  
the parameter to the method. By putting the # sign after the = sign we  
are actually commenting out the parameter to the method but leaving  
the method call in place. The interpreter might not know what to do  
with a method call with no parameter (maybe a parameter is mandatory  
for the = sign method?) and burps. However if you put the # sign in  
front of the method call (the = sign) you are commenting the whole  
ruby code, hence the interpreter has no problem with it.

This is just a guess about what might be going on and if anybody knows  
the right answer out there I would like to know.

Pepe

On May 24, 3:31 pm, SpringFlowers AutumnMoon \<rails-mailing-

---

<div class="post-metadata">

**Author:** ![winterheat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7993a0/32.png) [@winterheat](https://www.ruby-forum.com/u/winterheat)\
**Post date:** [May 28, 2009, 5:54am UTC](https://www.ruby-forum.com/t/why-does-this-comment-create-a-compile-error/168714/4 "2009-05-28T05:54:20Z")

</div>

pepe wrote:

> I’ve run into the same problem several times before and never thought  
> too much of it, just made the correct change to be able to compile and  
> kept going. Now that I think about it I might have an answer.
> 
> The ruby code is just what it is between \<% and %\>. Those ‘delimiters’  
> are just to tell the engine something like ‘ruby code coming’. The =  
> sign is probably actually a method call equivalent to ‘puts’ (I might  
> have read that somewhere in the AWDWR book). The rest of the line is  
> the parameter to the method. By putting the # sign after the = sign we  
> are actually commenting out the parameter to the method but leaving  
> the method call in place. The interpreter might not know what to do  
> with a method call with no parameter (maybe a parameter is mandatory  
> for the = sign method?) and burps. However if you put the # sign in  
> front of the method call (the = sign) you are commenting the whole  
> ruby code, hence the interpreter has no problem with it.

yeah i am suspecting it is either:

\<%= whatever %\>

changed to \<% concat(whatever) %\>  
or changed to \<% output\_buffer \<\< whatever %\>

so if it is

\<%= #comment %\>

it becomes

\<% concat( #comment ) %\>

or

\<% output\_buffer \<\< #comment %\>

the first one fails because it comments out the “)” as well. the second  
one fails because it is missing something for the “\<\<” operator.
