[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Whitespace matters in instance_eval? I'm confused

Harold Hausman

8/6/2006 4:58:00 AM

irb(main):001:0> foo = Object.new
=> #<Object:0x2b9bb88>
irb(main):002:0> foo.instance_eval "3.times{ puts 'boom' }"
boom
boom
boom
=> 3
irb(main):003:0> foo.instance_eval "3.times{ puts 'boom' \n}"
boom
boom
boom
=> 3
irb(main):004:0> foo.instance_eval "3.times\n{ puts 'boom' \n}"
SyntaxError: (eval):3:in `irb_binding': compile error
(eval):2: syntax error
{ puts 'boom'
^
(eval):3: syntax error
from (irb):4

#is there a rule that says that the opening curly brace has to be on
the same line?

Any help appreciated,
-Harold

7 Answers

Rick DeNatale

8/6/2006 5:10:00 AM

0

On 8/6/06, Harold Hausman <hhausman@gmail.com> wrote:

> irb(main):004:0> foo.instance_eval "3.times\n{ puts 'boom' \n}"
> SyntaxError: (eval):3:in `irb_binding': compile error
> (eval):2: syntax error
> { puts 'boom'
> ^
> (eval):3: syntax error
> from (irb):4
>
> #is there a rule that says that the opening curly brace has to be on
> the same line?

I think that it pretty much falls out of the way Ruby handles lines in
source. As the pickaxe put's it Ruby is 'line-oriented'

1) An expression or statement which looks like complete by the end of
the line IS considered complete

2) Blocks are optional in method calls, so
3.times
looks like (and is a complete expression, and a complete statement)

3) a bare block is not a valid statement

It's got nothing to do with instance_eval

irb(main):001:0> 3.times
LocalJumpError: no block given
from (irb):1:in `times'
from (irb):1
irb(main):002:0> { puts "boom" }
SyntaxError: compile error
(irb):2: parse error, unexpected tSTRING_BEG, expecting kDO or '{' or '('
{ puts "boom" }
^
(irb):2: parse error, unexpected '}', expecting $
from (irb):2
irb(main):003:0>



--
Rick DeNatale

Harold Hausman

8/6/2006 5:21:00 AM

0

On 8/6/06, Rick DeNatale <rick.denatale@gmail.com> wrote:
> On 8/6/06, Harold Hausman <hhausman@gmail.com> wrote:
>
> > irb(main):004:0> foo.instance_eval "3.times\n{ puts 'boom' \n}"
> > SyntaxError: (eval):3:in `irb_binding': compile error
> > (eval):2: syntax error
> > { puts 'boom'
> > ^
> > (eval):3: syntax error
> > from (irb):4
> >
> > #is there a rule that says that the opening curly brace has to be on
> > the same line?
>
> I think that it pretty much falls out of the way Ruby handles lines in
> source. As the pickaxe put's it Ruby is 'line-oriented'
>
> 1) An expression or statement which looks like complete by the end of
> the line IS considered complete
>
> 2) Blocks are optional in method calls, so
> 3.times
> looks like (and is a complete expression, and a complete statement)
>
> 3) a bare block is not a valid statement
>
> It's got nothing to do with instance_eval
>

...

> --
> Rick DeNatale
>

Makes good sense, thank you kindly.

-Harold

Charles Hoffman

8/6/2006 3:49:00 PM

0

