Gavin Kistner wrote:
> I’d like to have a def that I can scope in one go, i.e.,
>
> class A
> scoped_def :private, :a do
> ⋮
> end
> end
What do you prefer about the above, versus the existing (and, IMO,
slightly prettier):
class A
private; def meth1( arg1, arg2=:foo )
'private'
end
protected; def meth2( arg1, arg2='bar' )
'protected'
end
public; def meth2( arg1, arg2 )
'public'
end
end
Well, the visibility will affect all methods defined after it and I
really want to intermingle methods of varying visibility, i.e., not, as
you suggest below, to group them by visibility.
With your technique, you cannot declare default values for arguments,
correct? (At least, not in blocks in 1.8)
And while the above syntax that I wrote is close to yours, I further
personally prefer using the public/protected/private items as they
were intended, to denote blocks of methods in my class which are
each, visually grouping like-scoped methods.
Actually, I’d argue that this isn’t how they were intended, as that is a
behavior that these methods take upon themselves if not passed any
arguments. Looking at the standard library, there are thirty instances
of private being used as below and ninety-one instances of the
private :name1, :name2, …
kind.
class A
def public1; ...; end
def public2; ...; end
protected
def protected1; ...; end
def protected2; ...; end
private
def private1; ...; end
def private2; ...; end
end
Anyway, thanks for your input,
nikolai
···
On May 17, 2005, at 7:52 AM, Nikolai Weibull wrote:
--
Nikolai Weibull: now available free of charge at http://bitwi.se/\!
Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}