# Puzzeling little inconsistency

**URL:** <https://www.ruby-forum.com/t/puzzeling-little-inconsistency/135707>\
**Category:** Ruby\
**Created:** [April 24, 2008, 11:39am UTC](https://www.ruby-forum.com/t/puzzeling-little-inconsistency/135707 "2008-04-24T11:39:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![flatekmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e8c25b/32.png) [@flatekmonkey](https://www.ruby-forum.com/u/flatekmonkey)\
**Post date:** [April 24, 2008, 11:39am UTC](https://www.ruby-forum.com/t/puzzeling-little-inconsistency/135707/1 "2008-04-24T11:39:13Z")

</div>

I just stumbled upon this, not sure what is going on here. BTW Ruby,  
Ruby1.9 and JRuby behave all the like.

546/46 \> cat syntax.rb && echo “—\>” && ruby syntax.rb  
module M  
def % z  
puts z  
end  
extend self  
self % “Top” # Line Fourty Two  
end

extend M  
% “Hi”  
send “%”, “Low”  
o = Object.new.extend M  
o % “Bottom”  
—\>  
Top  
Low  
Bottom

* * *

Additionally if you remove self from line Fourty Two, you get a synatx  
error.

## syntax.rb:9: syntax error, unexpected tCONSTANT, expecting kEND syntax.rb:13: syntax error, unexpected $end, expecting kEND

I am quite puzzled, any explanations?

Cheers  
Robert

–  
[http://ruby-smalltalk.blogspot.com/](http://ruby-smalltalk.blogspot.com/)

* * *

Whereof one cannot speak, thereof one must be silent.  
Ludwig Wittgenstein

---

<div class="post-metadata">

**Author:** ![flatekmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e8c25b/32.png) [@flatekmonkey](https://www.ruby-forum.com/u/flatekmonkey)\
**Post date:** [April 24, 2008, 12:03pm UTC](https://www.ruby-forum.com/t/puzzeling-little-inconsistency/135707/2 "2008-04-24T12:03:56Z")

</div>

Robert D. wrote:

> % “Hi”

Try this

vgs% ruby -e ‘p(% Hi )’  
“Hi”  
vgs%

vgs% echo “p(% ‘Hi’\nsend )” | ruby  
“‘Hi’\nsend”  
vgs%

Guy Decoux

---

<div class="post-metadata">

**Author:** ![flatekmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e8c25b/32.png) [@flatekmonkey](https://www.ruby-forum.com/u/flatekmonkey)\
**Post date:** [April 24, 2008, 12:07pm UTC](https://www.ruby-forum.com/t/puzzeling-little-inconsistency/135707/3 "2008-04-24T12:07:28Z")

</div>

On Thu, Apr 24, 2008 at 11:38 AM, Robert D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> end
> 
> * * *
> 
> Additionally if you remove self from line Fourty Two, you get a synatx error.
> 
> ## syntax.rb:9: syntax error, unexpected tCONSTANT, expecting kEND syntax.rb:13: syntax error, unexpected $end, expecting kEND
> 
> I am quite puzzled, any explanations?

I’m seeing the same behavior as you are, provided that I remove the  
comment and add a space after “Hi”.

The expressions starting with % are interpreted as string literals.  
Because the following character is a space, it is used as a delimiter.  
It is an unusual delimiter, but Ruby allows it.

Peter

---

<div class="post-metadata">

**Author:** ![flatekmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e8c25b/32.png) [@flatekmonkey](https://www.ruby-forum.com/u/flatekmonkey)\
**Post date:** [April 24, 2008, 12:12pm UTC](https://www.ruby-forum.com/t/puzzeling-little-inconsistency/135707/4 "2008-04-24T12:12:13Z")

</div>

> 

Guy you did not redefine % as I did, of course it still behaves like  
the built in.  
Robert

–  
[http://ruby-smalltalk.blogspot.com/](http://ruby-smalltalk.blogspot.com/)

* * *

Whereof one cannot speak, thereof one must be silent.  
Ludwig Wittgenstein

---

<div class="post-metadata">

**Author:** ![flatekmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e8c25b/32.png) [@flatekmonkey](https://www.ruby-forum.com/u/flatekmonkey)\
**Post date:** [April 24, 2008, 12:15pm UTC](https://www.ruby-forum.com/t/puzzeling-little-inconsistency/135707/5 "2008-04-24T12:15:11Z")

</div>

On Thu, Apr 24, 2008 at 12:06 PM, Calamitas [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I’m seeing the same behavior as you are, provided that I remove the  
> comment and add a space after “Hi”.
> 
> The expressions starting with % are interpreted as string literals.  
> Because the following character is a space, it is used as a delimiter.  
> It is an unusual delimiter, but Ruby allows it  
> Oh thanx Peter, I just had the idea to use parse tree the next time  
> before asking stupid questions ;).  
> Side remark to Guy, I know what you meant with your examples now, but  
> I believe that your examples were consistent with % being a method I  
> did therefore not understand.  
> R.

---

<div class="post-metadata">

**Author:** ![flatekmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e8c25b/32.png) [@flatekmonkey](https://www.ruby-forum.com/u/flatekmonkey)\
**Post date:** [April 24, 2008, 12:19pm UTC](https://www.ruby-forum.com/t/puzzeling-little-inconsistency/135707/6 "2008-04-24T12:19:18Z")

</div>

On Thu, Apr 24, 2008 at 12:02 PM, ts [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> vgs% ruby -e ‘p(% Hi )’  
> Ok I see it _now_ sorry my brain just put the quotes which were not  
> there.

Tu purrais être un petit peu plus clair pour les personnes agées, LOL.  
Merci quand même.

R.
