Hi
I’ve been trying to get my head around the rules for making classes. One
question I have is whether a class must be initialized. Or can a class
just hold data without taking an argument.
Hi
I’ve been trying to get my head around the rules for making classes. One
question I have is whether a class must be initialized. Or can a class
just hold data without taking an argument.
An initialised class (if I guess your meaning correctly) is called an
object or an instance.
Classes don’t have to be initialised to hold data or methods, but from
a design perspective class methods and instance methods are used for
different things. A class is usually a generic category, and an
instance of that class represents a particular object in that category.
For instance, “Car” might be a class, and “my VW Jetta” would be an
instance of it. Generally, most methods will likely be instance
methods, since it’s instances that you’re usually interested in.
Post an example of what you’re trying to do - you’ll likely get more
concrete advice.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs