Puzzeling little inconsistency

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/


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

Robert D. wrote:

% “Hi”

Try this

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

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

Guy Decoux

On Thu, Apr 24, 2008 at 11:38 AM, Robert D. [email protected]
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

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


http://ruby-smalltalk.blogspot.com/


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

On Thu, Apr 24, 2008 at 12:06 PM, Calamitas [email protected]
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.

On Thu, Apr 24, 2008 at 12:02 PM, ts [email protected] 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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs