About class methods

Martin DeMello wrote:

It’s not a subclass, it’s an anonymous proxy superclass. It goes into
the inheritance chain between the object it extends and the class that
object derived from, like so (assume a is a String):

[String] — [class << a] — [a]

Since ruby doesn’t have multiple inheritance, you can see why there can
(and need!) only be a single proxy superclass.

So, this means you lose the functionality of a? I thought the whole
point was to extend a. The tutorial
(http://www.rubygarden.org/ruby?SingletonTutorial) actually doesn’t
mention whether it is super or sub, i just assumed sub. I suppose
whether it was super or sub really doesn’t matter except in what you
would be referencing by ‘self’ or ‘super’ in the added code (i.e., if
you are correct, then doing self at class scope level would allow you to
access the super class, or doing self at instance scope (in the new
code) would reference an instance of the super class. Of course, if you
used super in that context, it would reference the original class’
grandparent. Are you sure this is how it works? The tutorial doesn’t
do any of the things I just mentioned, so it can’t answer this question.

Thanks,
–J

Martin DeMello wrote:

It’s not a subclass, it’s an anonymous proxy superclass. It goes into
the inheritance chain between the object it extends and the class that
object derived from, like so (assume a is a String):

[String] — [class << a] — [a]

Since ruby doesn’t have multiple inheritance, you can see why there can
(and need!) only be a single proxy superclass.

martin

How about this old chestnut, which I frankly don’t understand:

http://onestepback.org/images/rubyobjects.png

jonathan leonard wrote:

Eero S. wrote:

Well, there is always define_method:

This code for illustrative purposes only. This is unadvisable.

class Class
def extend_by(method_name, &block)
o = Object.const_set("#{self.name}Extension", Class.new(self))
o.class_eval {
define_method(method_name, &block)
}
o
end
end

class Foo
end

Extension = Foo.extend_by(‘quux’) { puts “Hello from quux!” }
Extension.new.quux

Why is the code above unadvisable?

I personally think the idiom is a bit suspect but it could
just be I have not come across the need for it :slight_smile: The above
merely illustrates that it is quite possible to do that in
ruby; however, another way might lead to a better design.

(Generally, any types of factories are simple in ruby and
the whole duck-typing thing helps, too.)

–J

E

Eero S. wrote:

Why is the code above unadvisable?

I personally think the idiom is a bit suspect but it could
just be I have not come across the need for it :slight_smile: The above
merely illustrates that it is quite possible to do that in
ruby; however, another way might lead to a better design.

(Generally, any types of factories are simple in ruby and
the whole duck-typing thing helps, too.)

I don’t really see how duck-typing is relevant, but I would assume that
the idiom used above (i.e., ‘const_set’, ‘class_eval’, and
‘define_method’) could be done in an extension factory (rather than
procedurally as above). In other words, you might have a factory called
JumpExtensionFactory which could create any object that can jump (e.g.,
people, animals, monsters, etc.) from a non-jumping object say in a
video game model.

I suppose it would have to calculate the maximum jump height and length
based on other statistics such as leg strength, weight, etc. (which
would presumably have to be attributes the object already has or can
acquire) and the actual jump height and length based on run-time
attributes such as velocity and input force. That is the purpose I can
see for this sort of thing. Is that what you mean by utilizing
factories?

The only real problem I see with this is you really wouldn’t want to
create a new object, but rather extend the original one. In other
words, after a type learns to jump, then all objects of that type should
be able to jump (so there’s no need to distinguish from a non-jumping
version and the jumping version). So, actually, I would call it an
JumpExtender or a JumpTeacher (instead of JumpExtensionFactory).

(Thinking out loud here). But, hopefully we’re closer to the same page
now.

–J

Dave H. wrote:

On Dec 12, 2005, at 0:07, Chad P. wrote:

By the way . . . has anyone considered a name like “singular”? What
about “ad lib” instead of “ad hoc”?

I’ve gotta say, though, that I’m partial to the descriptor “eigen”.

–snip–

If you have a situation where none of the existing reasonable terms seem
like an adequately non-confusing match, then it’s actually much better
to use a term that doesn’t bring a lot of pre-conceived baggage to the
table.

Well, then there is obviously only one logical choice:

Chunky Bacon Class!

Regards,

Michael

On Dec 12, 2005, at 0:07, Chad P. wrote:

By the way . . . has anyone considered a name like “singular”? What
about “ad lib” instead of “ad hoc”?

I’ve gotta say, though, that I’m partial to the descriptor “eigen”.

Well, I’m having a terrible time following the distinction between the
indefinite number of flavors of this difficult-to-name type of method,
but I do know something about naming things. :slight_smile:

Generally, trying to find an existing term, like ‘singleton’ or ‘ad
hoc’, is a good thing, because lets somebody bring pre-constructed
expectations to the process, hopefully saving them time in learning how
this particular thing works.

Unless, of course, different people have different expectations for
that word, or if the thing in question contradicts the expectations in
some way.

If ‘simpleton’ and ‘singleton’ are equally applicable to either of two
different cases, as somebody suggested earlier, then these will lead
people to think they know what will happen, but there’s a 50/50
chance that it will be the other. So that’s not a good thing. There
appears to be some concern that “ad hoc” implies something much broader
(?) than this particular usage actually has. That’s not a good thing.

If you have a situation where none of the existing reasonable terms
seem like an adequately non-confusing match, then it’s actually much
better to use a term that doesn’t bring a lot of pre-conceived
baggage to the table. If you create a term that’s obviously
meaningless or ambiguous, then the first-time user knows right away
that they’ll have to look it up, instead of erroneously thinking they
know what it does just because of the name. Calling them something like
“intral methods”, “uni methods”, “anonic methods,” or “eigenz” is
better than using a “real” pre-existing word that is a poor fit. “Hmm.
Uni methods. Well, I have a hunch what that might be for, but it isn’t
immediately obvious. I’ll just have to read more about it to find out
what they actually do.”

Hi –

On Tue, 13 Dec 2005, Dave H. wrote:

do know something about naming things. :slight_smile:
different cases, as somebody suggested earlier, then these will lead people
erroneously thinking they know what it does just because of the name. Calling
them something like “intral methods”, “uni methods”, “anonic methods,” or
“eigenz” is better than using a “real” pre-existing word that is a poor fit.
“Hmm. Uni methods. Well, I have a hunch what that might be for, but it isn’t
immediately obvious. I’ll just have to read more about it to find out what
they actually do.”

A couple of problems with that, in this particular case:

First, there’s an existing term (singleton method/class) that’s under
review by Matz, with input from the community. That means that
calling them “potato-peel classes”, or whatever, not only adds
confusion but short-circuits a process that’s already underway and
that promises to result in a decision and clarification.

Second, you can’t read more about the thing if you don’t know what
it’s called. All this renaming just adds an extra layer of having to
learn about the history of ruby-talk, as well as the features of the
Ruby language, in order to know what people are talking about in the
first place. The advantages of this elude me. I think the community
would be well advised not to assume that the world’s interest in
keeping track of who uses which home-made synonym for “singleton
class” is unlimited.

David


David A. Black
[email protected]

“Ruby for Rails”, forthcoming from Manning Publications, April 2006!

Dave H. wrote:

If ‘simpleton’ and ‘singleton’ are equally applicable to either of two
different cases, as somebody suggested earlier, then these will lead
people to think they know what will happen, but there’s a 50/50
chance that it will be the other. So that’s not a good thing.

Well, I think ‘simpleton’ and ‘singleton’ are synonymous terms (about
98% sure of that if this were a lifeline). But, the problem would
remain if singleton isn’t a good fit to begin with. I actually think
singleton is a good fit and therefore so is simpleton.

–J

Dave H. wrote:

Generally, trying to find an existing term, like ‘singleton’ or ‘ad
hoc’, is a good thing, because lets somebody bring pre-constructed
expectations to the process, hopefully saving them time in learning how
this particular thing works.

I believe, and there is a slight chance that I’m wrong, that the terms
simpleton and singleton are synonymous.

–J

unknown wrote:

I think you’re laboring under a misunderstanding.

Please see http://dictionary.reference.com/search?q=simpleton

I don’t think so.

see:

or do a google search for ‘simpleton design pattern’ for many others.

–J

Hi –

On Wed, 14 Dec 2005, jonathan leonard [email protected]
[email protected] [email protected] wrote:

I think you’re laboring under a misunderstanding.

Please see http://dictionary.reference.com/search?q=simpleton

David


David A. Black
[email protected]

“Ruby for Rails”, forthcoming from Manning Publications, April 2006!

unknown wrote:

or do a google search for ‘simpleton design pattern’ for many others.
This seems to be some kind of play on words. “Simpleton” is not an
appropriate serious word for a language feature.

Yea, I agree there is some word playing going on (it may be kinda like
releasing a virus into the wild). Some of what the search turned up was
making fun of the singleton pattern by calling it simpleton (and the
rest could have been accidental misuses). However, I could have sworn
that I saw this word used in a more legitimate place (such as a lecture
or textbook). If I run across a more authoritative source, I’ll share
it.

Nevertheless, I have to disagree with your ‘serious’ requirement for
words for language features in general and, in particular, concerning
simpleton. Take for instance, ‘duck typing’. And, I see nothing wrong
with simpleton either, if there were an actual language construct which
fit the word; although, I admit, it might not fit for ‘singleton’ as
much as I initially thought.

However, if you expand your search, you can find people refering to code
modules as simpletons, based on the fact that they have a limited,
simple set of functionality (check out this page for instance):

and it does seem to fit their architecture.

–J

Hi –

On Wed, 14 Dec 2005, jonathan leonard [email protected]
[email protected] [email protected] wrote:

or do a google search for ‘simpleton design pattern’ for many others.
This seems to be some kind of play on words. “Simpleton” is not an
appropriate serious word for a language feature.

David


David A. Black
[email protected]

“Ruby for Rails”, forthcoming from Manning Publications, April 2006!

On Dec 13, 2005, at 10:00 PM, [email protected] wrote:

I think you’re laboring under a misunderstanding.

Please see Simpleton Definition & Meaning | Dictionary.com

Just for comparision:
singleton |Ë?si ng gÉ?ltÉ?n| |Ë?sɪÅ?gÉ?lt(É?)n| |Ë?sɪÅ?g(É?)lt(É?)n|
noun
a single person or thing of the kind under consideration : splitting
the clumps of plants into singletons.
â?¢ [often as adj. ] a child or animal born singly, rather than one of
a multiple birth : singleton boys.
â?¢ (in card games, esp. bridge) a card that is the only one of its
suit in a hand.
â?¢ Mathematics & Logic a set that contains exactly one element.
ORIGIN late 19th cent.: from single , on the pattern of simpleton.

Logan C. wrote:

Just for comparision:
singleton |Ë?si ng gÉ?ltÉ?n| |Ë?sɪÅ?gÉ?lt(É?)n| |Ë?sɪÅ?g(É?)lt(É?)n|
noun
a single person or thing of the kind under consideration : splitting
the clumps of plants into singletons.
â?¢ [often as adj. ] a child or animal born singly, rather than one of
a multiple birth : singleton boys.
â?¢ (in card games, esp. bridge) a card that is the only one of its
suit in a hand.
â?¢ Mathematics & Logic a set that contains exactly one element.
ORIGIN late 19th cent.: from single , on the pattern of simpleton.

What is the source of this definition? This could be my vindication. :slight_smile:

–J

On Wed, 14 Dec 2005 03:57:35 -0000, jonathan leonard
[email protected] wrote:

(David Black) wrote:

I think you’re laboring under a misunderstanding.

Please see http://dictionary.reference.com/search?q=simpleton

I don’t think so.

Lol!