[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: Random idea - private, blocks, constants

Yukihiro Matsumoto

12/14/2006 11:04:00 PM

Hi,

In message "Re: Random idea - private, blocks, constants"
on Fri, 15 Dec 2006 04:15:06 +0900, "Daniel Berger" <djberg96@gmail.com> writes:

|Do you object to the existence of private/protected then? You could
|say the same thing for methods. As I said, private is advisory only,
|but it does have its uses. For example, code coverage automation tools
|could be configured to ignore private methods (which is what I'm
|guessing most of them do by default).

The demand for private constants are much lower than private methods,
since constants are not overridden by subclasses, i.e.

class Foo
Foo=1
def foo
p "foo"
end
def bar
p Foo
p foo
end
end
class Bar < Foo
Foo=2
def foo
"bar"
end
end
Bar.new.bar

prints 1 and "bar", so that they need not to be protected by
visibility. They are, even if they are accepted, just for narrowing
constants list.

matz.

3 Answers

Sam Smoot

12/15/2006 12:30:00 AM

0


Yukihiro Matsumoto wrote:
> prints 1 and "bar", so that they need not to be protected by
> visibility. They are, even if they are accepted, just for narrowing
> constants list.
>
> matz.

In light of that, might the solution here simply be sub-classing the
objects involved (such as File) instead of decorating the existing
classes?

Daniel Berger

12/15/2006 5:15:00 AM

0

Sam Smoot wrote:
> Yukihiro Matsumoto wrote:
>> prints 1 and "bar", so that they need not to be protected by
>> visibility. They are, even if they are accepted, just for narrowing
>> constants list.
>>
>> matz.
>
> In light of that, might the solution here simply be sub-classing the
> objects involved (such as File) instead of decorating the existing
> classes?

Most of the time I would, but there are times when you want to redefine
methods of existing classes.

Also, C++ and C# seem to have the concept of private constants. What
they're used for in practice, though, I'm not sure. I'll have to
research more.

Regards,

Dan


Trans

12/15/2006 10:29:00 PM

0


Yukihiro Matsumoto wrote:
> Hi,
>
> In message "Re: Random idea - private, blocks, constants"
> on Fri, 15 Dec 2006 04:15:06 +0900, "Daniel Berger" <djberg96@gmail.com> writes:
>
> |Do you object to the existence of private/protected then? You could
> |say the same thing for methods. As I said, private is advisory only,
> |but it does have its uses. For example, code coverage automation tools
> |could be configured to ignore private methods (which is what I'm
> |guessing most of them do by default).
>
> The demand for private constants are much lower than private methods,
> since constants are not overridden by subclasses, i.e.
>
> class Foo
> Foo=1
> def foo
> p "foo"
> end
> def bar
> p Foo
> p foo
> end
> end
> class Bar < Foo
> Foo=2
> def foo
> "bar"
> end
> end
> Bar.new.bar
>
> prints 1 and "bar", so that they need not to be protected by
> visibility. They are, even if they are accepted, just for narrowing
> constants list.

How does method lookup differ from constant lookup? It has always
suprised me a little that FOO and FOO() are both legal and different.

trans.