What is the purpose of "initialize"

Why do you need initialize and what do you put in the parameter after
initialize(parameter)
?

···

--
Posted via http://www.ruby-forum.com/.

It's called a constructor in other languages. it can be used to initialize
the objects state. The arguments can give variance to the objects properties
which can alter it's behavior from the other instances initialized off the
same class template.

···

~

On Tue, Feb 15, 2011 at 6:26 PM, Gaba Luschi <friedoysterlover@gmail.com>wrote:

Why do you need initialize and what do you put in the parameter after
initialize(parameter)
?

--
Posted via http://www.ruby-forum.com/\.

the initialize method is your constructor it is called when you create a new
object automatically. It doesn't have to take a parameter at all. If it does
then you can set that to an instance variable to use in that class. If you
didn't understand much of that you might want to pick up a book on object
oriented programming it explains in much more detail.

···

---
Buddy Lindsey

http://www.twitter.com/buddylindsey

On Tue, Feb 15, 2011 at 6:26 PM, Gaba Luschi <friedoysterlover@gmail.com>wrote:

Why do you need initialize and what do you put in the parameter after
initialize(parameter)
?

--
Posted via http://www.ruby-forum.com/\.

Well, it is called by default when one instantiates an object from a class.
Furthermore, a class need not require a parameter upon instantiation. As in,
object = MyClass.new will set up an object with default values you have
chosen in the 'initialize' method. Without 'initialize', you inherit the
base constructor from which all all classes are derived.

···

On Tue, Feb 15, 2011 at 7:26 PM, Gaba Luschi <friedoysterlover@gmail.com>wrote:

Why do you need initialize and what do you put in the parameter after
initialize(parameter)
?

--
Posted via http://www.ruby-forum.com/\.

I should have said "from which all objects are derived"...

···

On Tue, Feb 15, 2011 at 8:30 PM, Brian Nicar <surprisevalley@verizon.net>wrote:

Well, it is called by default when one instantiates an object from a class.
Furthermore, a class need not require a parameter upon instantiation. As in,
object = MyClass.new will set up an object with default values you have
chosen in the 'initialize' method. Without 'initialize', you inherit the
base constructor from which all all classes are derived.

On Tue, Feb 15, 2011 at 7:26 PM, Gaba Luschi <friedoysterlover@gmail.com>wrote:

Why do you need initialize and what do you put in the parameter after
initialize(parameter)
?

--
Posted via http://www.ruby-forum.com/\.