Sign up or Sign in | Share
 
ClearMyBench
Welcome, Guest
Please Login or Register.    Lost Password?
Re:Ruby basics (1 viewing) (1) Guest
Go to bottom Post Reply Favoured: 0
TOPIC: Re:Ruby basics
#4583
ShriNi (User)
Software Techie (PEGA) currently on a Career Break
Platinum Boarder
Posts: 4000
graph
User Offline Click here to see the profile of this user
Gender: Female Location: Secundrabad India Birthdate: 1983-09-29
Re:Ruby basics 3 Years, 10 Months ago Karma: 0  
In addition to defining a new class, the class keyword creates a new constant to refer to the class.

The class name and the constant name are the same, so all class names must begin with a capital letter.
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#4584
ShriNi (User)
Software Techie (PEGA) currently on a Career Break
Platinum Boarder
Posts: 4000
graph
User Offline Click here to see the profile of this user
Gender: Female Location: Secundrabad India Birthdate: 1983-09-29
Re:Ruby basics 3 Years, 10 Months ago Karma: 0  
Within the body of a class, but outside of any instance methods defined by the class, the self keyword refers to the class being defined.
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#4585
ShriNi (User)
Software Techie (PEGA) currently on a Career Break
Platinum Boarder
Posts: 4000
graph
User Offline Click here to see the profile of this user
Gender: Female Location: Secundrabad India Birthdate: 1983-09-29
Re:Ruby basics 3 Years, 10 Months ago Karma: 0  
Instantiating an Object


Even though we haven't put anything in our Point class yet, we can still instantiate it:

p = Point.new
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#4586
ShriNi (User)
Software Techie (PEGA) currently on a Career Break
Platinum Boarder
Posts: 4000
graph
User Offline Click here to see the profile of this user
Gender: Female Location: Secundrabad India Birthdate: 1983-09-29
Re:Ruby basics 3 Years, 10 Months ago Karma: 0  
Initializing a Point:

When we create new Point objects, we want to initialize them with two numbers that represent their X and Y coordinates.

In many object-oriented languages, this is done with a constructor

. In Ruby, it is done with an initialize method:
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#4587
ShriNi (User)
Software Techie (PEGA) currently on a Career Break
Platinum Boarder
Posts: 4000
graph
User Offline Click here to see the profile of this user
Gender: Female Location: Secundrabad India Birthdate: 1983-09-29
Re:Ruby basics 3 Years, 10 Months ago Karma: 0  
An object can call initialize on itself, but you cannot explicitly call initialize on p to reinitialize its state
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#4588
ShriNi (User)
Software Techie (PEGA) currently on a Career Break
Platinum Boarder
Posts: 4000
graph
User Offline Click here to see the profile of this user
Gender: Female Location: Secundrabad India Birthdate: 1983-09-29
Re:Ruby basics 3 Years, 10 Months ago Karma: 0  
Defining a to_s Method

Any class we define should have a to_s instance method to return a string representation of the object
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
Go to top Post Reply
get the latest posts directly to your desktop
logo footer   Copyright 2009 - 2013 HotRecruiter.Com - All Rights Reserved