From: Robert Klemme Date: 2007-06-04T23:50:30+09:00 Subject: Re: Introducing the "it" keyword On 04.06.2007 16:29, Eleanor McHugh wrote: > On 3 Jun 2007, at 20:45, Robert Klemme wrote: >> On 03.06.2007 19:34, Eleanor McHugh wrote: >>> I tend to agree, although that's because I'd really like Ruby to have >>> the 'with' syntactic sugar that VB has. I also much prefer the idea >>> of being able to choose my own block variable name rather than being >>> stuck with 'it' which to my eye is an ungainly word. It still bothers >>> me though that a formulation that's intended to make for a simple >>> atomic statement would now cover three lines onscreen... >> >> I believe Ruby does not have "with" because there is instance_eval - >> it's more to type but can be easily aliased and has the same effect - >> rebinding "self". (I know that some talk about another "with", that >> rebinds arbitrary variable names. But I believe the original idea of >> "with" was, that you could invoke methods without explicit receiver). > > It's not entirely clear to me that 'instance_eval' would obey the same > scoping rules as 'with' in VB by dint of introducing a block. I'm not too familiar with VB (I'm kinda happy that I could stay away from it.) so I cannot really comment on the scoping question. > I also > just happen to prefer the syntactic form in the same way that there are > people who routinely use 'for' statements in their Ruby code. Tastes, tastes... Well, you can of course have your "with": module Kernel private def with(obj, &b) obj.instance_eval(&b) end end with "foo" do puts length end # same as "foo".instance_eval do puts length end :-) Kind regards robert PS: Thanks for teaching me another British(?) English idiom - hadn't known "by dint of" so far. :-)