J
jonathan
jonathan said:that each method is static (doesn't change any data members). One could
Oops, meant to say 'doesn't change any non-static (or non-class-wide, or
instance-specific)' members.
--Jonathan
jonathan said:that each method is static (doesn't change any data members). One could
logancapaldo said:And the slighlty harder way
class IAlsoAmASingleton
class << self
private :new
end
def self.instance
@inst ||= new
end
end
Having many terms for the same thing isn't necessarily a bad
thing. It
happens in every other aspect of programming as well (class methods
are
called 'member functions', 'methods', 'member methods', etc.).
So all this is a long way of saying that what I really want for Christmas
is a short name for (class <<obj; self; end). But if I don't get that,
I'll still be very happy with getting Ruby 1.8.4, which I will brag about
to all my friends who are still stuck with their crufty old static language
tools.
matz said:I thought we were talking about so called singleton classes, right?
It's totally different from static classes in C# and C++.
Singleton classes in Ruby are:
* created run time on demand
* can be modified (or enhanced) run time
* their methods may modify any instances
* their scope are not limited to certain file
matz.
gwtmp01 said:Yes but we don't have Class#member, Class#method, Class#member_method,
Class#attribute, and Class#feature, etc. in Ruby. We have
Class#method and
that all by itself probably forces a canonical term for the concept.
Ahh. Ok. I think I also gathered from other posts that it also helps
to be able to differentiate these for the purpose of error messages.
Well, this may be a solution:
Let the type of singleton which implements the singleton design pattern
remain as a 'singleton' in error messaging and introspection. But, let
the class which is a singleton by having nothing but class methods be
known as a simpleton.
dblack said:Anyway -- I'm trying to follow along but not sure what you mean by
classes that have nothing but class methods and class data. Can you
give a code example of such a class?
dblack said:Do you know what the word "simpleton" means? It's really not a
candidate for a name for a language construct.
Anyway -- I'm trying to follow along but not sure what you mean by
classes that have nothing but class methods and class data. Can you
give a code example of such a class?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.