[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Puzzeling little inconsistency

Robert Dober

4/24/2008 9:39:00 AM

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

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

5 Answers

ts

4/24/2008 10:02:00 AM

0

Robert Dober wrote:
> % "Hi"

Try this

vgs% ruby -e 'p(% Hi )'
"Hi"
vgs%

vgs% echo "p(% 'Hi'\nsend )" | ruby
"'Hi'\nsend"
vgs%


Guy Decoux

Calamitas

4/24/2008 10:07:00 AM

0

On Thu, Apr 24, 2008 at 11:38 AM, Robert Dober <robert.dober@gmail.com> wrote:
> 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?

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

Robert Dober

4/24/2008 10:12:00 AM

0

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



--
http://ruby-smalltalk.blo...

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

Robert Dober

4/24/2008 10:15:00 AM

0

On Thu, Apr 24, 2008 at 12:06 PM, Calamitas <calamitates@gmail.com> 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.

Robert Dober

4/24/2008 10:18:00 AM

0

On Thu, Apr 24, 2008 at 12:02 PM, ts <decoux@moulon.inra.fr> wrote:
> 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.