Puzzeling little inconsistency

R

Robert Dober

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
 
C

Calamitas

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'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
 
R

Robert Dober

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

Robert Dober

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.
 
R

Robert Dober

vgs% ruby -e 'p(% Hi )'
Ok I see it *now* sorry my brain just put the quotes which were not there.

Tu purrais =EAtre un petit peu plus clair pour les personnes ag=E9es, LOL.
Merci quand m=EAme.

R.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,217
Latest member
IRMNikole

Latest Threads

Top