Having a block executed in the context of an instance

Hi --

···

On Thu, 9 Mar 2006, itsme213 wrote:

<dblack@wobblini.net> wrote

You can look at it the other way around, though: you *always* specify
a receiver explicitly in Ruby, except in the one case where the
receiver is self and the syntax is such as to be unambiguously a
method call.

Not quite. I believe
   self.foo
does completely different privacy checks than just
   foo

Specifically,
   self.foo
on a private foo will fail, while
   self.foo=
on private foo= will succeed.

I don't think that's an exception to what I said, though. A call to a
private (non-=) method falls into the category I'm describing: the
receiver is self, and the syntax is such as to be unambiguously a
method call.

David

--
David A. Black (dblack@wobblini.net)
Ruby Power and Light, LLC (http://www.rubypowerandlight.com)

"Ruby for Rails" chapters now available
from Manning Early Access Program! Ruby for Rails

Dominik Bathon wrote:

meth .attr=42

I would say that would also be meth.attr=42 and not meth(.attr=42).

The spacing, though, makes it look like the latter. The spacing really
makes it look like 42 goes with .attr, not with meth.

Of course, then there is:

meth . attr = 42

and other fun variations :frowning:

Anthony DeRobertis <aderobertis@metrics.net> writes:

Dominik Bathon wrote:

meth .attr=42

I would say that would also be meth.attr=42 and not meth(.attr=42).

The spacing, though, makes it look like the latter. The spacing really
makes it look like 42 goes with .attr, not with meth.

Of course, then there is:

meth . attr = 42

and other fun variations :frowning:

It's a bit iffy, isn't it? Wouldn't it also break Matz's golden
rules of when to use call parens? I believe it goes:

  * if there are no args, don't use parens.
  * elsif you use the return value, use parens.
  * else parens are optional.