On Sun, 2006-08-06 at 13:58 +0900, Harold Hausman wrote:
> irb(main):001:0> foo = Object.new
> => #<Object:0x2b9bb88>
> irb(main):002:0> foo.instance_eval "3.times{ puts 'boom' }"
> boom
> boom
> boom
> => 3
> irb(main):003:0> foo.instance_eval "3.times{ puts 'boom' \n}"
> boom
> boom
> boom
> => 3
> irb(main):004:0> foo.instance_eval "3.times\n{ puts 'boom' \n}"
> SyntaxError: (eval):3:in `irb_binding': compile error
> (eval):2: syntax error
> { puts 'boom'
> ^
> (eval):3: syntax error
> from (irb):4
>
> #is there a rule that says that the opening curly brace has to be on
> the same line?
>
> Any help appreciated,
> -Harold
>

I think maybe there is. In any case, the common/recommended practice
seems to be to use do..end for multi-line blocks rather than curly
braces. And every piece of Ruby code I've seen to date puts the opening
curly brace or do on the same line as the method call the block is being
passed to.

I'm guessing that

foo.instance_eval "3.times do \n puts 'boom' \n end

would work, but

foo.instance_eval "3.times \n do \n puts 'boom' \n end

would not.

--ch--


The Highlander

1/19/2009 3:29:00 PM

0

On Jan 18, 5:05 pm, "Ben Cramer" <ben'salw...@around.com> wrote:
> "Nor" <nor...@NOTblueyonder.co.uk> wrote in message
>
> news:Q5Mcl.22121$Sp5.5768@text.news.virginmedia.com...
>
>
>
>
>
> > "Ariadne" <ariadne....@gmail.com> wrote in message
> >news:d03dc75c-854c-4fee-b502-546758ddacac@e1g2000pra.googlegroups.com...
> > On 18 Jan, 19:49, "Nor" <nor...@NOTblueyonder.co.uk> wrote:
> >> "conwaycaine" <conwayca...@bellsouth.net> wrote in message
>
> >>news:o6Kcl.5477$aO6.1320@bignews3.bellsouth.net...
>
> >> > "Ben Cramer" <ben'salw...@around.com> wrote in message
> >> >news:QtOdnWeKcYl5YO_UnZ2dnUVZ_trinZ2d@giganews.com...
> >> > You have eyes but you will not see
> >> > You have ears but you will not hear.
>
> >> There are over 200 kids who will not see or hear again, well done
> >> Israel!! -
> >> NOT
>
> >> I used to support Israel until they bombed Lebanon into the ground, and
> >> in
> >> the process killed many ordinary Lebanese people.
>
> >> If the Israelis think their actions will bring peace they are delusional.
> >> I
> >> get the impression that they love all this warfare, killing innocents.
>
> >> Gerald Haufman has gone up in my estimation for saying it as it is.
>
> >> Nor
>
> > What a total swallower of Arab terrorist BS you are.
> > Muslim or neo-Nazi?
>
> > Neither you silly wee wumman!
> > LOL at you
> > Nor
>
> She is certainly silly, but wee?  No way. She's an ancient, obese, smelly
> jewess.
>

Ben Cramer is a smelly Irish racist poof and anti-semitic troll from
Belfast, a city which needs no introduction in terms of racial and
religious hatred. He has appeared in scs on various occasions, but
usually vanishes whenever attempts are made to locate him.Like most of
the semi-deranged racists whose psychological problems are all too
visible, he spends his time baiting Jewish groups and generally making
a fool of himself and appears to support himself with the help of the
UK Welfare system.

Adam Whyte-Settlar

1/19/2009 4:25:00 PM

0



> She is certainly silly, but wee? No way. She's an ancient, obese, smelly
> jewess.
>

Ben Cramer is a smelly Irish racist poof and anti-semitic troll from
Belfast, a city which needs no introduction in terms of racial and
religious hatred. He has appeared in scs on various occasions, but
usually vanishes whenever attempts are made to locate him.Like most of
the semi-deranged racists whose psychological problems are all too
visible, he spends his time baiting Jewish groups and generally making
a fool of himself and appears to support himself with the help of the
UK Welfare system.



I take it you're officially back then?


A belated happy new year by the way.


Ben Cramer

1/20/2009 11:32:00 AM

0


"The Highlander" <micheil@shaw.ca> wrote in message
news:bd4374d7-7c3d-42c9-b370-53c2457966b1@r41g2000prr.googlegroups.com...
On Jan 18, 5:05 pm, "Ben Cramer" <ben'salw...@around.com> wrote:
> "Nor" <nor...@NOTblueyonder.co.uk> wrote in message
>
> news:Q5Mcl.22121$Sp5.5768@text.news.virginmedia.com...
>
>
>
>
>
> > "Ariadne" <ariadne....@gmail.com> wrote in message
> >news:d03dc75c-854c-4fee-b502-546758ddacac@e1g2000pra.googlegroups.com...
> > On 18 Jan, 19:49, "Nor" <nor...@NOTblueyonder.co.uk> wrote:
> >> "conwaycaine" <conwayca...@bellsouth.net> wrote in message
>
> >>news:o6Kcl.5477$aO6.1320@bignews3.bellsouth.net...
>
> >> > "Ben Cramer" <ben'salw...@around.com> wrote in message
> >> >news:QtOdnWeKcYl5YO_UnZ2dnUVZ_trinZ2d@giganews.com...
> >> > You have eyes but you will not see
> >> > You have ears but you will not hear.
>
> >> There are over 200 kids who will not see or hear again, well done
> >> Israel!! -
> >> NOT
>
> >> I used to support Israel until they bombed Lebanon into the ground, and
> >> in
> >> the process killed many ordinary Lebanese people.
>
> >> If the Israelis think their actions will bring peace they are
> >> delusional.
> >> I
> >> get the impression that they love all this warfare, killing innocents.
>
> >> Gerald Haufman has gone up in my estimation for saying it as it is.
>
> >> Nor
>
> > What a total swallower of Arab terrorist BS you are.
> > Muslim or neo-Nazi?
>
> > Neither you silly wee wumman!
> > LOL at you
> > Nor
>
> She is certainly silly, but wee? No way. She's an ancient, obese, smelly
> jewess.
>

>Ben Cramer is a smelly Irish racist poof and anti-semitic troll from
>Belfast,

Seven claims, all of which are wrong, ya wee faggot.




Ben Cramer

1/20/2009 11:34:00 AM

0


"Adam Whyte-Settlar" <ador@ble> wrote in message
news:AoudnWoLwJukLenUnZ2dnUVZ8tHinZ2d@westnet.com.au...
>
>
>> She is certainly silly, but wee? No way. She's an ancient, obese, smelly
>> jewess.
>>
>
> Ben Cramer is a smelly Irish racist poof and anti-semitic troll from
> Belfast,
>
>
> I take it you're officially back then?

The wee faggot is officially certifiable.

He makes seven claims in the tripe above, (the rest snipped to save him
further embarrassment) which are all incorrect.