<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Sandi</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Sandi"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Sandi"/>
	<updated>2026-05-07T11:34:02Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ans&amp;diff=82036</id>
		<title>CSC/ECE 517 Fall 2013/oss ans</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ans&amp;diff=82036"/>
		<updated>2013-10-31T02:38:37Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* Project Description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''' E807 : Refactoring and testing response_controller.rb''' &lt;br /&gt;
&lt;br /&gt;
== Project Description == &lt;br /&gt;
The response controller creates, edits, and displays responses, that is, rubrics to be filled out, or filled-out rubrics.&lt;br /&gt;
Responses are typically reviews, metareviews or feedback depending upon the stage of the current project. &lt;br /&gt;
Our project requirement entailed the following things to be done.&lt;br /&gt;
&lt;br /&gt;
* Reduce the method complexity in the response controller.&lt;br /&gt;
* Remove duplicated code.&lt;br /&gt;
* There were “custom_create” and “custom_update” methods for “custom” (multipart) rubrics. We already had create and update methods that were handling the normal rubrics. Our job was to use polymorphism in order to eliminate the custom methods.&lt;br /&gt;
&lt;br /&gt;
== Refactoring carried out ==&lt;br /&gt;
As per the project requirements the following work was carried out :&lt;br /&gt;
&lt;br /&gt;
* The duplicated code has been refactored and put in a separate method which is called wherever required. This prevents redundancy.&lt;br /&gt;
* The variables set up in controller become automatically available to the views. Hence the repeated code from controller and view for finding the topic id signed up by a user/team has been deleted from controller and incorporated only in the response view. The following code snippet was removed from the response controller.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if !@map.contributor.nil?&lt;br /&gt;
        if @map.assignment.team_assignment?&lt;br /&gt;
          team_member = TeamsUser.find_by_team_id(@map.contributor).user_id&lt;br /&gt;
          @topic_id = Participant.find_by_parent_id_and_user_id(@map.assignment.id,team_member).topic_id&lt;br /&gt;
        else&lt;br /&gt;
          @topic_id = Participant.find(@map.contributor).topic_id&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
if !@topic_id.nil?&lt;br /&gt;
        @signedUpTopic = SignUpTopic.find(@topic_id).topic_name&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because , similar code existed in the response view&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% if !@map.contributor.nil?%&amp;gt;&lt;br /&gt;
  &amp;lt;%if @map.assignment.team_assignment?&lt;br /&gt;
        team_member = TeamsUser.find_by_team_id(@map.contributor).user_id&lt;br /&gt;
        topic_id = Participant.find_by_parent_id_and_user_id(@map.assignment.id,team_member).topic_id&lt;br /&gt;
    else%&amp;gt;&lt;br /&gt;
        &amp;lt;% topic_id = Participant.find(@map.contributor).topic_id%&amp;gt;&lt;br /&gt;
  &amp;lt;%end%&amp;gt;  &lt;br /&gt;
  &amp;lt;%if !topic_id.nil?%&amp;gt;&lt;br /&gt;
    &amp;lt;h2&amp;gt;You are reviewing &amp;lt;%=SignUpTopic.find(topic_id).topic_name%&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
  &amp;lt;%end%&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* We created a new method in order to find the latest response thereby by eliminating the need to reuse the following code multiple times.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def latestResponseVersion&lt;br /&gt;
    #get all previous versions of responses for the response map.&lt;br /&gt;
    array_not_empty=0&lt;br /&gt;
    @review_scores=Array.new&lt;br /&gt;
    @prev=Response.find_by_map_id(@map.id)&lt;br /&gt;
    for element in @prev&lt;br /&gt;
      array_not_empty=1&lt;br /&gt;
      @review_scores &amp;lt;&amp;lt; element&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The custom create and custom update methods have been removed. Their functionality has been merged with create and update methods as was mentioned in the requirement specification. Depending on the type of rubric rendered, the create and update method does the necessary updations.&lt;br /&gt;
&lt;br /&gt;
== Testing Done ==&lt;br /&gt;
&lt;br /&gt;
Integration tests for capybara were created for the scenarios describing admin login, creation of an assignment by admin and user login.&lt;br /&gt;
&lt;br /&gt;
==Future Work ==&lt;br /&gt;
=== Design Changes ===&lt;br /&gt;
* An even better way to handle the rubrics would be to do subclassing of the questionnaire model in order to create two sub classes the rating rubric and the multipart rubric. As per the rubric being rendered the appropriate class would be called. This method would be much more efficient than the current way the functionality is being handled also it would be more O-O like.&lt;br /&gt;
&lt;br /&gt;
=== Further Refactoring ===&lt;br /&gt;
Given the current state of the response controller, further improvements can be done to the code: &lt;br /&gt;
&lt;br /&gt;
* The controller still has some code that is only there for some specific assignments. This is bad design and this code needs to be removed.&lt;br /&gt;
&lt;br /&gt;
* The purpose of saving method is not quite clear. It predominantly has the code for an assignment '562' which has been hard coded and can be removed.&lt;br /&gt;
&lt;br /&gt;
* The rubric model has been created but has not been used anywhere in the code.&lt;br /&gt;
&lt;br /&gt;
== Appendix ==&lt;br /&gt;
=== Setup Process ===&lt;br /&gt;
* We cloned the repo from https://github.com/expertiza/expertiza into our local directory.&lt;br /&gt;
* After installing MySQL server we loaded the test-db.sql sample database into the application.&lt;br /&gt;
* Next we created our own users and a new assignment to understand the working of the response controller.&lt;br /&gt;
* First of all, an admin needs to create a minimum of two users who will participate in the same assignment. &lt;br /&gt;
* The admin needs to create one assignment and add participants to the assignment. Further details of the assignment need to be added as necessary such as due dates, review strategy etc.&lt;br /&gt;
* Review strategy can be auto selected or student selected. If the TA or instructor is manually assigning the assignments for review, it has to be “instructor selected”. &lt;br /&gt;
* Check the &amp;quot;Due dates&amp;quot; tab and check if the review is allowed at the current date. Update due dates so that the review date starts after the submission date is passed. Save dependencies.&lt;br /&gt;
* Add a signup sheet to the assignment. This sheet will display topics which the users can select to review.&lt;br /&gt;
* Now, login through user1 account and select an assignment. Then sign up for one topic from the list of available topics.&lt;br /&gt;
* After that, user1 needs to submit a hyperlink.&lt;br /&gt;
* Now, login through user2 credentials. User2 must select the assignment(of which it was made a participant by the admin).&lt;br /&gt;
* User2 must go to the student_task page and select the link &amp;quot;other's work&amp;quot; which will be enabled only if a particular topic of an assignment has review_allowed to be true, that means the deadline should be properly configured by the admin. &lt;br /&gt;
&lt;br /&gt;
* After that, response view would be rendered to the reviewer.&lt;br /&gt;
* The reviewer would review the assignment submitted by user1. Once the review has been saved, user1 will have an option to provide feedback on the review.&lt;br /&gt;
* If meta reviews have been enabled by the admin, then the other participants will be able to see the reviews of other users.&lt;br /&gt;
&lt;br /&gt;
=== Issues Encountered ===&lt;br /&gt;
&lt;br /&gt;
* In order to get the application working properly we added several routes to the routes.rb file.&lt;br /&gt;
* Assignment submission status was not being changed in spite of changing the deadline due-dates in the edit assignment section for the admin.&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
:1. [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza]&lt;br /&gt;
&lt;br /&gt;
:2. [http://152.7.99.43:3000/ VCL Link]&lt;br /&gt;
&lt;br /&gt;
:3. [https://github.com/nixtish/expertiza Git repository]&lt;br /&gt;
&lt;br /&gt;
:4. [https://docs.google.com/a/ncsu.edu/document/d/1Z0xjFZu-Zy-xm73YyUVUgFCtfWgRwhN1rZuThoyF-U0/edit Steps to setup Expertiza]&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ans&amp;diff=82013</id>
		<title>CSC/ECE 517 Fall 2013/oss ans</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ans&amp;diff=82013"/>
		<updated>2013-10-31T02:29:45Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* Issues Encountered */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''' E807 : Refactoring and testing response_controller.rb''' &lt;br /&gt;
&lt;br /&gt;
== Project Description == &lt;br /&gt;
The response controller creates, edits, and displays responses, that is, rubrics to be filled out, or filled-out rubrics. Our project requirement entailed the following things to be done.&lt;br /&gt;
&lt;br /&gt;
* Reduce the method complexity in the response controller.&lt;br /&gt;
* Remove duplicated code.&lt;br /&gt;
* There were “custom_create” and “custom_update” methods for “custom” (multipart) rubrics. We already had create and update methods that were handling the normal rubrics. Our job was to use polymorphism in order to eliminate the custom methods.&lt;br /&gt;
&lt;br /&gt;
== Refactoring carried out ==&lt;br /&gt;
As per the project requirements the following work was carried out :&lt;br /&gt;
&lt;br /&gt;
* The duplicated code has been refactored and put in a separate method which is called wherever required. This prevents redundancy.&lt;br /&gt;
* The variables set up in controller become automatically available to the views. Hence the repeated code from controller and view for finding the topic id signed up by a user/team has been deleted from controller and incorporated only in the response view. The following code snippet was removed from the response controller.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if !@map.contributor.nil?&lt;br /&gt;
        if @map.assignment.team_assignment?&lt;br /&gt;
          team_member = TeamsUser.find_by_team_id(@map.contributor).user_id&lt;br /&gt;
          @topic_id = Participant.find_by_parent_id_and_user_id(@map.assignment.id,team_member).topic_id&lt;br /&gt;
        else&lt;br /&gt;
          @topic_id = Participant.find(@map.contributor).topic_id&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
if !@topic_id.nil?&lt;br /&gt;
        @signedUpTopic = SignUpTopic.find(@topic_id).topic_name&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because , similar code existed in the response view&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% if !@map.contributor.nil?%&amp;gt;&lt;br /&gt;
  &amp;lt;%if @map.assignment.team_assignment?&lt;br /&gt;
        team_member = TeamsUser.find_by_team_id(@map.contributor).user_id&lt;br /&gt;
        topic_id = Participant.find_by_parent_id_and_user_id(@map.assignment.id,team_member).topic_id&lt;br /&gt;
    else%&amp;gt;&lt;br /&gt;
        &amp;lt;% topic_id = Participant.find(@map.contributor).topic_id%&amp;gt;&lt;br /&gt;
  &amp;lt;%end%&amp;gt;  &lt;br /&gt;
  &amp;lt;%if !topic_id.nil?%&amp;gt;&lt;br /&gt;
    &amp;lt;h2&amp;gt;You are reviewing &amp;lt;%=SignUpTopic.find(topic_id).topic_name%&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
  &amp;lt;%end%&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* We created a new method in order to find the latest response thereby by eliminating the need to reuse the following code multiple times.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def latestResponseVersion&lt;br /&gt;
    #get all previous versions of responses for the response map.&lt;br /&gt;
    array_not_empty=0&lt;br /&gt;
    @review_scores=Array.new&lt;br /&gt;
    @prev=Response.find_by_map_id(@map.id)&lt;br /&gt;
    for element in @prev&lt;br /&gt;
      array_not_empty=1&lt;br /&gt;
      @review_scores &amp;lt;&amp;lt; element&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The custom create and custom update methods have been removed. Their functionality has been merged with create and update methods as was mentioned in the requirement specification. Depending on the type of rubric rendered, the create and update method does the necessary updations.&lt;br /&gt;
&lt;br /&gt;
== Testing Done ==&lt;br /&gt;
&lt;br /&gt;
Integration tests for capybara were created for the scenarios describing admin login, creation of an assignment by admin and user login.&lt;br /&gt;
&lt;br /&gt;
==Future Work ==&lt;br /&gt;
=== Design Changes ===&lt;br /&gt;
* An even better way to handle the rubrics would be to do subclassing of the questionnaire model in order to create two sub classes the rating rubric and the multipart rubric. As per the rubric being rendered the appropriate class would be called. This method would be much more efficient than the current way the functionality is being handled also it would be more O-O like.&lt;br /&gt;
&lt;br /&gt;
=== Further Refactoring ===&lt;br /&gt;
Given the current state of the response controller, further improvements can be done to the code: &lt;br /&gt;
&lt;br /&gt;
* The controller still has some code that is only there for some specific assignments. This is bad design and this code needs to be removed.&lt;br /&gt;
&lt;br /&gt;
* The purpose of saving method is not quite clear. It predominantly has the code for an assignment '562' which has been hard coded and can be removed.&lt;br /&gt;
&lt;br /&gt;
* The rubric model has been created but has not been used anywhere in the code.&lt;br /&gt;
&lt;br /&gt;
== Appendix ==&lt;br /&gt;
=== Setup Process ===&lt;br /&gt;
* We cloned the repo from https://github.com/expertiza/expertiza into our local directory.&lt;br /&gt;
* After installing MySQL server we loaded the test-db.sql sample database into the application.&lt;br /&gt;
* Next we created our own users and a new assignment to understand the working of the response controller.&lt;br /&gt;
* First of all, an admin needs to create a minimum of two users who will participate in the same assignment. &lt;br /&gt;
* The admin needs to create one assignment and add participants to the assignment. Further details of the assignment need to be added as necessary such as due dates, review strategy etc.&lt;br /&gt;
* Review strategy can be auto selected or student selected. If the TA or instructor is manually assigning the assignments for review, it has to be “instructor selected”. &lt;br /&gt;
* Check the &amp;quot;Due dates&amp;quot; tab and check if the review is allowed at the current date. Update due dates so that the review date starts after the submission date is passed. Save dependencies.&lt;br /&gt;
* Add a signup sheet to the assignment. This sheet will display topics which the users can select to review.&lt;br /&gt;
* Now, login through user1 account and select an assignment. Then sign up for one topic from the list of available topics.&lt;br /&gt;
* After that, user1 needs to submit a hyperlink.&lt;br /&gt;
* Now, login through user2 credentials. User2 must select the assignment(of which it was made a participant by the admin).&lt;br /&gt;
* User2 must go to the student_task page and select the link &amp;quot;other's work&amp;quot; which will be enabled only if a particular topic of an assignment has review_allowed to be true, that means the deadline should be properly configured by the admin. &lt;br /&gt;
&lt;br /&gt;
* After that, response view would be rendered to the reviewer.&lt;br /&gt;
* The reviewer would review the assignment submitted by user1. Once the review has been saved, user1 will have an option to provide feedback on the review.&lt;br /&gt;
* If meta reviews have been enabled by the admin, then the other participants will be able to see the reviews of other users.&lt;br /&gt;
&lt;br /&gt;
=== Issues Encountered ===&lt;br /&gt;
&lt;br /&gt;
* In order to get the application working properly we added several routes to the routes.rb file.&lt;br /&gt;
* Assignment submission status was not being changed in spite of changing the deadline due-dates in the edit assignment section for the admin.&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
:1. [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza]&lt;br /&gt;
&lt;br /&gt;
:2. [http://152.7.99.43:3000/ VCL Link]&lt;br /&gt;
&lt;br /&gt;
:3. [https://github.com/nixtish/expertiza Git repository]&lt;br /&gt;
&lt;br /&gt;
:4. [https://docs.google.com/a/ncsu.edu/document/d/1Z0xjFZu-Zy-xm73YyUVUgFCtfWgRwhN1rZuThoyF-U0/edit Steps to setup Expertiza]&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ans&amp;diff=82011</id>
		<title>CSC/ECE 517 Fall 2013/oss ans</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ans&amp;diff=82011"/>
		<updated>2013-10-31T02:29:20Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* Further Refactoring */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''' E807 : Refactoring and testing response_controller.rb''' &lt;br /&gt;
&lt;br /&gt;
== Project Description == &lt;br /&gt;
The response controller creates, edits, and displays responses, that is, rubrics to be filled out, or filled-out rubrics. Our project requirement entailed the following things to be done.&lt;br /&gt;
&lt;br /&gt;
* Reduce the method complexity in the response controller.&lt;br /&gt;
* Remove duplicated code.&lt;br /&gt;
* There were “custom_create” and “custom_update” methods for “custom” (multipart) rubrics. We already had create and update methods that were handling the normal rubrics. Our job was to use polymorphism in order to eliminate the custom methods.&lt;br /&gt;
&lt;br /&gt;
== Refactoring carried out ==&lt;br /&gt;
As per the project requirements the following work was carried out :&lt;br /&gt;
&lt;br /&gt;
* The duplicated code has been refactored and put in a separate method which is called wherever required. This prevents redundancy.&lt;br /&gt;
* The variables set up in controller become automatically available to the views. Hence the repeated code from controller and view for finding the topic id signed up by a user/team has been deleted from controller and incorporated only in the response view. The following code snippet was removed from the response controller.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if !@map.contributor.nil?&lt;br /&gt;
        if @map.assignment.team_assignment?&lt;br /&gt;
          team_member = TeamsUser.find_by_team_id(@map.contributor).user_id&lt;br /&gt;
          @topic_id = Participant.find_by_parent_id_and_user_id(@map.assignment.id,team_member).topic_id&lt;br /&gt;
        else&lt;br /&gt;
          @topic_id = Participant.find(@map.contributor).topic_id&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
if !@topic_id.nil?&lt;br /&gt;
        @signedUpTopic = SignUpTopic.find(@topic_id).topic_name&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because , similar code existed in the response view&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% if !@map.contributor.nil?%&amp;gt;&lt;br /&gt;
  &amp;lt;%if @map.assignment.team_assignment?&lt;br /&gt;
        team_member = TeamsUser.find_by_team_id(@map.contributor).user_id&lt;br /&gt;
        topic_id = Participant.find_by_parent_id_and_user_id(@map.assignment.id,team_member).topic_id&lt;br /&gt;
    else%&amp;gt;&lt;br /&gt;
        &amp;lt;% topic_id = Participant.find(@map.contributor).topic_id%&amp;gt;&lt;br /&gt;
  &amp;lt;%end%&amp;gt;  &lt;br /&gt;
  &amp;lt;%if !topic_id.nil?%&amp;gt;&lt;br /&gt;
    &amp;lt;h2&amp;gt;You are reviewing &amp;lt;%=SignUpTopic.find(topic_id).topic_name%&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
  &amp;lt;%end%&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* We created a new method in order to find the latest response thereby by eliminating the need to reuse the following code multiple times.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def latestResponseVersion&lt;br /&gt;
    #get all previous versions of responses for the response map.&lt;br /&gt;
    array_not_empty=0&lt;br /&gt;
    @review_scores=Array.new&lt;br /&gt;
    @prev=Response.find_by_map_id(@map.id)&lt;br /&gt;
    for element in @prev&lt;br /&gt;
      array_not_empty=1&lt;br /&gt;
      @review_scores &amp;lt;&amp;lt; element&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The custom create and custom update methods have been removed. Their functionality has been merged with create and update methods as was mentioned in the requirement specification. Depending on the type of rubric rendered, the create and update method does the necessary updations.&lt;br /&gt;
&lt;br /&gt;
== Testing Done ==&lt;br /&gt;
&lt;br /&gt;
Integration tests for capybara were created for the scenarios describing admin login, creation of an assignment by admin and user login.&lt;br /&gt;
&lt;br /&gt;
==Future Work ==&lt;br /&gt;
=== Design Changes ===&lt;br /&gt;
* An even better way to handle the rubrics would be to do subclassing of the questionnaire model in order to create two sub classes the rating rubric and the multipart rubric. As per the rubric being rendered the appropriate class would be called. This method would be much more efficient than the current way the functionality is being handled also it would be more O-O like.&lt;br /&gt;
&lt;br /&gt;
=== Further Refactoring ===&lt;br /&gt;
Given the current state of the response controller, further improvements can be done to the code: &lt;br /&gt;
&lt;br /&gt;
* The controller still has some code that is only there for some specific assignments. This is bad design and this code needs to be removed.&lt;br /&gt;
&lt;br /&gt;
* The purpose of saving method is not quite clear. It predominantly has the code for an assignment '562' which has been hard coded and can be removed.&lt;br /&gt;
&lt;br /&gt;
* The rubric model has been created but has not been used anywhere in the code.&lt;br /&gt;
&lt;br /&gt;
== Appendix ==&lt;br /&gt;
=== Setup Process ===&lt;br /&gt;
* We cloned the repo from https://github.com/expertiza/expertiza into our local directory.&lt;br /&gt;
* After installing MySQL server we loaded the test-db.sql sample database into the application.&lt;br /&gt;
* Next we created our own users and a new assignment to understand the working of the response controller.&lt;br /&gt;
* First of all, an admin needs to create a minimum of two users who will participate in the same assignment. &lt;br /&gt;
* The admin needs to create one assignment and add participants to the assignment. Further details of the assignment need to be added as necessary such as due dates, review strategy etc.&lt;br /&gt;
* Review strategy can be auto selected or student selected. If the TA or instructor is manually assigning the assignments for review, it has to be “instructor selected”. &lt;br /&gt;
* Check the &amp;quot;Due dates&amp;quot; tab and check if the review is allowed at the current date. Update due dates so that the review date starts after the submission date is passed. Save dependencies.&lt;br /&gt;
* Add a signup sheet to the assignment. This sheet will display topics which the users can select to review.&lt;br /&gt;
* Now, login through user1 account and select an assignment. Then sign up for one topic from the list of available topics.&lt;br /&gt;
* After that, user1 needs to submit a hyperlink.&lt;br /&gt;
* Now, login through user2 credentials. User2 must select the assignment(of which it was made a participant by the admin).&lt;br /&gt;
* User2 must go to the student_task page and select the link &amp;quot;other's work&amp;quot; which will be enabled only if a particular topic of an assignment has review_allowed to be true, that means the deadline should be properly configured by the admin. &lt;br /&gt;
&lt;br /&gt;
* After that, response view would be rendered to the reviewer.&lt;br /&gt;
* The reviewer would review the assignment submitted by user1. Once the review has been saved, user1 will have an option to provide feedback on the review.&lt;br /&gt;
* If meta reviews have been enabled by the admin, then the other participants will be able to see the reviews of other users.&lt;br /&gt;
&lt;br /&gt;
=== Issues Encountered ===&lt;br /&gt;
&lt;br /&gt;
* In order to get the application working properly we added several routes to the routes.rb file.&lt;br /&gt;
* Assignment submission status was not being changed in spite of changing the deadline due-dates in the edit assignment section of the admin.&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
:1. [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza]&lt;br /&gt;
&lt;br /&gt;
:2. [http://152.7.99.43:3000/ VCL Link]&lt;br /&gt;
&lt;br /&gt;
:3. [https://github.com/nixtish/expertiza Git repository]&lt;br /&gt;
&lt;br /&gt;
:4. [https://docs.google.com/a/ncsu.edu/document/d/1Z0xjFZu-Zy-xm73YyUVUgFCtfWgRwhN1rZuThoyF-U0/edit Steps to setup Expertiza]&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ans&amp;diff=81983</id>
		<title>CSC/ECE 517 Fall 2013/oss ans</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ans&amp;diff=81983"/>
		<updated>2013-10-31T02:18:05Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* Testing Done */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''' E807 : Refactoring and testing response_controller.rb''' &lt;br /&gt;
&lt;br /&gt;
== Project Description == &lt;br /&gt;
The response controller creates, edits, and displays responses, that is, rubrics to be filled out, or filled-out rubrics. Our project requirement entailed the following things to be done.&lt;br /&gt;
&lt;br /&gt;
* Reduce the method complexity in the response controller.&lt;br /&gt;
* Remove duplicated code.&lt;br /&gt;
* There were “custom_create” and “custom_update” methods for “custom” (multipart) rubrics. We already had create and update methods that were handling the normal rubrics. Our job was to use polymorphism in order to eliminate the custom methods.&lt;br /&gt;
&lt;br /&gt;
== Refactoring carried out ==&lt;br /&gt;
As per the project requirements the following work was carried out :&lt;br /&gt;
&lt;br /&gt;
* The duplicated code has been refactored and put in a separate method which is called wherever required. This prevents redundancy.&lt;br /&gt;
* The variables set up in controller become automatically available to the views. Hence the repeated code from controller and view for finding the topic id signed up by a user/team has been deleted from controller and incorporated only in the response view. The following code snippet was removed from the response controller.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if !@map.contributor.nil?&lt;br /&gt;
        if @map.assignment.team_assignment?&lt;br /&gt;
          team_member = TeamsUser.find_by_team_id(@map.contributor).user_id&lt;br /&gt;
          @topic_id = Participant.find_by_parent_id_and_user_id(@map.assignment.id,team_member).topic_id&lt;br /&gt;
        else&lt;br /&gt;
          @topic_id = Participant.find(@map.contributor).topic_id&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
if !@topic_id.nil?&lt;br /&gt;
        @signedUpTopic = SignUpTopic.find(@topic_id).topic_name&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because , similar code existed in the response view&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% if !@map.contributor.nil?%&amp;gt;&lt;br /&gt;
  &amp;lt;%if @map.assignment.team_assignment?&lt;br /&gt;
        team_member = TeamsUser.find_by_team_id(@map.contributor).user_id&lt;br /&gt;
        topic_id = Participant.find_by_parent_id_and_user_id(@map.assignment.id,team_member).topic_id&lt;br /&gt;
    else%&amp;gt;&lt;br /&gt;
        &amp;lt;% topic_id = Participant.find(@map.contributor).topic_id%&amp;gt;&lt;br /&gt;
  &amp;lt;%end%&amp;gt;  &lt;br /&gt;
  &amp;lt;%if !topic_id.nil?%&amp;gt;&lt;br /&gt;
    &amp;lt;h2&amp;gt;You are reviewing &amp;lt;%=SignUpTopic.find(topic_id).topic_name%&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
  &amp;lt;%end%&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* We created a new method in order to find the latest response thereby by eliminating the need to reuse the following code multiple times.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def latestResponseVersion&lt;br /&gt;
    #get all previous versions of responses for the response map.&lt;br /&gt;
    array_not_empty=0&lt;br /&gt;
    @review_scores=Array.new&lt;br /&gt;
    @prev=Response.find_by_map_id(@map.id)&lt;br /&gt;
    for element in @prev&lt;br /&gt;
      array_not_empty=1&lt;br /&gt;
      @review_scores &amp;lt;&amp;lt; element&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The custom create and custom update methods have been removed. Their functionality has been merged with create and update methods as was mentioned in the requirement specification. Depending on the type of rubric rendered, the create and update method does the necessary updations.&lt;br /&gt;
&lt;br /&gt;
== Testing Done ==&lt;br /&gt;
&lt;br /&gt;
Integration tests for capybara were created for the scenarios describing admin login, creation of an assignment by admin and user login.&lt;br /&gt;
&lt;br /&gt;
==Future Work ==&lt;br /&gt;
=== Design Changes ===&lt;br /&gt;
* An even better way to handle the rubrics would be to do subclassing of the questionnaire model in order to create two sub classes the rating rubric and the multipart rubric. As per the rubric being rendered the appropriate class would be called. This method would be much more efficient than the current way the functionality is being handled also it would be more O-O like.&lt;br /&gt;
&lt;br /&gt;
=== Further Refactoring ===&lt;br /&gt;
Given the current state of the response controller there is still a lot of work that can be done in order to further improve the code. Based on our findings the following things can be done :&lt;br /&gt;
* The controller still has some code that is only there for some specific assignments. This is bad design and this code needs to be removed.&lt;br /&gt;
&lt;br /&gt;
* The purpose of saving method is not quite clear. It predominantly has the code for an assignment '562' which has been hard coded and can be removed.&lt;br /&gt;
&lt;br /&gt;
* The rubric model has been created but has not been used anywhere in the code.&lt;br /&gt;
&lt;br /&gt;
== Appendix ==&lt;br /&gt;
=== Setup Process ===&lt;br /&gt;
* We cloned the repo from https://github.com/expertiza/expertiza into our local directory.&lt;br /&gt;
* After installing MySQL server we loaded the test-db.sql sample database into the application.&lt;br /&gt;
* Next we created our own users and a new assignment to understand the working of the response controller.&lt;br /&gt;
* First of all, an admin needs to create a minimum of two users who will participate in the same assignment. &lt;br /&gt;
* The admin needs to create one assignment and add participants to the assignment. Further details of the assignment need to be added as necessary such as due dates, review strategy etc.&lt;br /&gt;
* Review strategy can be auto selected or student selected. If the TA or instructor is manually assigning the assignments for review, it has to be “instructor selected”. &lt;br /&gt;
* Check the &amp;quot;Due dates&amp;quot; tab and check if the review is allowed at the current date. Update due dates so that the review date starts after the submission date is passed. Save dependencies.&lt;br /&gt;
* Add a signup sheet to the assignment. This sheet will display topics which the users can select to review.&lt;br /&gt;
* Now, login through user1 account and select an assignment. Then sign up for one topic from the list of available topics.&lt;br /&gt;
* After that, user1 needs to submit a hyperlink.&lt;br /&gt;
* Now, login through user2 credentials. User2 must select the assignment(of which it was made a participant by the admin).&lt;br /&gt;
* User2 must go to the student_task page and select the link &amp;quot;other's work&amp;quot; which will be enabled only if a particular topic of an assignment has review_allowed to be true, that means the deadline should be properly configured by the admin. &lt;br /&gt;
&lt;br /&gt;
* After that, response view would be rendered to the reviewer.&lt;br /&gt;
* The reviewer would review the assignment submitted by user1. Once the review has been saved, user1 will have an option to provide feedback on the review.&lt;br /&gt;
* If meta reviews have been enabled by the admin, then the other participants will be able to see the reviews of other users.&lt;br /&gt;
&lt;br /&gt;
=== Issues Encountered ===&lt;br /&gt;
&lt;br /&gt;
* In order to get the application working properly we added several routes to the routes.rb file.&lt;br /&gt;
* Assignment submission status was not being changed in spite of changing the deadline due-dates in the edit assignment section of the admin.&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
:1. [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza]&lt;br /&gt;
&lt;br /&gt;
:2. [http://152.7.99.43:3000/ VCL Link]&lt;br /&gt;
&lt;br /&gt;
:3. [https://github.com/nixtish/expertiza Git repository]&lt;br /&gt;
&lt;br /&gt;
:4. [https://docs.google.com/a/ncsu.edu/document/d/1Z0xjFZu-Zy-xm73YyUVUgFCtfWgRwhN1rZuThoyF-U0/edit Steps to setup Expertiza]&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ans&amp;diff=81942</id>
		<title>CSC/ECE 517 Fall 2013/oss ans</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_ans&amp;diff=81942"/>
		<updated>2013-10-31T01:59:07Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* Issues Encountered */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''' E807 : Refactoring and testing response_controller.rb''' &lt;br /&gt;
&lt;br /&gt;
== Project Description == &lt;br /&gt;
The response controller creates, edits, and displays responses, that is, rubrics to be filled out, or filled-out rubrics. Our project requirement entailed the following things to be done.&lt;br /&gt;
&lt;br /&gt;
* Reduce the method complexity in the response controller.&lt;br /&gt;
* Remove duplicated code.&lt;br /&gt;
* There were “custom_create” and “custom_update” methods for “custom” (multipart) rubrics. We already had create and update methods that were handling the normal rubrics. Our job was to use polymorphism in order to eliminate the custom methods.&lt;br /&gt;
&lt;br /&gt;
== Refactoring carried out ==&lt;br /&gt;
As per the project requirements the following work was carried out :&lt;br /&gt;
&lt;br /&gt;
* The duplicated code has been refactored and put in a separate method which is called wherever required. This prevents redundancy.&lt;br /&gt;
* The variables set up in controller become automatically available to the views. Hence the repeated code from controller and view for finding the topic id signed up by a user/team has been deleted from controller and incorporated only in the response view. The following code snippet was removed from the response controller.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if !@map.contributor.nil?&lt;br /&gt;
        if @map.assignment.team_assignment?&lt;br /&gt;
          team_member = TeamsUser.find_by_team_id(@map.contributor).user_id&lt;br /&gt;
          @topic_id = Participant.find_by_parent_id_and_user_id(@map.assignment.id,team_member).topic_id&lt;br /&gt;
        else&lt;br /&gt;
          @topic_id = Participant.find(@map.contributor).topic_id&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
if !@topic_id.nil?&lt;br /&gt;
        @signedUpTopic = SignUpTopic.find(@topic_id).topic_name&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because , similar code existed in the response view&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% if !@map.contributor.nil?%&amp;gt;&lt;br /&gt;
  &amp;lt;%if @map.assignment.team_assignment?&lt;br /&gt;
        team_member = TeamsUser.find_by_team_id(@map.contributor).user_id&lt;br /&gt;
        topic_id = Participant.find_by_parent_id_and_user_id(@map.assignment.id,team_member).topic_id&lt;br /&gt;
    else%&amp;gt;&lt;br /&gt;
        &amp;lt;% topic_id = Participant.find(@map.contributor).topic_id%&amp;gt;&lt;br /&gt;
  &amp;lt;%end%&amp;gt;  &lt;br /&gt;
  &amp;lt;%if !topic_id.nil?%&amp;gt;&lt;br /&gt;
    &amp;lt;h2&amp;gt;You are reviewing &amp;lt;%=SignUpTopic.find(topic_id).topic_name%&amp;gt;&amp;lt;/h2&amp;gt;&lt;br /&gt;
  &amp;lt;%end%&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* We created a new method in order to find the latest response thereby by eliminating the need to reuse the following code multiple times.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def latestResponseVersion&lt;br /&gt;
    #get all previous versions of responses for the response map.&lt;br /&gt;
    array_not_empty=0&lt;br /&gt;
    @review_scores=Array.new&lt;br /&gt;
    @prev=Response.find_by_map_id(@map.id)&lt;br /&gt;
    for element in @prev&lt;br /&gt;
      array_not_empty=1&lt;br /&gt;
      @review_scores &amp;lt;&amp;lt; element&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The custom create and custom update methods have been removed. Their functionality has been merged with create and update methods as was mentioned in the requirement specification. Depending on the type of rubric rendered, the create and update method does the necessary updations.&lt;br /&gt;
&lt;br /&gt;
== Testing Done ==&lt;br /&gt;
&lt;br /&gt;
Capybara tests were created for the response controller in order to carry out integration testing.&lt;br /&gt;
&lt;br /&gt;
==Future Work ==&lt;br /&gt;
=== Design Changes ===&lt;br /&gt;
* An even better way to handle the rubrics would be to do subclassing of the questionnaire model in order to create two sub classes the rating rubric and the multipart rubric. As per the rubric being rendered the appropriate class would be called. This method would be much more efficient than the current way the functionality is being handled also it would be more O-O like.&lt;br /&gt;
&lt;br /&gt;
=== Further Refactoring ===&lt;br /&gt;
Given the current state of the response controller there is still a lot of work that can be done in order to further improve the code. Based on our findings the following things can be done :&lt;br /&gt;
* The controller still has some code that is only there for some specific assignments. This is bad design and this code needs to be removed.&lt;br /&gt;
&lt;br /&gt;
* The purpose of saving method is not quite clear. It predominantly has the code for an assignment '562' which has been hard coded and can be removed.&lt;br /&gt;
&lt;br /&gt;
* The rubric model has been created but has not been used anywhere in the code.&lt;br /&gt;
&lt;br /&gt;
== Appendix ==&lt;br /&gt;
=== Setup Process ===&lt;br /&gt;
* We cloned the repo from https://github.com/expertiza/expertiza into our local directory.&lt;br /&gt;
* After installing MySQL server we loaded the test-db.sql sample database into the application.&lt;br /&gt;
* Next we created our own users and a new assignment to understand the working of the response controller.&lt;br /&gt;
* First of all, an admin needs to create a minimum of two users who will participate in the same assignment. &lt;br /&gt;
* The admin needs to create one assignment and add participants to the assignment. Further details of the assignment need to be added as necessary such as due dates, review strategy etc.&lt;br /&gt;
* Review strategy can be auto selected or student selected. If the TA or instructor is manually assigning the assignments for review, it has to be “instructor selected”. &lt;br /&gt;
* Check the &amp;quot;Due dates&amp;quot; tab and check if the review is allowed at the current date. Update due dates so that the review date starts after the submission date is passed. Save dependencies.&lt;br /&gt;
* Add a signup sheet to the assignment. This sheet will display topics which the users can select to review.&lt;br /&gt;
* Now, login through user1 account and select an assignment. Then sign up for one topic from the list of available topics.&lt;br /&gt;
* After that, user1 needs to submit a hyperlink.&lt;br /&gt;
* Now, login through user2 credentials. User2 must select the assignment(of which it was made a participant by the admin).&lt;br /&gt;
* User2 must go to the student_task page and select the link &amp;quot;other's work&amp;quot; which will be enabled only if a particular topic of an assignment has review_allowed to be true, that means the deadline should be properly configured by the admin. &lt;br /&gt;
&lt;br /&gt;
* After that, response view would be rendered to the reviewer.&lt;br /&gt;
* The reviewer would review the assignment submitted by user1. Once the review has been saved, user1 will have an option to provide feedback on the review.&lt;br /&gt;
* If meta reviews have been enabled by the admin, then the other participants will be able to see the reviews of other users.&lt;br /&gt;
&lt;br /&gt;
=== Issues Encountered ===&lt;br /&gt;
&lt;br /&gt;
* In order to get the application working properly we added several routes to the routes.rb file.&lt;br /&gt;
* Assignment submission status was not being changed in spite of changing the deadline due-dates in the edit assignment section of the admin.&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
:1. [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza]&lt;br /&gt;
&lt;br /&gt;
:2. [http://152.7.99.43:3000/ VCL Link]&lt;br /&gt;
&lt;br /&gt;
:3. [https://github.com/nixtish/expertiza Git repository]&lt;br /&gt;
&lt;br /&gt;
:4. [https://docs.google.com/a/ncsu.edu/document/d/1Z0xjFZu-Zy-xm73YyUVUgFCtfWgRwhN1rZuThoyF-U0/edit Steps to setup Expertiza]&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=79051</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=79051"/>
		<updated>2013-09-25T01:18:55Z</updated>

		<summary type="html">&lt;p&gt;Sandi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby [http://en.wikipedia.org/wiki/Computer_programming programming] world. This is indeed a very unique feature of Ruby. This article will help us [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w14_st#Understanding_the_Ruby_Object_Model understand the ruby object model], speak about it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Comparison_with_other_Object-Oriented_languages comparison to object models of other programming languages] and explain it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Advantages_of_the_Ruby_Object_Model advantages] and [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Disadvantages_of_the_Ruby_Object_Model disadvantages].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it is purely object-oriented, meaning it recognizes all of it's basic constructs as [http://en.wikipedia.org/wiki/Object_(computer_science) objects]. Everything that we manipulate and  even the results of the manipulations are also objects.&lt;br /&gt;
&lt;br /&gt;
In an [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] code, you look forward to model concepts from the real world in your code. For example, in a ''Theatre'', the concept of a &amp;quot;movie&amp;quot; is defined as a class and is a combination of states(e.g name of the movie) and methods that use that state(e.g play the movie). We can create instances of these classes, known as objects. For example, in the above example the instances would be the various movies. &lt;br /&gt;
&lt;br /&gt;
In Ruby, these objects are created a special method called a ''constructor'', a special method associated with a [http://en.wikipedia.org/wiki/Class_(computer_programming) class]. The standard constructor is called ''new''.&lt;br /&gt;
&lt;br /&gt;
  movie1 = Movie.new(&amp;quot;ABC PQR&amp;quot;)&lt;br /&gt;
  movie2 = Movie.new(&amp;quot;XYZ ABCD&amp;quot;) &lt;br /&gt;
&lt;br /&gt;
These instances are derived from the same class, but have unique characteristics. Every object has a unique ''object identifier'' and define instance variables that are unique to each instance, like &amp;quot;name&amp;quot; in our example.&lt;br /&gt;
You can define instance methods within each class. A method is a chunk of functionality that may be called from within a class or outside it, depending on the accessibility constraints.&lt;br /&gt;
&lt;br /&gt;
Whenever you call a method on an object, the [http://en.wikipedia.org/wiki/Interpreter_(computing) interpreter] first looks through the object’s instance methods to check if that particular method exists. If the interpreter finds the method, it will be executed but if that particular method does not exist, the interpreter will pass the request up the hierarchy to the object’s class. &lt;br /&gt;
&lt;br /&gt;
If the interpreter is not able to find the method anywhere in the hierarchy, it will go back to the object and call method_missing(). Again, the interpreter will look for method_missing() in the object’s methods, then the object’s class’s instance methods, following the hierarchy until it reaches the Object class where method_missing() is defined  and will raise a NoMethodError error. To change the default behavior, method_missing()can be defined within the class.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Sample&lt;br /&gt;
    def method_missing(name, *args)&lt;br /&gt;
      puts &amp;quot;#{name} was called with arguments: #{args.join(',')}&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
 m = Sample.new&lt;br /&gt;
 m.method1(&amp;quot;one&amp;quot;, &amp;quot;two&amp;quot;) &lt;br /&gt;
&lt;br /&gt;
There is no [http://en.wikipedia.org/wiki/Method_(computer_programming) method] named method1() within our class that we are trying to call. here, we don’t see the usual NoMethodError,and we see the name of the methods and their [http://en.wikipedia.org/wiki/Arguments arguments], just like we defined in method_missing().&lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that have numbers and [http://en.wikipedia.org/wiki/String_(computer_science)strings] calling in-built [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. &lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Displays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time by writing them in a chain. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
In the above examples the thing before the period is called the ''receiver'', and the name after the period is the method to be invoked. &lt;br /&gt;
&lt;br /&gt;
It's worth noting here a major difference between Ruby and most other languages:&lt;br /&gt;
&lt;br /&gt;
'''In JAVA''': To find the absolute value of a number, we can a separate function and pass the value of that number in that function.&lt;br /&gt;
 Number = Math.abs(number)   // Java Code&lt;br /&gt;
'''In RUBY''': The ability to determine the absolute value is built into numbers(which are also objects) internally.&lt;br /&gt;
 number = number.abs       # Ruby Code&lt;br /&gt;
&lt;br /&gt;
This is the reason behind why Ruby is called a purely object oriented language.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object Hierarchy of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an [http://en.wikipedia.org/wiki/Instance_(computer_science) instance] of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a [http://en.wikipedia.org/wiki/Message_passing message] to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second [http://en.wikipedia.org/wiki/Parameter_(computer_programming) parameter] evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send is a very important concept in the Ruby object model as almost all actions in Ruby, atleast conceptually, boils down to sending a message to an object.&lt;br /&gt;
&lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''&amp;quot;Class&amp;quot;''. Classes are defined in Ruby using the ''class'' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as ''attr_accessor''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) extending] its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparison with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling of unused objects.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected [http://en.wikipedia.org/wiki/Access_modifiers access specifiers] for methods defined within objects.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports [http://en.wikipedia.org/wiki/Inheritance inheritance] of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses [http://en.wikipedia.org/wiki/Interfaces_(computer_science) interfaces] for defining empty methods which are later handled by [http://en.wikipedia.org/wiki/Concrete_class#Abstract_and_Concrete concrete class] objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, [http://en.wikipedia.org/wiki/Constructor_(object-oriented_programming) constructor] is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are [http://en.wikipedia.org/wiki/Immutable_object immutable] (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and methods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behavior of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a [http://en.wikipedia.org/wiki/Compile_time compile-time] entity. || A ruby class is a [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run-time] entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
|C++ does not need a base class as it supports [http://en.wikipedia.org/wiki/Generic_programming generic programming]. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the open and close braces.&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_classes.html Objects and Classes in Ruby] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://fhwang.net/2004/11/14/Coming-to-Ruby-from-Java Coming to Ruby from Java]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://staff.science.uva.nl/~heck/JAVAcourse/ch3/s1.html Class Hierarchies] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://stackoverflow.com/questions/4688467/class-vs-object-hierarchies Understanding the difference between an object and a class hierarchy]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=79026</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=79026"/>
		<updated>2013-09-25T00:44:19Z</updated>

		<summary type="html">&lt;p&gt;Sandi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby [http://en.wikipedia.org/wiki/Computer_programming programming] world. This is indeed a very unique feature of Ruby. This article will help us [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w14_st#Understanding_the_Ruby_Object_Model understand the ruby object model], speak about it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Comparison_with_other_Object-Oriented_languages comparison to object models of other programming languages] and explain it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Advantages_of_the_Ruby_Object_Model advantages] and [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Disadvantages_of_the_Ruby_Object_Model disadvantages].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it is purely object-oriented, meaning it recognizes all of it's basic constructs as objects. Everything that we manipulate and  even the results of the manipulations are also objects.&lt;br /&gt;
&lt;br /&gt;
In an [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] code, you look forward to model concepts from the real world in your code. For example, in a ''Theatre'', the concept of a &amp;quot;movie&amp;quot; is defined as a class and is a combination of states(e.g name of the movie) and methods that use that state(e.g play the movie). We can create instances of these classes, known as objects. For example, in the above example the instances would be the various movies. &lt;br /&gt;
&lt;br /&gt;
In Ruby, these objects are created a special method called a ''constructor'', a special method associated with a class. The standard constructor is called ''new''.&lt;br /&gt;
&lt;br /&gt;
  movie1 = Movie.new(&amp;quot;ABC PQR&amp;quot;)&lt;br /&gt;
  movie2 = Movie.new(&amp;quot;XYZ ABCD&amp;quot;) &lt;br /&gt;
&lt;br /&gt;
These instances are derived from the same class, but they have unique characteristics. Every object has a unique ''object identifier'' and define instance variables that are unique to each instance, like &amp;quot;title&amp;quot; in our example.&lt;br /&gt;
&lt;br /&gt;
Within each class, you can define instance methods. Each method is a chunk of functionality that may be called from whithin a class or outside it depending on the accessibility constraints.&lt;br /&gt;
&lt;br /&gt;
Whenever you call a method on an object, the interpreter first looks through the object’s instance methods to check if that particular method exists. If the interpreter finds the method, it will be executed but if that particular method does not exist, the interpreter will pass the request up the hierarchy to the object’s class. &lt;br /&gt;
&lt;br /&gt;
If the interpreter is not able to find the method anywhere up the object’s chain of inheritance, it will go back to the object and call another method called method_missing(). Like earlier, the interpreter will look for method_missing() in the object’s methods, then the object’s class’s instance methods etc. until it reaches the Object class where method_missing() is defined  and will raise a NoMethodError error. To change the default behaviour,method_missing()can be defined within the class.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Sample&lt;br /&gt;
    def method_missing(name, *args)&lt;br /&gt;
      puts &amp;quot;#{name} was called with arguments: #{args.join(',')}&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
 m = Sample.new&lt;br /&gt;
 m.method1(&amp;quot;one&amp;quot;, &amp;quot;two&amp;quot;) &lt;br /&gt;
&lt;br /&gt;
There is no [http://en.wikipedia.org/wiki/Method_(computer_programming) method] named method1() within our class that we are trying to call. here, we don’t see the usual NoMethodError,and we see the name of the methods and their [http://en.wikipedia.org/wiki/Arguments arguments], just like we defined in method_missing().&lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that have numbers and [http://en.wikipedia.org/wiki/String_(computer_science)strings] calling in-built [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. &lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Displays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time by writing them in a chain. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
In the above examples the thing before the period is called the ''receiver'', and the name after the period is the method to be invoked. &lt;br /&gt;
&lt;br /&gt;
It's worth noting here a major difference between Ruby and most other languages:&lt;br /&gt;
&lt;br /&gt;
'''In JAVA''': To find the absolute value of a number, we can a separate function and pass the value of that number in that function.&lt;br /&gt;
 Number = Math.abs(number)   // Java Code&lt;br /&gt;
'''In RUBY''': The ability to determine the absolute value is built into numbers(which are also objects) internally.&lt;br /&gt;
 number = number.abs       # Ruby Code&lt;br /&gt;
&lt;br /&gt;
This is the reason behind why Ruby is called a purely object oriented language.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object Hierarchy of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send is a veryimportant concept in the Ruby object model as almost all actions in Ruby, atleast conceptually, boils down to sending a message to an object.&lt;br /&gt;
&lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''&amp;quot;Class&amp;quot;''. Classes are defined in Ruby using the ''class'' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as ''attr_accessor''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparison with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling of unused objects.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected [http://en.wikipedia.org/wiki/Access_modifiers access specifiers] for methods defined within objects.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports [http://en.wikipedia.org/wiki/Inheritance inheritance] of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses [http://en.wikipedia.org/wiki/Interfaces_(computer_science) interfaces] for defining empty methods which are later handled by [http://en.wikipedia.org/wiki/Concrete_class#Abstract_and_Concrete concrete class] objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, [http://en.wikipedia.org/wiki/Constructor_(object-oriented_programming) constructor] is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are [http://en.wikipedia.org/wiki/Immutable_object immutable] (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behavior of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a [http://en.wikipedia.org/wiki/Compile_time compile-time] entity. || A ruby class is a [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run-time] entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
|C++ does not need a base class as it supports [http://en.wikipedia.org/wiki/Generic_programming generic programming]. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the open and close braces.&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_classes.html Objects and Classes in Ruby] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://fhwang.net/2004/11/14/Coming-to-Ruby-from-Java Coming to Ruby from Java]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://staff.science.uva.nl/~heck/JAVAcourse/ch3/s1.html Class Hierarchies] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://stackoverflow.com/questions/4688467/class-vs-object-hierarchies Understanding the difference between an object and a class hierarchy]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=79016</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=79016"/>
		<updated>2013-09-25T00:34:14Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* Ruby Object Model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby [http://en.wikipedia.org/wiki/Computer_programming programming] world. This is indeed a very unique feature of Ruby. This article will help us [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w14_st#Understanding_the_Ruby_Object_Model understand the ruby object model], speak about it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Comparison_with_other_Object-Oriented_languages comparison to object models of other programming languages] and explain it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Advantages_of_the_Ruby_Object_Model advantages] and [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Disadvantages_of_the_Ruby_Object_Model disadvantages].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it is purely object-oriented, meaning it recognizes all of it's basic constructs as objects. Everything that we manipulate and  even the results of the manipulations are also objects.&lt;br /&gt;
&lt;br /&gt;
In an object-oriented code, you look forward to model concepts from the real world in your code. For example, in a ''Theatre'', the concept of a &amp;quot;movie&amp;quot; is defined as a class and is a combination of states(e.g name of the movie) and methods that use that state(e.g play the movie). We can create instances of these classes, known as objects. For example, in the above example the instances would be the various movies. &lt;br /&gt;
&lt;br /&gt;
In Ruby, these objects are created a special method called a ''constructor'', a special method associated with a class. The standard constructor is called ''new''.&lt;br /&gt;
&lt;br /&gt;
  movie1 = Movie.new(&amp;quot;ABC PQR&amp;quot;)&lt;br /&gt;
  movie2 = Movie.new(&amp;quot;XYZ ABCD&amp;quot;) &lt;br /&gt;
&lt;br /&gt;
These instances are derived from the same class, but they have unique characteristics. Every object has a unique ''object identifier'' and define instance variables that are unique to each instance, like &amp;quot;title&amp;quot; in our example.&lt;br /&gt;
&lt;br /&gt;
Within each class, you can define instance methods. Each method is a chunk of functionality that may be called from whithin a class or outside it depending on the accessibility constraints.&lt;br /&gt;
&lt;br /&gt;
Whenever you call a method on an object, the interpreter first looks through the object’s instance methods to check if that particular method exists. If the interpreter finds the method, it will be executed but if that particular method does not exist, the interpreter will pass the request up the hierarchy to the object’s class. &lt;br /&gt;
&lt;br /&gt;
If the interpreter is not able to find the method anywhere up the object’s chain of inheritance, it will go back to the object and call another method called method_missing(). Like earlier, the interpreter will look for method_missing() in the object’s methods, then the object’s class’s instance methods etc. until it reaches the Object class where method_missing() is defined  and will raise a NoMethodError error. To change the default behaviour,method_missing()can be defined within the class.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Sample&lt;br /&gt;
    def method_missing(name, *args)&lt;br /&gt;
      puts &amp;quot;#{name} was called with arguments: #{args.join(',')}&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
 m = Sample.new&lt;br /&gt;
 m.method1(&amp;quot;one&amp;quot;, &amp;quot;two&amp;quot;) &lt;br /&gt;
&lt;br /&gt;
There is no method named method1() within our class that we are trying to call. here, we don’t see the usual NoMethodError,and we see the name of the methods and their arguments, just like we defined in method_missing().&lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that have numbers and strings calling in-built [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. &lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Displays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time by writing them in a chain. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
In the above examples the thing before the period is called the ''receiver'', and the name after the period is the method to be invoked. &lt;br /&gt;
&lt;br /&gt;
It's worth noting here a major difference between Ruby and most other languages:&lt;br /&gt;
&lt;br /&gt;
'''In JAVA''': To find the absolute value of a number, we can a separate function and pass the value of that number in that function.&lt;br /&gt;
 Number = Math.abs(number)   // Java Code&lt;br /&gt;
'''In RUBY''': The ability to determine the absolute value is built into numbers(which are also objects) internally.&lt;br /&gt;
 number = number.abs       # Ruby Code&lt;br /&gt;
&lt;br /&gt;
This is the reason behind why Ruby is called a purely object oriented language.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object Hierarchy of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send is a veryimportant concept in the Ruby object model as almost all actions in Ruby, atleast conceptually, boils down to sending a message to an object.&lt;br /&gt;
&lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''&amp;quot;Class&amp;quot;''. Classes are defined in Ruby using the ''class'' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as ''attr_accessor''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparison with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling of unused objects.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected [http://en.wikipedia.org/wiki/Access_modifiers access specifiers] for methods defined within objects.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports [http://en.wikipedia.org/wiki/Inheritance inheritance] of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses [http://en.wikipedia.org/wiki/Interfaces_(computer_science) interfaces] for defining empty methods which are later handled by [http://en.wikipedia.org/wiki/Concrete_class#Abstract_and_Concrete concrete class] objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, [http://en.wikipedia.org/wiki/Constructor_(object-oriented_programming) constructor] is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are [http://en.wikipedia.org/wiki/Immutable_object immutable] (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behavior of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a [http://en.wikipedia.org/wiki/Compile_time compile-time] entity. || A ruby class is a [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run-time] entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
|C++ does not need a base class as it supports [http://en.wikipedia.org/wiki/Generic_programming generic programming]. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the open and close braces.&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_classes.html Objects and Classes in Ruby] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://fhwang.net/2004/11/14/Coming-to-Ruby-from-Java Coming to Ruby from Java]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://staff.science.uva.nl/~heck/JAVAcourse/ch3/s1.html Class Hierarchies] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://stackoverflow.com/questions/4688467/class-vs-object-hierarchies Understanding the difference between an object and a class hierarchy]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=79004</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=79004"/>
		<updated>2013-09-25T00:32:07Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* See Also */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will help us [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w14_st#Understanding_the_Ruby_Object_Model understand the ruby object model], speak about it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Comparison_with_other_Object-Oriented_languages comparison to object models of other programming languages] and explain it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Advantages_of_the_Ruby_Object_Model advantages] and [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Disadvantages_of_the_Ruby_Object_Model disadvantages].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it is purely object-oriented, meaning it recognizes all of it's basic constructs as objects. Everything that we manipulate and  even the results of the manipulations are also objects.&lt;br /&gt;
&lt;br /&gt;
In an object-oriented code, you look forward to model concepts from the real world in your code. For example, in a ''Theatre'', the concept of a &amp;quot;movie&amp;quot; is defined as a class and is a combination of states(e.g name of the movie) and methods that use that state(e.g play the movie). We can create instances of these classes, known as objects. For example, in the above example the instances would be the various movies. &lt;br /&gt;
&lt;br /&gt;
In Ruby, these objects are created a special method called a ''constructor'', a special method associated with a class. The standard constructor is called ''new''.&lt;br /&gt;
&lt;br /&gt;
  movie1 = Movie.new(&amp;quot;ABC PQR&amp;quot;)&lt;br /&gt;
  movie2 = Movie.new(&amp;quot;XYZ ABCD&amp;quot;) &lt;br /&gt;
&lt;br /&gt;
These instances are derived from the same class, but they have unique characteristics. Every object has a unique ''object identifier'' and define instance variables that are unique to each instance, like &amp;quot;title&amp;quot; in our example.&lt;br /&gt;
&lt;br /&gt;
Within each class, you can define instance methods. Each method is a chunk of functionality that may be called from whithin a class or outside it depending on the accessibility constraints.&lt;br /&gt;
&lt;br /&gt;
Whenever you call a method on an object, the interpreter first looks through the object’s instance methods to check if that particular method exists. If the interpreter finds the method, it will be executed but if that particular method does not exist, the interpreter will pass the request up the hierarchy to the object’s class. &lt;br /&gt;
&lt;br /&gt;
If the interpreter is not able to find the method anywhere up the object’s chain of inheritance, it will go back to the object and call another method called method_missing(). Like earlier, the interpreter will look for method_missing() in the object’s methods, then the object’s class’s instance methods etc. until it reaches the Object class where method_missing() is defined  and will raise a NoMethodError error. To change the default behaviour,method_missing()can be defined within the class.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Sample&lt;br /&gt;
    def method_missing(name, *args)&lt;br /&gt;
      puts &amp;quot;#{name} was called with arguments: #{args.join(',')}&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
 m = Sample.new&lt;br /&gt;
 m.method1(&amp;quot;one&amp;quot;, &amp;quot;two&amp;quot;) &lt;br /&gt;
&lt;br /&gt;
There is no method named method1() within our class that we are trying to call. here, we don’t see the usual NoMethodError,and we see the name of the methods and their arguments, just like we defined in method_missing().&lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that have numbers and strings calling in-built [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. &lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Displays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time by writing them in a chain. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
In the above examples the thing before the period is called the ''receiver'', and the name after the period is the method to be invoked. &lt;br /&gt;
&lt;br /&gt;
It's worth noting here a major difference between Ruby and most other languages:&lt;br /&gt;
&lt;br /&gt;
'''In JAVA''': To find the absolute value of a number, we can a separate function and pass the value of that number in that function.&lt;br /&gt;
 Number = Math.abs(number)   // Java Code&lt;br /&gt;
'''In RUBY''': The ability to determine the absolute value is built into numbers(which are also objects) internally.&lt;br /&gt;
 number = number.abs       # Ruby Code&lt;br /&gt;
&lt;br /&gt;
This is the reason behind why Ruby is called a purely object oriented language.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object Hierarchy of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send is a veryimportant concept in the Ruby object model as almost all actions in Ruby, atleast conceptually, boils down to sending a message to an object.&lt;br /&gt;
&lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''&amp;quot;Class&amp;quot;''. Classes are defined in Ruby using the ''class'' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as ''attr_accessor''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparison with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling of unused objects.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected [http://en.wikipedia.org/wiki/Access_modifiers access specifiers] for methods defined within objects.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports [http://en.wikipedia.org/wiki/Inheritance inheritance] of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses [http://en.wikipedia.org/wiki/Interfaces_(computer_science) interfaces] for defining empty methods which are later handled by [http://en.wikipedia.org/wiki/Concrete_class#Abstract_and_Concrete concrete class] objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, [http://en.wikipedia.org/wiki/Constructor_(object-oriented_programming) constructor] is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are [http://en.wikipedia.org/wiki/Immutable_object immutable] (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behavior of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a [http://en.wikipedia.org/wiki/Compile_time compile-time] entity. || A ruby class is a [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run-time] entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
|C++ does not need a base class as it supports [http://en.wikipedia.org/wiki/Generic_programming generic programming]. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the open and close braces.&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_classes.html Objects and Classes in Ruby] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://fhwang.net/2004/11/14/Coming-to-Ruby-from-Java Coming to Ruby from Java]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://staff.science.uva.nl/~heck/JAVAcourse/ch3/s1.html Class Hierarchies] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://stackoverflow.com/questions/4688467/class-vs-object-hierarchies Understanding the difference between an object and a class hierarchy]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=79000</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=79000"/>
		<updated>2013-09-25T00:31:40Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* See Also */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will help us [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w14_st#Understanding_the_Ruby_Object_Model understand the ruby object model], speak about it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Comparison_with_other_Object-Oriented_languages comparison to object models of other programming languages] and explain it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Advantages_of_the_Ruby_Object_Model advantages] and [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Disadvantages_of_the_Ruby_Object_Model disadvantages].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it is purely object-oriented, meaning it recognizes all of it's basic constructs as objects. Everything that we manipulate and  even the results of the manipulations are also objects.&lt;br /&gt;
&lt;br /&gt;
In an object-oriented code, you look forward to model concepts from the real world in your code. For example, in a ''Theatre'', the concept of a &amp;quot;movie&amp;quot; is defined as a class and is a combination of states(e.g name of the movie) and methods that use that state(e.g play the movie). We can create instances of these classes, known as objects. For example, in the above example the instances would be the various movies. &lt;br /&gt;
&lt;br /&gt;
In Ruby, these objects are created a special method called a ''constructor'', a special method associated with a class. The standard constructor is called ''new''.&lt;br /&gt;
&lt;br /&gt;
  movie1 = Movie.new(&amp;quot;ABC PQR&amp;quot;)&lt;br /&gt;
  movie2 = Movie.new(&amp;quot;XYZ ABCD&amp;quot;) &lt;br /&gt;
&lt;br /&gt;
These instances are derived from the same class, but they have unique characteristics. Every object has a unique ''object identifier'' and define instance variables that are unique to each instance, like &amp;quot;title&amp;quot; in our example.&lt;br /&gt;
&lt;br /&gt;
Within each class, you can define instance methods. Each method is a chunk of functionality that may be called from whithin a class or outside it depending on the accessibility constraints.&lt;br /&gt;
&lt;br /&gt;
Before going further, it is important that we understand the basics of Ruby’s Object Model and how Ruby deals with method calls.&lt;br /&gt;
&lt;br /&gt;
Whenever you call a method on an object, the interpreter first looks through the object’s instance methods to check if that particular method exists. If the interpreter can find the method, it will execute it as expected but if that particular method does not exists, it will pass the request up the chain to the object’s class. If it can’t find the method there it will continue to look in that class’s parent class, then the parent’s parent etc. up to the Object class itself.&lt;br /&gt;
&lt;br /&gt;
In the end, if the interpreter is not able to find the method anywhere up the object’s chain of inheritance, it will go back to the object and call another method called method_missing(). Just like with our first method, the interpreter looks for method_missing() in the object’s methods, then the object’s class’s instance methods etc. until it reaches the Object class where method_missing() is defined  and will raise a NoMethodError error. By defining method_missing() yourself within a class, it’s possible to change this default behaviour.  &lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Sample&lt;br /&gt;
    def method_missing(name, *args)&lt;br /&gt;
      puts &amp;quot;#{name} was called with arguments: #{args.join(',')}&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
 m = Sample.new&lt;br /&gt;
 m.method1(&amp;quot;one&amp;quot;, &amp;quot;two&amp;quot;) &lt;br /&gt;
&lt;br /&gt;
There is no method named method1() within our class that we are trying to call. here, we don’t see the usual NoMethodError,and we see the name of the methods and their arguments, just like we defined in method_missing().&lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that have numbers and strings calling in-built [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. &lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Displays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time by writing them in a chain. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
In the above examples the thing before the period is called the ''receiver'', and the name after the period is the method to be invoked. &lt;br /&gt;
&lt;br /&gt;
It's worth noting here a major difference between Ruby and most other languages:&lt;br /&gt;
&lt;br /&gt;
'''In JAVA''': To find the absolute value of a number, we can a separate function and pass the value of that number in that function.&lt;br /&gt;
 Number = Math.abs(number)   // Java Code&lt;br /&gt;
'''In RUBY''': The ability to determine the absolute value is built into numbers(which are also objects) internally.&lt;br /&gt;
 number = number.abs       # Ruby Code&lt;br /&gt;
&lt;br /&gt;
This is the reason behind why Ruby is called a purely object oriented language.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object Hierarchy of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send is a veryimportant concept in the Ruby object model as almost all actions in Ruby, atleast conceptually, boils down to sending a message to an object.&lt;br /&gt;
&lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''&amp;quot;Class&amp;quot;''. Classes are defined in Ruby using the ''class'' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as ''attr_accessor''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparison with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling of unused objects.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected [http://en.wikipedia.org/wiki/Access_modifiers access specifiers] for methods defined within objects.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports [http://en.wikipedia.org/wiki/Inheritance inheritance] of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses [http://en.wikipedia.org/wiki/Interfaces_(computer_science) interfaces] for defining empty methods which are later handled by [http://en.wikipedia.org/wiki/Concrete_class#Abstract_and_Concrete concrete class] objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, [http://en.wikipedia.org/wiki/Constructor_(object-oriented_programming) constructor] is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are [http://en.wikipedia.org/wiki/Immutable_object immutable] (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behavior of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a [http://en.wikipedia.org/wiki/Compile_time compile-time] entity. || A ruby class is a [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run-time] entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
|C++ does not need a base class as it supports [http://en.wikipedia.org/wiki/Generic_programming generic programming]. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the open and close braces.&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_classes.html Objects and Classes in Ruby] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://fhwang.net/2004/11/14/Coming-to-Ruby-from-Java Coming to Ruby from Java]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://staff.science.uva.nl/~heck/JAVAcourse/ch3/s1.html Class Hierarchies]&lt;br /&gt;
[http://stackoverflow.com/questions/4688467/class-vs-object-hierarchies Understanding the difference between an object and a class hierarchy]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78996</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78996"/>
		<updated>2013-09-25T00:29:25Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* See Also */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will help us [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w14_st#Understanding_the_Ruby_Object_Model understand the ruby object model], speak about it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Comparison_with_other_Object-Oriented_languages comparison to object models of other programming languages] and explain it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Advantages_of_the_Ruby_Object_Model advantages] and [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Disadvantages_of_the_Ruby_Object_Model disadvantages].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it is purely object-oriented, meaning it recognizes all of it's basic constructs as objects. Everything that we manipulate and  even the results of the manipulations are also objects.&lt;br /&gt;
&lt;br /&gt;
In an object-oriented code, you look forward to model concepts from the real world in your code. For example, in a ''Theatre'', the concept of a &amp;quot;movie&amp;quot; is defined as a class and is a combination of states(e.g name of the movie) and methods that use that state(e.g play the movie). We can create instances of these classes, known as objects. For example, in the above example the instances would be the various movies. &lt;br /&gt;
&lt;br /&gt;
In Ruby, these objects are created a special method called a ''constructor'', a special method associated with a class. The standard constructor is called ''new''.&lt;br /&gt;
&lt;br /&gt;
  movie1 = Movie.new(&amp;quot;ABC PQR&amp;quot;)&lt;br /&gt;
  movie2 = Movie.new(&amp;quot;XYZ ABCD&amp;quot;) &lt;br /&gt;
&lt;br /&gt;
These instances are derived from the same class, but they have unique characteristics. Every object has a unique ''object identifier'' and define instance variables that are unique to each instance, like &amp;quot;title&amp;quot; in our example.&lt;br /&gt;
&lt;br /&gt;
Within each class, you can define instance methods. Each method is a chunk of functionality that may be called from whithin a class or outside it depending on the accessibility constraints.&lt;br /&gt;
&lt;br /&gt;
Before going further, it is important that we understand the basics of Ruby’s Object Model and how Ruby deals with method calls.&lt;br /&gt;
&lt;br /&gt;
Whenever you call a method on an object, the interpreter first looks through the object’s instance methods to check if that particular method exists. If the interpreter can find the method, it will execute it as expected but if that particular method does not exists, it will pass the request up the chain to the object’s class. If it can’t find the method there it will continue to look in that class’s parent class, then the parent’s parent etc. up to the Object class itself.&lt;br /&gt;
&lt;br /&gt;
In the end, if the interpreter is not able to find the method anywhere up the object’s chain of inheritance, it will go back to the object and call another method called method_missing(). Just like with our first method, the interpreter looks for method_missing() in the object’s methods, then the object’s class’s instance methods etc. until it reaches the Object class where method_missing() is defined  and will raise a NoMethodError error. By defining method_missing() yourself within a class, it’s possible to change this default behaviour.  &lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Sample&lt;br /&gt;
    def method_missing(name, *args)&lt;br /&gt;
      puts &amp;quot;#{name} was called with arguments: #{args.join(',')}&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
 m = Sample.new&lt;br /&gt;
 m.method1(&amp;quot;one&amp;quot;, &amp;quot;two&amp;quot;) &lt;br /&gt;
&lt;br /&gt;
There is no method named method1() within our class that we are trying to call. here, we don’t see the usual NoMethodError,and we see the name of the methods and their arguments, just like we defined in method_missing().&lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that have numbers and strings calling in-built [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. &lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Displays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time by writing them in a chain. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
In the above examples the thing before the period is called the ''receiver'', and the name after the period is the method to be invoked. &lt;br /&gt;
&lt;br /&gt;
It's worth noting here a major difference between Ruby and most other languages:&lt;br /&gt;
&lt;br /&gt;
'''In JAVA''': To find the absolute value of a number, we can a separate function and pass the value of that number in that function.&lt;br /&gt;
 Number = Math.abs(number)   // Java Code&lt;br /&gt;
'''In RUBY''': The ability to determine the absolute value is built into numbers(which are also objects) internally.&lt;br /&gt;
 number = number.abs       # Ruby Code&lt;br /&gt;
&lt;br /&gt;
This is the reason behind why Ruby is called a purely object oriented language.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object Hierarchy of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send is a veryimportant concept in the Ruby object model as almost all actions in Ruby, atleast conceptually, boils down to sending a message to an object.&lt;br /&gt;
&lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''&amp;quot;Class&amp;quot;''. Classes are defined in Ruby using the ''class'' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as ''attr_accessor''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparison with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling of unused objects.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected [http://en.wikipedia.org/wiki/Access_modifiers access specifiers] for methods defined within objects.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports [http://en.wikipedia.org/wiki/Inheritance inheritance] of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses [http://en.wikipedia.org/wiki/Interfaces_(computer_science) interfaces] for defining empty methods which are later handled by [http://en.wikipedia.org/wiki/Concrete_class#Abstract_and_Concrete concrete class] objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, [http://en.wikipedia.org/wiki/Constructor_(object-oriented_programming) constructor] is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are [http://en.wikipedia.org/wiki/Immutable_object immutable] (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behavior of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a [http://en.wikipedia.org/wiki/Compile_time compile-time] entity. || A ruby class is a [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run-time] entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
|C++ does not need a base class as it supports [http://en.wikipedia.org/wiki/Generic_programming generic programming]. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the open and close braces.&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_classes.html Objects and Classes in Ruby] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://fhwang.net/2004/11/14/Coming-to-Ruby-from-Java Coming to Ruby from Java]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://staff.science.uva.nl/~heck/JAVAcourse/ch3/s1.html Class Hierarchies]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78991</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78991"/>
		<updated>2013-09-25T00:23:54Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* See Also */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will help us [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w14_st#Understanding_the_Ruby_Object_Model understand the ruby object model], speak about it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Comparison_with_other_Object-Oriented_languages comparison to object models of other programming languages] and explain it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Advantages_of_the_Ruby_Object_Model advantages] and [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Disadvantages_of_the_Ruby_Object_Model disadvantages].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it is purely object-oriented meaning it recognizes all of it's basic constructs as objects. Everything we manipulate is an object and the results of those manipulations are themselves objects.&lt;br /&gt;
&lt;br /&gt;
When you write an object-oriented code, you look forward to model concepts from the real world in your code. During this process yuo will find categories of things that needs to be represented in code. For example, in a ''Theatre'', the concept of a &amp;quot;movie&amp;quot; could be such a category which in Ruby is defined as a class and is a combination of states(e.g name of the movie) and methods that use that state(e.g play the movie).&lt;br /&gt;
&lt;br /&gt;
Once you have classes, you'll want to create instances of these classes. For example, in the above example the instances would be the various movies. The word ''object'' is used interchangeably with ''class instance''.&lt;br /&gt;
&lt;br /&gt;
In Ruby, these objects are created a special method called a ''constructor'', a special method associated with a class. The standard constructor is called ''new''.&lt;br /&gt;
&lt;br /&gt;
  movie1 = Movie.new(&amp;quot;ABC PQR&amp;quot;)&lt;br /&gt;
  movie2 = Movie.new(&amp;quot;XYZ ABCD&amp;quot;) &lt;br /&gt;
&lt;br /&gt;
These instances are derived from the same class, but they have unique characteristics. Every object has a unique ''object identifier'' and define instance variables that are unique to each instance, like &amp;quot;title&amp;quot; in our example.&lt;br /&gt;
&lt;br /&gt;
Within each class, you can define instance methods. Each method is a chunk of functionality that may be called from whithin a class or outside it depending on the accessibility constraints.&lt;br /&gt;
&lt;br /&gt;
Before going further, it is important that we understand the basics of Ruby’s Object Model and how Ruby deals with method calls.&lt;br /&gt;
&lt;br /&gt;
Whenever you call a method on an object, the interpreter first looks through the object’s instance methods to check if that particular method exists. If the interpreter can find the method, it will execute it as expected but if that particular method does not exists, it will pass the request up the chain to the object’s class. If it can’t find the method there it will continue to look in that class’s parent class, then the parent’s parent etc. up to the Object class itself.&lt;br /&gt;
&lt;br /&gt;
In the end, if the interpreter is not able to find the method anywhere up the object’s chain of inheritance, it will go back to the object and call another method called method_missing(). Just like with our first method, the interpreter looks for method_missing() in the object’s methods, then the object’s class’s instance methods etc. until it reaches the Object class where method_missing() is defined  and will raise a NoMethodError error. By defining method_missing() yourself within a class, it’s possible to change this default behaviour.  &lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Sample&lt;br /&gt;
    def method_missing(name, *args)&lt;br /&gt;
      puts &amp;quot;#{name} was called with arguments: #{args.join(',')}&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
 m = Sample.new&lt;br /&gt;
 m.method1(&amp;quot;one&amp;quot;, &amp;quot;two&amp;quot;) &lt;br /&gt;
&lt;br /&gt;
There is no method named method1() within our class that we are trying to call. here, we don’t see the usual NoMethodError,and we see the name of the methods and their arguments, just like we defined in method_missing().&lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that have numbers and strings calling in-built [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. &lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Displays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time by writing them in a chain. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
In the above examples the thing before the period is called the ''receiver'', and the name after the period is the method to be invoked. &lt;br /&gt;
&lt;br /&gt;
It's worth noting here a major difference between Ruby and most other languages:&lt;br /&gt;
&lt;br /&gt;
'''In JAVA''': To find the absolute value of a number, we can a separate function and pass the value of that number in that function.&lt;br /&gt;
 Number = Math.abs(number)   // Java Code&lt;br /&gt;
'''In RUBY''': The ability to determine the absolute value is built into numbers(which are also objects) internally.&lt;br /&gt;
 number = number.abs       # Ruby Code&lt;br /&gt;
&lt;br /&gt;
This is the reason behind why Ruby is called a purely object oriented language.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object Hierarchy of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send is a veryimportant concept in the Ruby object model as almost all actions in Ruby, atleast conceptually, boils down to sending a message to an object.&lt;br /&gt;
&lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''&amp;quot;Class&amp;quot;''. Classes are defined in Ruby using the ''class'' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as ''attr_accessor''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparison with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling of unused objects.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected [http://en.wikipedia.org/wiki/Access_modifiers access specifiers] for methods defined within objects.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports [http://en.wikipedia.org/wiki/Inheritance inheritance] of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses [http://en.wikipedia.org/wiki/Interfaces_(computer_science) interfaces] for defining empty methods which are later handled by [http://en.wikipedia.org/wiki/Concrete_class#Abstract_and_Concrete concrete class] objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, [http://en.wikipedia.org/wiki/Constructor_(object-oriented_programming) constructor] is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are [http://en.wikipedia.org/wiki/Immutable_object immutable] (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behavior of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a [http://en.wikipedia.org/wiki/Compile_time compile-time] entity. || A ruby class is a [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run-time] entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
|C++ does not need a base class as it supports [http://en.wikipedia.org/wiki/Generic_programming generic programming]. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the open and close braces.&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_classes.html Objects and Classes in Ruby] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://fhwang.net/2004/11/14/Coming-to-Ruby-from-Java Coming to Ruby from Java]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78974</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78974"/>
		<updated>2013-09-25T00:12:22Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* Understanding the Ruby Object Model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will help us [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w14_st#Understanding_the_Ruby_Object_Model understand the ruby object model], speak about it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Comparison_with_other_Object-Oriented_languages comparison to object models of other programming languages] and explain it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Advantages_of_the_Ruby_Object_Model advantages] and [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Disadvantages_of_the_Ruby_Object_Model disadvantages].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it is purely object-oriented meaning it recognizes all of it's basic constructs as objects. Everything we manipulate is an object and the results of those manipulations are themselves objects.&lt;br /&gt;
&lt;br /&gt;
When you write an object-oriented code, you look forward to model concepts from the real world in your code. During this process yuo will find categories of things that needs to be represented in code. For example, in a ''Theatre'', the concept of a &amp;quot;movie&amp;quot; could be such a category which in Ruby is defined as a class and is a combination of states(e.g name of the movie) and methods that use that state(e.g play the movie).&lt;br /&gt;
&lt;br /&gt;
Once you have classes, you'll want to create instances of these classes. For example, in the above example the instances would be the various movies. The word ''object'' is used interchangeably with ''class instance''.&lt;br /&gt;
&lt;br /&gt;
In Ruby, these objects are created a special method called a ''constructor'', a special method associated with a class. The standard constructor is called ''new''.&lt;br /&gt;
&lt;br /&gt;
  movie1 = Movie.new(&amp;quot;ABC PQR&amp;quot;)&lt;br /&gt;
  movie2 = Movie.new(&amp;quot;XYZ ABCD&amp;quot;) &lt;br /&gt;
&lt;br /&gt;
These instances are derived from the same class, but they have unique characteristics. Every object has a unique ''object identifier'' and define instance variables that are unique to each instance, like &amp;quot;title&amp;quot; in our example.&lt;br /&gt;
&lt;br /&gt;
Within each class, you can define instance methods. Each method is a chunk of functionality that may be called from whithin a class or outside it depending on the accessibility constraints.&lt;br /&gt;
&lt;br /&gt;
Before going further, it is important that we understand the basics of Ruby’s Object Model and how Ruby deals with method calls.&lt;br /&gt;
&lt;br /&gt;
Whenever you call a method on an object, the interpreter first looks through the object’s instance methods to check if that particular method exists. If the interpreter can find the method, it will execute it as expected but if that particular method does not exists, it will pass the request up the chain to the object’s class. If it can’t find the method there it will continue to look in that class’s parent class, then the parent’s parent etc. up to the Object class itself.&lt;br /&gt;
&lt;br /&gt;
In the end, if the interpreter is not able to find the method anywhere up the object’s chain of inheritance, it will go back to the object and call another method called method_missing(). Just like with our first method, the interpreter looks for method_missing() in the object’s methods, then the object’s class’s instance methods etc. until it reaches the Object class where method_missing() is defined  and will raise a NoMethodError error. By defining method_missing() yourself within a class, it’s possible to change this default behaviour.  &lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Sample&lt;br /&gt;
    def method_missing(name, *args)&lt;br /&gt;
      puts &amp;quot;#{name} was called with arguments: #{args.join(',')}&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
 m = Sample.new&lt;br /&gt;
 m.method1(&amp;quot;one&amp;quot;, &amp;quot;two&amp;quot;) &lt;br /&gt;
&lt;br /&gt;
There is no method named method1() within our class that we are trying to call. here, we don’t see the usual NoMethodError,and we see the name of the methods and their arguments, just like we defined in method_missing().&lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that have numbers and strings calling in-built [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. &lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Displays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time by writing them in a chain. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
In the above examples the thing before the period is called the ''receiver'', and the name after the period is the method to be invoked. &lt;br /&gt;
&lt;br /&gt;
It's worth noting here a major difference between Ruby and most other languages:&lt;br /&gt;
&lt;br /&gt;
'''In JAVA''': To find the absolute value of a number, we can a separate function and pass the value of that number in that function.&lt;br /&gt;
 Number = Math.abs(number)   // Java Code&lt;br /&gt;
'''In RUBY''': The ability to determine the absolute value is built into numbers(which are also objects) internally.&lt;br /&gt;
 number = number.abs       # Ruby Code&lt;br /&gt;
&lt;br /&gt;
This is the reason behind why Ruby is called a purely object oriented language.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object Hierarchy of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send is a veryimportant concept in the Ruby object model as almost all actions in Ruby, atleast conceptually, boils down to sending a message to an object.&lt;br /&gt;
&lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''&amp;quot;Class&amp;quot;''. Classes are defined in Ruby using the ''class'' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as ''attr_accessor''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparison with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling of unused objects.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected [http://en.wikipedia.org/wiki/Access_modifiers access specifiers] for methods defined within objects.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports [http://en.wikipedia.org/wiki/Inheritance inheritance] of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses [http://en.wikipedia.org/wiki/Interfaces_(computer_science) interfaces] for defining empty methods which are later handled by [http://en.wikipedia.org/wiki/Concrete_class#Abstract_and_Concrete concrete class] objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, [http://en.wikipedia.org/wiki/Constructor_(object-oriented_programming) constructor] is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are [http://en.wikipedia.org/wiki/Immutable_object immutable] (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behavior of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a [http://en.wikipedia.org/wiki/Compile_time compile-time] entity. || A ruby class is a [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run-time] entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
|C++ does not need a base class as it supports [http://en.wikipedia.org/wiki/Generic_programming generic programming]. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the open and close braces.&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78972</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78972"/>
		<updated>2013-09-25T00:12:07Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* Understanding the Ruby Object Model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will help us [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w14_st#Understanding_the_Ruby_Object_Model understand the ruby object model], speak about it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Comparison_with_other_Object-Oriented_languages comparison to object models of other programming languages] and explain it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Advantages_of_the_Ruby_Object_Model advantages] and [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Disadvantages_of_the_Ruby_Object_Model disadvantages].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it is purely object-oriented meaning it recognizes all of it's basic constructs as objects. Everything we manipulate is an object and the results of those manipulations are themselves objects.&lt;br /&gt;
&lt;br /&gt;
When you write an object-oriented code, you look forward to model concepts from the real world in your code. During this process yuo will find categories of things that needs to be represented in code. For example, in a ''Theatre'', the concept of a &amp;quot;movie&amp;quot; could be such a category which in Ruby is defined as a class and is a combination of states(e.g name of the movie) and methods that use that state(e.g play the movie).&lt;br /&gt;
&lt;br /&gt;
Once you have classes, you'll want to create instances of these classes. For example, in the above example the instances would be the various movies. The word ''object'' is used interchangeably with ''class instance''.&lt;br /&gt;
&lt;br /&gt;
In Ruby, these objects are created a special method called a ''constructor'', a special method associated with a class. The standard constructor is called ''new''.&lt;br /&gt;
&lt;br /&gt;
  movie1 = Movie.new(&amp;quot;ABC PQR&amp;quot;)&lt;br /&gt;
  movie2 = Movie.new(&amp;quot;XYZ ABCD&amp;quot;) &lt;br /&gt;
&lt;br /&gt;
These instances are derived from the same class, but they have unique characteristics. Every object has a unique ''object identifier'' and define instance variables that are unique to each instance, like &amp;quot;title&amp;quot; in our example.&lt;br /&gt;
&lt;br /&gt;
Within each class, you can define instance methods. Each method is a chunk of functionality that may be called from whithin a class or outside it depending on the accessibility constraints.&lt;br /&gt;
&lt;br /&gt;
Before going further, it is important that we understand the basics of Ruby’s Object Model and how Ruby deals with method calls.&lt;br /&gt;
&lt;br /&gt;
Whenever you call a method on an object, the interpreter first looks through the object’s instance methods to check if that particular method exists. If the interpreter can find the method, it will execute it as expected but if that particular method does not exists, it will pass the request up the chain to the object’s class. If it can’t find the method there it will continue to look in that class’s parent class, then the parent’s parent etc. up to the Object class itself.&lt;br /&gt;
&lt;br /&gt;
In the end, if the interpreter is not able to find the method anywhere up the object’s chain of inheritance, it will go back to the object and call another method called method_missing(). Just like with our first method, the interpreter looks for method_missing() in the object’s methods, then the object’s class’s instance methods etc. until it reaches the Object class where method_missing() is defined  and will raise a NoMethodError error. By defining method_missing() yourself within a class, it’s possible to change this default behaviour. &amp;lt;ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Sample&lt;br /&gt;
    def method_missing(name, *args)&lt;br /&gt;
      puts &amp;quot;#{name} was called with arguments: #{args.join(',')}&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
 m = Sample.new&lt;br /&gt;
 m.method1(&amp;quot;one&amp;quot;, &amp;quot;two&amp;quot;) &lt;br /&gt;
&lt;br /&gt;
There is no method named method1() within our class that we are trying to call. here, we don’t see the usual NoMethodError,and we see the name of the methods and their arguments, just like we defined in method_missing().&lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that have numbers and strings calling in-built [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. &lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Displays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time by writing them in a chain. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
In the above examples the thing before the period is called the ''receiver'', and the name after the period is the method to be invoked. &lt;br /&gt;
&lt;br /&gt;
It's worth noting here a major difference between Ruby and most other languages:&lt;br /&gt;
&lt;br /&gt;
'''In JAVA''': To find the absolute value of a number, we can a separate function and pass the value of that number in that function.&lt;br /&gt;
 Number = Math.abs(number)   // Java Code&lt;br /&gt;
'''In RUBY''': The ability to determine the absolute value is built into numbers(which are also objects) internally.&lt;br /&gt;
 number = number.abs       # Ruby Code&lt;br /&gt;
&lt;br /&gt;
This is the reason behind why Ruby is called a purely object oriented language.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object Hierarchy of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send is a veryimportant concept in the Ruby object model as almost all actions in Ruby, atleast conceptually, boils down to sending a message to an object.&lt;br /&gt;
&lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''&amp;quot;Class&amp;quot;''. Classes are defined in Ruby using the ''class'' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as ''attr_accessor''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparison with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling of unused objects.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected [http://en.wikipedia.org/wiki/Access_modifiers access specifiers] for methods defined within objects.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports [http://en.wikipedia.org/wiki/Inheritance inheritance] of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses [http://en.wikipedia.org/wiki/Interfaces_(computer_science) interfaces] for defining empty methods which are later handled by [http://en.wikipedia.org/wiki/Concrete_class#Abstract_and_Concrete concrete class] objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, [http://en.wikipedia.org/wiki/Constructor_(object-oriented_programming) constructor] is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are [http://en.wikipedia.org/wiki/Immutable_object immutable] (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behavior of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a [http://en.wikipedia.org/wiki/Compile_time compile-time] entity. || A ruby class is a [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run-time] entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
|C++ does not need a base class as it supports [http://en.wikipedia.org/wiki/Generic_programming generic programming]. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the open and close braces.&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78949</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78949"/>
		<updated>2013-09-24T23:54:44Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* Object's built-in properties */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will help us [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w14_st#Understanding_the_Ruby_Object_Model understand the ruby object model], speak about it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Comparison_with_other_Object-Oriented_languages comparison to object models of other programming languages] and explain it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Advantages_of_the_Ruby_Object_Model advantages] and [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Disadvantages_of_the_Ruby_Object_Model disadvantages].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it is purely object-oriented meaning it recognizes all of it's basic constructs as objects. Everything we manipulate is an object and the results of those manipulations are themselves objects.&lt;br /&gt;
&lt;br /&gt;
When you write an object-oriented code, you look forward to model concepts from the real world in your code. During this process yuo will find categories of things that needs to be represented in code. For example, in a ''Theatre'', the concept of a &amp;quot;movie&amp;quot; could be such a category which in Ruby is defined as a class and is a combination of states(e.g name of the movie) and methods that use that state(e.g play the movie).&lt;br /&gt;
&lt;br /&gt;
Once you have classes, you'll want to create instances of these classes. For example, in the above example the instances would be the various movies. The word ''object'' is used interchangeably with ''class instance''.&lt;br /&gt;
&lt;br /&gt;
In Ruby, these objects are created a special method called a ''constructor'', a special method associated with a class. The standard constructor is called ''new''.&lt;br /&gt;
&lt;br /&gt;
  movie1 = Movie.new(&amp;quot;ABC PQR&amp;quot;)&lt;br /&gt;
  movie2 = Movie.new(&amp;quot;XYZ ABCD&amp;quot;) &lt;br /&gt;
&lt;br /&gt;
These instances are derived from the same class, but they have unique characteristics. Every object has a unique ''object identifier'' and define instance variables that are unique to each instance, like &amp;quot;title&amp;quot; in our example.&lt;br /&gt;
&lt;br /&gt;
Within each class, you can define instance methods. Each method is a chunk of functionality that may be called from whithin a class or outside it depending on the accessibility constraints.&lt;br /&gt;
&lt;br /&gt;
Before going further, it is important that we understand the basics of Ruby’s Object Model and how Ruby deals with method calls.&lt;br /&gt;
&lt;br /&gt;
Whenever you call a method on an object, the interpreter first looks through the object’s instance methods to check if that particular method exists. If the interpreter can find the method, it will execute it as expected but if that particular method does not exists, it will pass the request up the chain to the object’s class. If it can’t find the method there it will continue to look in that class’s parent class, then the parent’s parent etc. up to the Object class itself.&lt;br /&gt;
&lt;br /&gt;
In the end, if the interpreter is not able to find the method anywhere up the object’s chain of inheritance, it will go back to the object and call another method called method_missing(). Just like with our first method, the interpreter looks for method_missing() in the object’s methods, then the object’s class’s instance methods etc. until it reaches the Object class where method_missing() is defined  and will raise a NoMethodError error. By defining method_missing() yourself within a class, it’s possible to change this default behaviour.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Sample&lt;br /&gt;
    def method_missing(name, *args)&lt;br /&gt;
      puts &amp;quot;#{name} was called with arguments: #{args.join(',')}&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
 m = Sample.new&lt;br /&gt;
 m.method1(&amp;quot;one&amp;quot;, &amp;quot;two&amp;quot;) &lt;br /&gt;
&lt;br /&gt;
There is no method named method1() within our class that we are trying to call. here, we don’t see the usual NoMethodError,and we see the name of the methods and their arguments, just like we defined in method_missing().&lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that have numbers and strings calling in-built [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. &lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Displays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time by writing them in a chain. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object Hierarchy of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send is a veryimportant concept in the Ruby object model as almost all actions in Ruby, atleast conceptually, boils down to sending a message to an object.&lt;br /&gt;
&lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''&amp;quot;Class&amp;quot;''. Classes are defined in Ruby using the ''class'' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as ''attr_accessor''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparison with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling of unused objects.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected [http://en.wikipedia.org/wiki/Access_modifiers access specifiers] for methods defined within objects.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports [http://en.wikipedia.org/wiki/Inheritance inheritance] of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses [http://en.wikipedia.org/wiki/Interfaces_(computer_science) interfaces] for defining empty methods which are later handled by [http://en.wikipedia.org/wiki/Concrete_class#Abstract_and_Concrete concrete class] objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, [http://en.wikipedia.org/wiki/Constructor_(object-oriented_programming) constructor] is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are [http://en.wikipedia.org/wiki/Immutable_object immutable] (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behavior of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a [http://en.wikipedia.org/wiki/Compile_time compile-time] entity. || A ruby class is a [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run-time] entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
|C++ does not need a base class as it supports [http://en.wikipedia.org/wiki/Generic_programming generic programming]. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the open and close braces.&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78898</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78898"/>
		<updated>2013-09-24T21:35:19Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* Comparison with C++ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will help us [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w14_st#Understanding_the_Ruby_Object_Model understand the ruby object model], speak about it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Comparison_with_other_Object-Oriented_languages comparison to object models of other programming languages] and explain it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Advantages_of_the_Ruby_Object_Model advantages] and [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Disadvantages_of_the_Ruby_Object_Model disadvantages].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it is purely object-oriented meaning it recognizes all of it's basic constructs as objects. Every variable(defined for it's type) can be given it's own properties and actions.Rules applicable to objects are relevant to all constructs of ruby. &amp;lt;ref&amp;gt;https://www.ruby-lang.org/en/about&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that have numbers and strings calling in-built [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. &lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Displays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time by writing them in a chain. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object Hierarchy of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &amp;lt;ref&amp;gt; http://www.slideshare.net/cchamnap/ruby-object-model-4978263 &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, [http://stackoverflow.com/questions/13793060/respond-to-vs-respond-to-missing respond_to_missing?] method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send is a veryimportant concept in the Ruby object model as almost all actions in Ruby, atleast conceptually, boils down to sending a message to an object.&lt;br /&gt;
&lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''&amp;quot;Class&amp;quot;''. Classes are defined in Ruby using the ''class'' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as ''attr_accessor''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparison with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling of unused objects.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected [http://en.wikipedia.org/wiki/Access_modifiers access specifiers] for methods defined within objects.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports [http://en.wikipedia.org/wiki/Inheritance inheritance] of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses [http://en.wikipedia.org/wiki/Interfaces_(computer_science) interfaces] for defining empty methods which are later handled by [http://en.wikipedia.org/wiki/Concrete_class#Abstract_and_Concrete concrete class] objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, [http://en.wikipedia.org/wiki/Constructor_(object-oriented_programming) constructor] is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are [http://en.wikipedia.org/wiki/Immutable_object immutable] (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behavior of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a [http://en.wikipedia.org/wiki/Compile_time compile-time] entity. || A ruby class is a [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run-time] entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
|C++ does not need a base class as it supports [http://en.wikipedia.org/wiki/Generic_programming generic programming]. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the open and close braces.&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78896</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78896"/>
		<updated>2013-09-24T21:32:34Z</updated>

		<summary type="html">&lt;p&gt;Sandi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will help us [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w14_st#Understanding_the_Ruby_Object_Model understand the ruby object model], speak about it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Comparison_with_other_Object-Oriented_languages comparison to object models of other programming languages] and explain it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Advantages_of_the_Ruby_Object_Model advantages] and [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Disadvantages_of_the_Ruby_Object_Model disadvantages].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it is purely object-oriented meaning it recognizes all of it's basic constructs as objects. Every variable(defined for it's type) can be given it's own properties and actions.Rules applicable to objects are relevant to all constructs of ruby. &amp;lt;ref&amp;gt;https://www.ruby-lang.org/en/about&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that have numbers and strings calling in-built [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. &lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Displays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time by writing them in a chain. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object Hierarchy of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &amp;lt;ref&amp;gt; http://www.slideshare.net/cchamnap/ruby-object-model-4978263 &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, [http://stackoverflow.com/questions/13793060/respond-to-vs-respond-to-missing respond_to_missing?] method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send is a veryimportant concept in the Ruby object model as almost all actions in Ruby, atleast conceptually, boils down to sending a message to an object.&lt;br /&gt;
&lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''&amp;quot;Class&amp;quot;''. Classes are defined in Ruby using the ''class'' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as ''attr_accessor''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparison with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling of unused objects.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected [http://en.wikipedia.org/wiki/Access_modifiers access specifiers] for methods defined within objects.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports [http://en.wikipedia.org/wiki/Inheritance inheritance] of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses [http://en.wikipedia.org/wiki/Interfaces_(computer_science) interfaces] for defining empty methods which are later handled by [http://en.wikipedia.org/wiki/Concrete_class#Abstract_and_Concrete concrete class] objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, [http://en.wikipedia.org/wiki/Constructor_(object-oriented_programming) constructor] is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are [http://en.wikipedia.org/wiki/Immutable_object immutable] (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behavior of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a [http://en.wikipedia.org/wiki/Compile_time compile-time] entity. || A ruby class is a [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run-time] entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| Variables in C++ refer to data members of corresponding classes. || There’s no explicit references in Ruby. Every variable is a name for some object.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| We have to include all the required functionality while defining the class. || We can reopen a class at anytime and add functionality.  &lt;br /&gt;
|- &lt;br /&gt;
|C++ does not need a base class as it supports [http://en.wikipedia.org/wiki/Generic_programming generic programming]. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the open and close braces.&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78894</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78894"/>
		<updated>2013-09-24T21:25:22Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* Classes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will help us [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w14_st#Understanding_the_Ruby_Object_Model understand the ruby object model], speak about it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Comparison_with_other_Object-Oriented_languages comparison to object models of other programming languages] and explain it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Advantages_of_the_Ruby_Object_Model advantages] and [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Disadvantages_of_the_Ruby_Object_Model disadvantages].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it is purely object-oriented meaning it recognizes all of it's basic constructs as objects. Every variable(defined for it's type) can be given it's own properties and actions.Rules applicable to objects are relevant to all constructs of ruby. &amp;lt;ref&amp;gt;https://www.ruby-lang.org/en/about&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that have numbers and strings calling in-built [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. &lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Displays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time by writing them in a chain. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object Hierarchy of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &amp;lt;ref&amp;gt; http://www.slideshare.net/cchamnap/ruby-object-model-4978263 &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send is a veryimportant concept in the Ruby object model as almost all actions in Ruby, atleast conceptually, boils down to sending a message to an object.&lt;br /&gt;
&lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''&amp;quot;Class&amp;quot;''. Classes are defined in Ruby using the ''class'' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as ''attr_accessor''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparison with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling of unused objects.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected [http://en.wikipedia.org/wiki/Access_modifiers access specifiers] for methods defined within objects.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports [http://en.wikipedia.org/wiki/Inheritance inheritance] of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses [http://en.wikipedia.org/wiki/Interfaces_(computer_science) interfaces] for defining empty methods which are later handled by [http://en.wikipedia.org/wiki/Concrete_class#Abstract_and_Concrete concrete class] objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, [http://en.wikipedia.org/wiki/Constructor_(object-oriented_programming) constructor] is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are [http://en.wikipedia.org/wiki/Immutable_object immutable] (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behavior of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a [http://en.wikipedia.org/wiki/Compile_time compile-time] entity. || A ruby class is a [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run-time] entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| Variables in C++ refer to data members of corresponding classes. || There’s no explicit references in Ruby. Every variable is a name for some object.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| We have to include all the required functionality while defining the class. || We can reopen a class at anytime and add functionality.  &lt;br /&gt;
|- &lt;br /&gt;
|C++ does not need a base class as it supports [http://en.wikipedia.org/wiki/Generic_programming generic programming]. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the open and close braces.&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78893</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78893"/>
		<updated>2013-09-24T21:22:44Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* Understanding the Ruby Object Model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will help us [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w14_st#Understanding_the_Ruby_Object_Model understand the ruby object model], speak about it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Comparison_with_other_Object-Oriented_languages comparison to object models of other programming languages] and explain it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Advantages_of_the_Ruby_Object_Model advantages] and [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Disadvantages_of_the_Ruby_Object_Model disadvantages].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it is purely object-oriented meaning it recognizes all of it's basic constructs as objects. Every variable(defined for it's type) can be given it's own properties and actions.Rules applicable to objects are relevant to all constructs of ruby. &amp;lt;ref&amp;gt;https://www.ruby-lang.org/en/about&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that have numbers and strings calling in-built [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. &lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Displays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time by writing them in a chain. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object Hierarchy of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &amp;lt;ref&amp;gt; http://www.slideshare.net/cchamnap/ruby-object-model-4978263 &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send is a veryimportant concept in the Ruby object model as almost all actions in Ruby, atleast conceptually, boils down to sending a message to an object.&lt;br /&gt;
&lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''&amp;quot;Class&amp;quot;''. Classes are defined in Ruby using the ''class'' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter. In case of more than one word in the class name, the first letter of every word must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as ''attr_accessor''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparison with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling of unused objects.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected [http://en.wikipedia.org/wiki/Access_modifiers access specifiers] for methods defined within objects.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports [http://en.wikipedia.org/wiki/Inheritance inheritance] of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses [http://en.wikipedia.org/wiki/Interfaces_(computer_science) interfaces] for defining empty methods which are later handled by [http://en.wikipedia.org/wiki/Concrete_class#Abstract_and_Concrete concrete class] objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, [http://en.wikipedia.org/wiki/Constructor_(object-oriented_programming) constructor] is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are [http://en.wikipedia.org/wiki/Immutable_object immutable] (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behavior of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a [http://en.wikipedia.org/wiki/Compile_time compile-time] entity. || A ruby class is a [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run-time] entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| Variables in C++ refer to data members of corresponding classes. || There’s no explicit references in Ruby. Every variable is a name for some object.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| We have to include all the required functionality while defining the class. || We can reopen a class at anytime and add functionality.  &lt;br /&gt;
|- &lt;br /&gt;
|C++ does not need a base class as it supports [http://en.wikipedia.org/wiki/Generic_programming generic programming]. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the open and close braces.&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78892</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78892"/>
		<updated>2013-09-24T21:21:55Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* Understanding the Ruby Object Model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will help us [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w14_st#Understanding_the_Ruby_Object_Model understand the ruby object model], speak about it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Comparison_with_other_Object-Oriented_languages comparison to object models of other programming languages] and explain it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Advantages_of_the_Ruby_Object_Model advantages] and [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Disadvantages_of_the_Ruby_Object_Model disadvantages].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it is purely object-oriented meaning it recognizes all of it's basic constructs as objects. Every variable(defined for it's type) can be given it's own properties and actions.Rules applicable to objects are relevant to all constructs of ruby. &amp;lt;ref&amp;gt;https://www.ruby-lang.org/en/about&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that have numbers and strings calling in-built [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. &lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Displays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object Hierarchy of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &amp;lt;ref&amp;gt; http://www.slideshare.net/cchamnap/ruby-object-model-4978263 &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send is a veryimportant concept in the Ruby object model as almost all actions in Ruby, atleast conceptually, boils down to sending a message to an object.&lt;br /&gt;
&lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''&amp;quot;Class&amp;quot;''. Classes are defined in Ruby using the ''class'' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter. In case of more than one word in the class name, the first letter of every word must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as ''attr_accessor''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparison with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling of unused objects.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected [http://en.wikipedia.org/wiki/Access_modifiers access specifiers] for methods defined within objects.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports [http://en.wikipedia.org/wiki/Inheritance inheritance] of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses [http://en.wikipedia.org/wiki/Interfaces_(computer_science) interfaces] for defining empty methods which are later handled by [http://en.wikipedia.org/wiki/Concrete_class#Abstract_and_Concrete concrete class] objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, [http://en.wikipedia.org/wiki/Constructor_(object-oriented_programming) constructor] is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are [http://en.wikipedia.org/wiki/Immutable_object immutable] (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behavior of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a [http://en.wikipedia.org/wiki/Compile_time compile-time] entity. || A ruby class is a [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run-time] entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| Variables in C++ refer to data members of corresponding classes. || There’s no explicit references in Ruby. Every variable is a name for some object.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| We have to include all the required functionality while defining the class. || We can reopen a class at anytime and add functionality.  &lt;br /&gt;
|- &lt;br /&gt;
|C++ does not need a base class as it supports [http://en.wikipedia.org/wiki/Generic_programming generic programming]. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the open and close braces.&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78889</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78889"/>
		<updated>2013-09-24T21:19:17Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* Comparison with Java */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will help us [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w14_st#Understanding_the_Ruby_Object_Model understand the ruby object model], speak about it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Comparison_with_other_Object-Oriented_languages comparison to object models of other programming languages] and explain it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Advantages_of_the_Ruby_Object_Model advantages] and [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Disadvantages_of_the_Ruby_Object_Model disadvantages].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it is purely object-oriented meaning it recognizes all of it's basic constructs as objects. Every bit of information and code can be given their own properties and actions.Rules applicable to objects are relevant to all constructs of ruby. &amp;lt;ref&amp;gt;https://www.ruby-lang.org/en/about&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that have numbers and strings calling in-built [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. &lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Displays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object Hierarchy of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &amp;lt;ref&amp;gt; http://www.slideshare.net/cchamnap/ruby-object-model-4978263 &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send is a veryimportant concept in the Ruby object model as almost all actions in Ruby, atleast conceptually, boils down to sending a message to an object.&lt;br /&gt;
&lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''&amp;quot;Class&amp;quot;''. Classes are defined in Ruby using the ''class'' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter. In case of more than one word in the class name, the first letter of every word must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as ''attr_accessor''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparison with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling of unused objects.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected [http://en.wikipedia.org/wiki/Access_modifiers access specifiers] for methods defined within objects.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports [http://en.wikipedia.org/wiki/Inheritance inheritance] of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses [http://en.wikipedia.org/wiki/Interfaces_(computer_science) interfaces] for defining empty methods which are later handled by [http://en.wikipedia.org/wiki/Concrete_class#Abstract_and_Concrete concrete class] objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, [http://en.wikipedia.org/wiki/Constructor_(object-oriented_programming) constructor] is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are [http://en.wikipedia.org/wiki/Immutable_object immutable] (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behavior of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a [http://en.wikipedia.org/wiki/Compile_time compile-time] entity. || A ruby class is a [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run-time] entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| Variables in C++ refer to data members of corresponding classes. || There’s no explicit references in Ruby. Every variable is a name for some object.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| We have to include all the required functionality while defining the class. || We can reopen a class at anytime and add functionality.  &lt;br /&gt;
|- &lt;br /&gt;
|C++ does not need a base class as it supports [http://en.wikipedia.org/wiki/Generic_programming generic programming]. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the open and close braces.&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78888</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78888"/>
		<updated>2013-09-24T21:18:02Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* Comparison with Java */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will help us [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w14_st#Understanding_the_Ruby_Object_Model understand the ruby object model], speak about it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Comparison_with_other_Object-Oriented_languages comparison to object models of other programming languages] and explain it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Advantages_of_the_Ruby_Object_Model advantages] and [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Disadvantages_of_the_Ruby_Object_Model disadvantages].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it is purely object-oriented meaning it recognizes all of it's basic constructs as objects. Every bit of information and code can be given their own properties and actions.Rules applicable to objects are relevant to all constructs of ruby. &amp;lt;ref&amp;gt;https://www.ruby-lang.org/en/about&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that have numbers and strings calling in-built [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. &lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Displays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object Hierarchy of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &amp;lt;ref&amp;gt; http://www.slideshare.net/cchamnap/ruby-object-model-4978263 &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send is a veryimportant concept in the Ruby object model as almost all actions in Ruby, atleast conceptually, boils down to sending a message to an object.&lt;br /&gt;
&lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''&amp;quot;Class&amp;quot;''. Classes are defined in Ruby using the ''class'' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter. In case of more than one word in the class name, the first letter of every word must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as ''attr_accessor''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparison with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling of unused objects.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected [http://en.wikipedia.org/wiki/Access_modifiers access specifiers] for methods.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports [http://en.wikipedia.org/wiki/Inheritance inheritance] of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses [http://en.wikipedia.org/wiki/Interfaces_(computer_science) interfaces] for defining empty methods which are later handled by [http://en.wikipedia.org/wiki/Concrete_class#Abstract_and_Concrete concrete class] objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, [http://en.wikipedia.org/wiki/Constructor_(object-oriented_programming) constructor] is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are [http://en.wikipedia.org/wiki/Immutable_object immutable] (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behavior of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a [http://en.wikipedia.org/wiki/Compile_time compile-time] entity. || A ruby class is a [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run-time] entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| Variables in C++ refer to data members of corresponding classes. || There’s no explicit references in Ruby. Every variable is a name for some object.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| We have to include all the required functionality while defining the class. || We can reopen a class at anytime and add functionality.  &lt;br /&gt;
|- &lt;br /&gt;
|C++ does not need a base class as it supports [http://en.wikipedia.org/wiki/Generic_programming generic programming]. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the open and close braces.&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78886</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78886"/>
		<updated>2013-09-24T21:16:22Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* Diagramatic Representation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will help us [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w14_st#Understanding_the_Ruby_Object_Model understand the ruby object model], speak about it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Comparison_with_other_Object-Oriented_languages comparison to object models of other programming languages] and explain it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Advantages_of_the_Ruby_Object_Model advantages] and [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Disadvantages_of_the_Ruby_Object_Model disadvantages].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it is purely object-oriented meaning it recognizes all of it's basic constructs as objects. Every bit of information and code can be given their own properties and actions.Rules applicable to objects are relevant to all constructs of ruby. &amp;lt;ref&amp;gt;https://www.ruby-lang.org/en/about&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that have numbers and strings calling in-built [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. &lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Displays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object Hierarchy of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &amp;lt;ref&amp;gt; http://www.slideshare.net/cchamnap/ruby-object-model-4978263 &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send is a veryimportant concept in the Ruby object model as almost all actions in Ruby, atleast conceptually, boils down to sending a message to an object.&lt;br /&gt;
&lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''&amp;quot;Class&amp;quot;''. Classes are defined in Ruby using the ''class'' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter. In case of more than one word in the class name, the first letter of every word must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as ''attr_accessor''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparison with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected [http://en.wikipedia.org/wiki/Access_modifiers access specifiers] for methods.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports [http://en.wikipedia.org/wiki/Inheritance inheritance] of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses [http://en.wikipedia.org/wiki/Interfaces_(computer_science) interfaces] for defining empty methods which are later handled by [http://en.wikipedia.org/wiki/Concrete_class#Abstract_and_Concrete concrete class] objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, [http://en.wikipedia.org/wiki/Constructor_(object-oriented_programming) constructor] is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are [http://en.wikipedia.org/wiki/Immutable_object immutable] (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behavior of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a [http://en.wikipedia.org/wiki/Compile_time compile-time] entity. || A ruby class is a [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run-time] entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| Variables in C++ refer to data members of corresponding classes. || There’s no explicit references in Ruby. Every variable is a name for some object.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| We have to include all the required functionality while defining the class. || We can reopen a class at anytime and add functionality.  &lt;br /&gt;
|- &lt;br /&gt;
|C++ does not need a base class as it supports [http://en.wikipedia.org/wiki/Generic_programming generic programming]. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the open and close braces.&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78884</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78884"/>
		<updated>2013-09-24T21:14:41Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* Understanding the Ruby Object Model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will help us [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w14_st#Understanding_the_Ruby_Object_Model understand the ruby object model], speak about it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Comparison_with_other_Object-Oriented_languages comparison to object models of other programming languages] and explain it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Advantages_of_the_Ruby_Object_Model advantages] and [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Disadvantages_of_the_Ruby_Object_Model disadvantages].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it is purely object-oriented meaning it recognizes all of it's basic constructs as objects. Every bit of information and code can be given their own properties and actions.Rules applicable to objects are relevant to all constructs of ruby. &amp;lt;ref&amp;gt;https://www.ruby-lang.org/en/about&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that have numbers and strings calling in-built [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. &lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Displays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object [http://en.wikipedia.org/wiki/Hierarchy Hierarchy] of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &amp;lt;ref&amp;gt; http://www.slideshare.net/cchamnap/ruby-object-model-4978263 &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send is a veryimportant concept in the Ruby object model as almost all actions in Ruby, atleast conceptually, boils down to sending a message to an object.&lt;br /&gt;
&lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''&amp;quot;Class&amp;quot;''. Classes are defined in Ruby using the ''class'' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter. In case of more than one word in the class name, the first letter of every word must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as ''attr_accessor''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparison with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected [http://en.wikipedia.org/wiki/Access_modifiers access specifiers] for methods.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports [http://en.wikipedia.org/wiki/Inheritance inheritance] of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses [http://en.wikipedia.org/wiki/Interfaces_(computer_science) interfaces] for defining empty methods which are later handled by [http://en.wikipedia.org/wiki/Concrete_class#Abstract_and_Concrete concrete class] objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, [http://en.wikipedia.org/wiki/Constructor_(object-oriented_programming) constructor] is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are [http://en.wikipedia.org/wiki/Immutable_object immutable] (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behavior of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a [http://en.wikipedia.org/wiki/Compile_time compile-time] entity. || A ruby class is a [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run-time] entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| Variables in C++ refer to data members of corresponding classes. || There’s no explicit references in Ruby. Every variable is a name for some object.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| We have to include all the required functionality while defining the class. || We can reopen a class at anytime and add functionality.  &lt;br /&gt;
|- &lt;br /&gt;
|C++ does not need a base class as it supports [http://en.wikipedia.org/wiki/Generic_programming generic programming]. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the open and close braces.&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78882</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78882"/>
		<updated>2013-09-24T21:12:37Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* Understanding the Ruby Object Model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will help us [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w14_st#Understanding_the_Ruby_Object_Model understand the ruby object model], speak about it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Comparison_with_other_Object-Oriented_languages comparison to object models of other programming languages] and explain it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Advantages_of_the_Ruby_Object_Model advantages] and [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Disadvantages_of_the_Ruby_Object_Model disadvantages].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it is purely object-oriented meaning it recognizes all of it's basic constructs as objects. Every bit of information and code can be given their own properties and actions.Rules applicable to objects are relevant to all constructs of ruby. &amp;lt;ref&amp;gt;https://www.ruby-lang.org/en/about&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that call  [http://en.wikipedia.org/wiki/Method_(computer_programming) methods] that are defined for numbers and strings.&lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Displays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object [http://en.wikipedia.org/wiki/Hierarchy Hierarchy] of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &amp;lt;ref&amp;gt; http://www.slideshare.net/cchamnap/ruby-object-model-4978263 &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send is a veryimportant concept in the Ruby object model as almost all actions in Ruby, atleast conceptually, boils down to sending a message to an object.&lt;br /&gt;
&lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''&amp;quot;Class&amp;quot;''. Classes are defined in Ruby using the ''class'' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter. In case of more than one word in the class name, the first letter of every word must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as ''attr_accessor''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparison with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected [http://en.wikipedia.org/wiki/Access_modifiers access specifiers] for methods.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports [http://en.wikipedia.org/wiki/Inheritance inheritance] of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses [http://en.wikipedia.org/wiki/Interfaces_(computer_science) interfaces] for defining empty methods which are later handled by [http://en.wikipedia.org/wiki/Concrete_class#Abstract_and_Concrete concrete class] objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, [http://en.wikipedia.org/wiki/Constructor_(object-oriented_programming) constructor] is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are [http://en.wikipedia.org/wiki/Immutable_object immutable] (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behavior of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a [http://en.wikipedia.org/wiki/Compile_time compile-time] entity. || A ruby class is a [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run-time] entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| Variables in C++ refer to data members of corresponding classes. || There’s no explicit references in Ruby. Every variable is a name for some object.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| We have to include all the required functionality while defining the class. || We can reopen a class at anytime and add functionality.  &lt;br /&gt;
|- &lt;br /&gt;
|C++ does not need a base class as it supports [http://en.wikipedia.org/wiki/Generic_programming generic programming]. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the open and close braces.&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78879</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78879"/>
		<updated>2013-09-24T21:06:38Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* Understanding the Ruby Object Model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will help us [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w14_st#Understanding_the_Ruby_Object_Model understand the ruby object model], speak about it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Comparison_with_other_Object-Oriented_languages comparison to object models of other programming languages] and explain it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Advantages_of_the_Ruby_Object_Model advantages] and [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Disadvantages_of_the_Ruby_Object_Model disadvantages].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it is purely object-oriented meaning it recognizes all of it's basic constructs as objects. Every bit of information and code can be given their own properties and actions.Rules applicable to objects are relevant to all constructs of ruby. &amp;lt;ref&amp;gt;https://www.ruby-lang.org/en/about&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that add [http://en.wikipedia.org/wiki/Method_(computer_programming) methods] to numbers and strings.&lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Displays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object [http://en.wikipedia.org/wiki/Hierarchy Hierarchy] of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &amp;lt;ref&amp;gt; http://www.slideshare.net/cchamnap/ruby-object-model-4978263 &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send is a veryimportant concept in the Ruby object model as almost all actions in Ruby, atleast conceptually, boils down to sending a message to an object.&lt;br /&gt;
&lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''&amp;quot;Class&amp;quot;''. Classes are defined in Ruby using the ''class'' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter. In case of more than one word in the class name, the first letter of every word must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as ''attr_accessor''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparison with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected [http://en.wikipedia.org/wiki/Access_modifiers access specifiers] for methods.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports [http://en.wikipedia.org/wiki/Inheritance inheritance] of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses [http://en.wikipedia.org/wiki/Interfaces_(computer_science) interfaces] for defining empty methods which are later handled by [http://en.wikipedia.org/wiki/Concrete_class#Abstract_and_Concrete concrete class] objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, [http://en.wikipedia.org/wiki/Constructor_(object-oriented_programming) constructor] is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are [http://en.wikipedia.org/wiki/Immutable_object immutable] (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behavior of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a [http://en.wikipedia.org/wiki/Compile_time compile-time] entity. || A ruby class is a [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run-time] entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| Variables in C++ refer to data members of corresponding classes. || There’s no explicit references in Ruby. Every variable is a name for some object.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| We have to include all the required functionality while defining the class. || We can reopen a class at anytime and add functionality.  &lt;br /&gt;
|- &lt;br /&gt;
|C++ does not need a base class as it supports [http://en.wikipedia.org/wiki/Generic_programming generic programming]. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the open and close braces.&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78396</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78396"/>
		<updated>2013-09-19T04:05:46Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* Classes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will help us [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w14_st#Understanding_the_Ruby_Object_Model understand the ruby object model], speak about it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Comparison_with_other_Object-Oriented_languages comparison to object models of other programming languages] and explain it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Advantages_of_the_Ruby_Object_Model advantages] and [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Disadvantages_of_the_Ruby_Object_Model disadvantages].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it recognizes all of it's basic constructs ([http://en.wikipedia.org/wiki/Variable_(computer_science) variables], classes etc...) as objects. Every bit of information and code can be given their own properties and actions.Rules applicable to objects are relevant to all constructs of ruby. &amp;lt;ref&amp;gt;https://www.ruby-lang.org/en/about&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that add [http://en.wikipedia.org/wiki/Method_(computer_programming) methods] to numbers and strings.&lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Displays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object [http://en.wikipedia.org/wiki/Hierarchy Hierarchy] of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &amp;lt;ref&amp;gt; http://www.slideshare.net/cchamnap/ruby-object-model-4978263 &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''&amp;quot;Class&amp;quot;''. Classes are defined in Ruby using the ''class'' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter. In case of more than one word in the class name, the first letter of every word must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as ''attr_accessor''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparison with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected [http://en.wikipedia.org/wiki/Access_modifiers access specifiers] for methods.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports [http://en.wikipedia.org/wiki/Inheritance inheritance] of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses [http://en.wikipedia.org/wiki/Interfaces_(computer_science) interfaces] for defining empty methods which are later handled by [http://en.wikipedia.org/wiki/Concrete_class#Abstract_and_Concrete concrete class] objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, [http://en.wikipedia.org/wiki/Constructor_(object-oriented_programming) constructor] is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are [http://en.wikipedia.org/wiki/Immutable_object immutable] (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behavior of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a [http://en.wikipedia.org/wiki/Compile_time compile-time] entity. || A ruby class is a [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run-time] entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| Variables in C++ refer to data members of corresponding classes. || There’s no explicit references in Ruby. Every variable is a name for some object.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| We have to include all the required functionality while defining the class. || We can reopen a class at anytime and add functionality.  &lt;br /&gt;
|- &lt;br /&gt;
|C++ does not need a base class as it supports [http://en.wikipedia.org/wiki/Generic_programming generic programming]. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the open and close braces.&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78395</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78395"/>
		<updated>2013-09-19T04:05:02Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* Classes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will help us [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w14_st#Understanding_the_Ruby_Object_Model understand the ruby object model], speak about it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Comparison_with_other_Object-Oriented_languages comparison to object models of other programming languages] and explain it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Advantages_of_the_Ruby_Object_Model advantages] and [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Disadvantages_of_the_Ruby_Object_Model disadvantages].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it recognizes all of it's basic constructs ([http://en.wikipedia.org/wiki/Variable_(computer_science) variables], classes etc...) as objects. Every bit of information and code can be given their own properties and actions.Rules applicable to objects are relevant to all constructs of ruby. &amp;lt;ref&amp;gt;https://www.ruby-lang.org/en/about&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that add [http://en.wikipedia.org/wiki/Method_(computer_programming) methods] to numbers and strings.&lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Displays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object [http://en.wikipedia.org/wiki/Hierarchy Hierarchy] of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &amp;lt;ref&amp;gt; http://www.slideshare.net/cchamnap/ruby-object-model-4978263 &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''Class''. Classes are defined in Ruby using the '''class''' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter. In case of more than one word in the class name, the first letter of every word must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as ''attr_accessor''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparison with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected [http://en.wikipedia.org/wiki/Access_modifiers access specifiers] for methods.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports [http://en.wikipedia.org/wiki/Inheritance inheritance] of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses [http://en.wikipedia.org/wiki/Interfaces_(computer_science) interfaces] for defining empty methods which are later handled by [http://en.wikipedia.org/wiki/Concrete_class#Abstract_and_Concrete concrete class] objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, [http://en.wikipedia.org/wiki/Constructor_(object-oriented_programming) constructor] is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are [http://en.wikipedia.org/wiki/Immutable_object immutable] (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behavior of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a [http://en.wikipedia.org/wiki/Compile_time compile-time] entity. || A ruby class is a [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run-time] entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| Variables in C++ refer to data members of corresponding classes. || There’s no explicit references in Ruby. Every variable is a name for some object.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| We have to include all the required functionality while defining the class. || We can reopen a class at anytime and add functionality.  &lt;br /&gt;
|- &lt;br /&gt;
|C++ does not need a base class as it supports [http://en.wikipedia.org/wiki/Generic_programming generic programming]. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the open and close braces.&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78394</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78394"/>
		<updated>2013-09-19T04:04:34Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* Classes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will help us [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w14_st#Understanding_the_Ruby_Object_Model understand the ruby object model], speak about it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Comparison_with_other_Object-Oriented_languages comparison to object models of other programming languages] and explain it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Advantages_of_the_Ruby_Object_Model advantages] and [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Disadvantages_of_the_Ruby_Object_Model disadvantages].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it recognizes all of it's basic constructs ([http://en.wikipedia.org/wiki/Variable_(computer_science) variables], classes etc...) as objects. Every bit of information and code can be given their own properties and actions.Rules applicable to objects are relevant to all constructs of ruby. &amp;lt;ref&amp;gt;https://www.ruby-lang.org/en/about&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that add [http://en.wikipedia.org/wiki/Method_(computer_programming) methods] to numbers and strings.&lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Displays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object [http://en.wikipedia.org/wiki/Hierarchy Hierarchy] of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &amp;lt;ref&amp;gt; http://www.slideshare.net/cchamnap/ruby-object-model-4978263 &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''“Class”''. Classes are defined in Ruby using the '''class''' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter. In case of more than one word in the class name, the first letter of every word must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as ''attr_accessor''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparison with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected [http://en.wikipedia.org/wiki/Access_modifiers access specifiers] for methods.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports [http://en.wikipedia.org/wiki/Inheritance inheritance] of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses [http://en.wikipedia.org/wiki/Interfaces_(computer_science) interfaces] for defining empty methods which are later handled by [http://en.wikipedia.org/wiki/Concrete_class#Abstract_and_Concrete concrete class] objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, [http://en.wikipedia.org/wiki/Constructor_(object-oriented_programming) constructor] is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are [http://en.wikipedia.org/wiki/Immutable_object immutable] (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behavior of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a [http://en.wikipedia.org/wiki/Compile_time compile-time] entity. || A ruby class is a [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run-time] entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| Variables in C++ refer to data members of corresponding classes. || There’s no explicit references in Ruby. Every variable is a name for some object.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| We have to include all the required functionality while defining the class. || We can reopen a class at anytime and add functionality.  &lt;br /&gt;
|- &lt;br /&gt;
|C++ does not need a base class as it supports [http://en.wikipedia.org/wiki/Generic_programming generic programming]. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the open and close braces.&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78293</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78293"/>
		<updated>2013-09-18T23:08:44Z</updated>

		<summary type="html">&lt;p&gt;Sandi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will help us [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w14_st#Understanding_the_Ruby_Object_Model understand the ruby object model], speak about it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Comparison_with_other_Object-Oriented_languages comparison to object models of other programming languages] and explain it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Advantages_of_the_Ruby_Object_Model advantages] and [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Disadvantages_of_the_Ruby_Object_Model disadvantages] in detail.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it recognizes all of it's basic constructs ([http://en.wikipedia.org/wiki/Variable_(computer_science) variables], operations, classes etc...) as objects. Every bit of information and code can be given their own properties and actions.Rules applicable to objects are relevant to all constructs of ruby. &amp;lt;ref&amp;gt;https://www.ruby-lang.org/en/about&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that add [http://en.wikipedia.org/wiki/Method_(computer_programming) methods] to numbers and strings.&lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Displays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object [http://en.wikipedia.org/wiki/Hierarchy Hierarchy] of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &amp;lt;ref&amp;gt; http://www.slideshare.net/cchamnap/ruby-object-model-4978263 &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''“Class”''. Classes are defined in Ruby using the '''class''' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter. In case of more than one word in the class name, the first letter of every word must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as '''''attr_accessor'''''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparison with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected access specifiers for methods.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports [http://en.wikipedia.org/wiki/Inheritance inheritance] of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses [http://en.wikipedia.org/wiki/Interfaces_(computer_science) interfaces] for defining empty methods which are later handled by [http://en.wikipedia.org/wiki/Concrete_class#Abstract_and_Concrete concrete class] objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, [http://en.wikipedia.org/wiki/Constructor_(object-oriented_programming) constructor] is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are [http://en.wikipedia.org/wiki/Immutable_object immutable] (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behavior of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a [http://en.wikipedia.org/wiki/Compile_time compile-time] entity. || A ruby class is a [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run-time] entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| Variables in C++ refer to data members of corresponding classes. || There’s no explicit references in Ruby. Every variable is a name for some object.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| We have to include all the required functionality while defining the class. || We can reopen a class at anytime and add functionality.  &lt;br /&gt;
|- &lt;br /&gt;
|C++ does not need a base class as it supports [http://en.wikipedia.org/wiki/Generic_programming generic programming]. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the open and close braces.&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78280</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78280"/>
		<updated>2013-09-18T22:55:38Z</updated>

		<summary type="html">&lt;p&gt;Sandi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will help us [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w14_st#Understanding_the_Ruby_Object_Model understand the ruby object model], speak about it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Comparision_with_other_Object-Oriented_languages comparison to object models of other programming languages] and explain it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Advantages_of_the_Ruby_Object_Model advantages] and [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Disadvantages_of_the_Ruby_Object_Model disadvantages] in detail.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it recognizes all of it's basic constructs ([http://en.wikipedia.org/wiki/Variable_(computer_science) variables], operations, classes etc...) as objects. Every bit of information and code can be given their own properties and actions.Rules applicable to objects are relevant to all constructs of ruby. &amp;lt;ref&amp;gt;https://www.ruby-lang.org/en/about&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that add [http://en.wikipedia.org/wiki/Method_(computer_programming) methods] to numbers and strings.&lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Diplays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object [http://en.wikipedia.org/wiki/Hierarchy Hierarchy] of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &amp;lt;ref&amp;gt; http://www.slideshare.net/cchamnap/ruby-object-model-4978263 &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''“Class”''. Classes are defined in Ruby using the '''class''' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter. In case of more than one word in the class name, the first letter of every word must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as '''''attr_accessor'''''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparision with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected access specifiers for methods.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports [http://en.wikipedia.org/wiki/Inheritance inheritance] of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses [http://en.wikipedia.org/wiki/Interfaces_(computer_science) interfaces] for defining empty methods which are later handled by [http://en.wikipedia.org/wiki/Concrete_class#Abstract_and_Concrete concrete class] objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, [http://en.wikipedia.org/wiki/Constructor_(object-oriented_programming) constructor] is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are [http://en.wikipedia.org/wiki/Immutable_object immutable] (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparision with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behaviour of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a [http://en.wikipedia.org/wiki/Compile_time compile-time] entity. || A ruby class is a [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run-time] entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| Variables in C++ refer to data members of corresponding classes. || There’s no explicit references in Ruby. Every variable is a name for some object.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| We have to include all the required functionality while defining the class. || We can reopen a class at anytime and add functionality.  &lt;br /&gt;
|- &lt;br /&gt;
|C++ does not need a base class as it supports [http://en.wikipedia.org/wiki/Generic_programming generic programming]. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the opena&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78279</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78279"/>
		<updated>2013-09-18T22:54:48Z</updated>

		<summary type="html">&lt;p&gt;Sandi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will help us [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w14_st#Understanding_the_Ruby_Object_Model understand the ruby object model], speak about it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Comparision_with_other_Object-Oriented_languages comparison to object models of other programming languages] and explain it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Advantages_of_the_Ruby_Object_Model advantages] and [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14#Disadvantages_of_the_Ruby_Object_Model disadvantages] in detail.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it recognizes all of it's basic constructs ([http://en.wikipedia.org/wiki/Variable_(computer_science) variables], operations, classes etc...) as objects. Every bit of information and code can be given their own properties and actions.Rules applicable to objects are relevant to all constructs of ruby. &amp;lt;ref&amp;gt;https://www.ruby-lang.org/en/about&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that add [http://en.wikipedia.org/wiki/Method_(computer_programming) methods] to numbers and strings.&lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Diplays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object [http://en.wikipedia.org/wiki/Hierarchy Hierarchy] of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &amp;lt;ref&amp;gt; http://www.slideshare.net/cchamnap/ruby-object-model-4978263 &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''“Class”''. Classes are defined in Ruby using the '''class''' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter. In case of more than one word in the class name, the first letter of every word must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as '''''attr_accessor'''''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparision with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected access specifiers for methods.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports [http://en.wikipedia.org/wiki/Inheritance inheritance] of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses [http://en.wikipedia.org/wiki/Interfaces_(computer_science) interfaces] for defining empty methods which are later handled by [http://en.wikipedia.org/wiki/Concrete_class#Abstract_and_Concrete concrete class] objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, [http://en.wikipedia.org/wiki/Constructor_(object-oriented_programming) constructor] is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are [http://en.wikipedia.org/wiki/Immutable_object immutable] (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparision with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behaviour of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a [http://en.wikipedia.org/wiki/Compile_time compile-time] entity. || A ruby class is a [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run-time] entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| Variables in C++ refer to data members of corresponding classes. || There’s no explicit references in Ruby. Every variable is a name for some object.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| We have to include all the required functionality while defining the class. || We can reopen a class at anytime and add functionality.  &lt;br /&gt;
|- &lt;br /&gt;
|C++ does not need a base class as it supports [http://en.wikipedia.org/wiki/Generic_programming generic programming]. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the opena&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78274</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78274"/>
		<updated>2013-09-18T22:51:20Z</updated>

		<summary type="html">&lt;p&gt;Sandi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will help us [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w14_st#Understanding_the_Ruby_Object_Model understand the ruby object model], speak about it's [http://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st#Comparision_with_other_Object-Oriented_languages comparison to object models of other programming languages] and explain it's advantages and disadvantages in detail.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it recognizes all of it's basic constructs ([http://en.wikipedia.org/wiki/Variable_(computer_science) variables], operations, classes etc...) as objects. Every bit of information and code can be given their own properties and actions.Rules applicable to objects are relevant to all constructs of ruby. &amp;lt;ref&amp;gt;https://www.ruby-lang.org/en/about&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that add [http://en.wikipedia.org/wiki/Method_(computer_programming) methods] to numbers and strings.&lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Diplays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object [http://en.wikipedia.org/wiki/Hierarchy Hierarchy] of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &amp;lt;ref&amp;gt; http://www.slideshare.net/cchamnap/ruby-object-model-4978263 &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''“Class”''. Classes are defined in Ruby using the '''class''' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter. In case of more than one word in the class name, the first letter of every word must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as '''''attr_accessor'''''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparision with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected access specifiers for methods.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports [http://en.wikipedia.org/wiki/Inheritance inheritance] of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses [http://en.wikipedia.org/wiki/Interfaces_(computer_science) interfaces] for defining empty methods which are later handled by [http://en.wikipedia.org/wiki/Concrete_class#Abstract_and_Concrete concrete class] objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, [http://en.wikipedia.org/wiki/Constructor_(object-oriented_programming) constructor] is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are [http://en.wikipedia.org/wiki/Immutable_object immutable] (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparision with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behaviour of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a [http://en.wikipedia.org/wiki/Compile_time compile-time] entity. || A ruby class is a [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run-time] entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| Variables in C++ refer to data members of corresponding classes. || There’s no explicit references in Ruby. Every variable is a name for some object.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| We have to include all the required functionality while defining the class. || We can reopen a class at anytime and add functionality.  &lt;br /&gt;
|- &lt;br /&gt;
|C++ does not need a base class as it supports [http://en.wikipedia.org/wiki/Generic_programming generic programming]. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the opena&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78271</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78271"/>
		<updated>2013-09-18T22:48:45Z</updated>

		<summary type="html">&lt;p&gt;Sandi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will help us [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w14_st#Understanding_the_Ruby_Object_Model understand the ruby object model], speak about it's comparison to object models of other [http://en.wikipedia.org/wiki/Programming_languages programming languages] and explain it's advantages and disadvantages in detail.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it recognizes all of it's basic constructs ([http://en.wikipedia.org/wiki/Variable_(computer_science) variables], operations, classes etc...) as objects. Every bit of information and code can be given their own properties and actions.Rules applicable to objects are relevant to all constructs of ruby. &amp;lt;ref&amp;gt;https://www.ruby-lang.org/en/about&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that add [http://en.wikipedia.org/wiki/Method_(computer_programming) methods] to numbers and strings.&lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Diplays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object [http://en.wikipedia.org/wiki/Hierarchy Hierarchy] of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &amp;lt;ref&amp;gt; http://www.slideshare.net/cchamnap/ruby-object-model-4978263 &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''“Class”''. Classes are defined in Ruby using the '''class''' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter. In case of more than one word in the class name, the first letter of every word must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as '''''attr_accessor'''''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparision with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected access specifiers for methods.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports [http://en.wikipedia.org/wiki/Inheritance inheritance] of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses [http://en.wikipedia.org/wiki/Interfaces_(computer_science) interfaces] for defining empty methods which are later handled by [http://en.wikipedia.org/wiki/Concrete_class#Abstract_and_Concrete concrete class] objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, [http://en.wikipedia.org/wiki/Constructor_(object-oriented_programming) constructor] is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are [http://en.wikipedia.org/wiki/Immutable_object immutable] (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparision with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behaviour of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a [http://en.wikipedia.org/wiki/Compile_time compile-time] entity. || A ruby class is a [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run-time] entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| Variables in C++ refer to data members of corresponding classes. || There’s no explicit references in Ruby. Every variable is a name for some object.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| We have to include all the required functionality while defining the class. || We can reopen a class at anytime and add functionality.  &lt;br /&gt;
|- &lt;br /&gt;
|C++ does not need a base class as it supports [http://en.wikipedia.org/wiki/Generic_programming generic programming]. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the opena&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78270</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78270"/>
		<updated>2013-09-18T22:45:09Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* Comparision with C++ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will help us understand the ruby object model, speak about it's comparison to object models of other [http://en.wikipedia.org/wiki/Programming_languages programming languages] and explain it's advantages and disadvantages in detail.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it recognizes all of it's basic constructs ([http://en.wikipedia.org/wiki/Variable_(computer_science) variables], operations, classes etc...) as objects. Every bit of information and code can be given their own properties and actions.Rules applicable to objects are relevant to all constructs of ruby. &amp;lt;ref&amp;gt;https://www.ruby-lang.org/en/about&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that add [http://en.wikipedia.org/wiki/Method_(computer_programming) methods] to numbers and strings.&lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Diplays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object [http://en.wikipedia.org/wiki/Hierarchy Hierarchy] of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &amp;lt;ref&amp;gt; http://www.slideshare.net/cchamnap/ruby-object-model-4978263 &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''“Class”''. Classes are defined in Ruby using the '''class''' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter. In case of more than one word in the class name, the first letter of every word must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as '''''attr_accessor'''''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparision with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected access specifiers for methods.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports [http://en.wikipedia.org/wiki/Inheritance inheritance] of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses [http://en.wikipedia.org/wiki/Interfaces_(computer_science) interfaces] for defining empty methods which are later handled by [http://en.wikipedia.org/wiki/Concrete_class#Abstract_and_Concrete concrete class] objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, [http://en.wikipedia.org/wiki/Constructor_(object-oriented_programming) constructor] is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are [http://en.wikipedia.org/wiki/Immutable_object immutable] (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparision with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behaviour of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a [http://en.wikipedia.org/wiki/Compile_time compile-time] entity. || A ruby class is a [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run-time] entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| Variables in C++ refer to data members of corresponding classes. || There’s no explicit references in Ruby. Every variable is a name for some object.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| We have to include all the required functionality while defining the class. || We can reopen a class at anytime and add functionality.  &lt;br /&gt;
|- &lt;br /&gt;
|C++ does not need a base class as it supports [http://en.wikipedia.org/wiki/Generic_programming generic programming]. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the opena&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78269</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78269"/>
		<updated>2013-09-18T22:43:00Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* Comparision with C++ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will help us understand the ruby object model, speak about it's comparison to object models of other [http://en.wikipedia.org/wiki/Programming_languages programming languages] and explain it's advantages and disadvantages in detail.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it recognizes all of it's basic constructs ([http://en.wikipedia.org/wiki/Variable_(computer_science) variables], operations, classes etc...) as objects. Every bit of information and code can be given their own properties and actions.Rules applicable to objects are relevant to all constructs of ruby. &amp;lt;ref&amp;gt;https://www.ruby-lang.org/en/about&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that add [http://en.wikipedia.org/wiki/Method_(computer_programming) methods] to numbers and strings.&lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Diplays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object [http://en.wikipedia.org/wiki/Hierarchy Hierarchy] of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &amp;lt;ref&amp;gt; http://www.slideshare.net/cchamnap/ruby-object-model-4978263 &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''“Class”''. Classes are defined in Ruby using the '''class''' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter. In case of more than one word in the class name, the first letter of every word must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as '''''attr_accessor'''''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparision with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected access specifiers for methods.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports [http://en.wikipedia.org/wiki/Inheritance inheritance] of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses [http://en.wikipedia.org/wiki/Interfaces_(computer_science) interfaces] for defining empty methods which are later handled by [http://en.wikipedia.org/wiki/Concrete_class#Abstract_and_Concrete concrete class] objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, [http://en.wikipedia.org/wiki/Constructor_(object-oriented_programming) constructor] is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are [http://en.wikipedia.org/wiki/Immutable_object immutable] (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparision with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behaviour of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a compile-time entity. || A ruby class is a run-time entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| Variables in C++ refer to data members of corresponding classes. || There’s no explicit references in Ruby. Every variable is a name for some object.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| We have to include all the required functionality while defining the class. || We can reopen a class at anytime and add functionality.  &lt;br /&gt;
|- &lt;br /&gt;
|C++ does not need a base class as it supports [http://en.wikipedia.org/wiki/Generic_programming generic programming]. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the opena&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78268</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78268"/>
		<updated>2013-09-18T22:41:19Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* Comparison with Java */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will help us understand the ruby object model, speak about it's comparison to object models of other [http://en.wikipedia.org/wiki/Programming_languages programming languages] and explain it's advantages and disadvantages in detail.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it recognizes all of it's basic constructs ([http://en.wikipedia.org/wiki/Variable_(computer_science) variables], operations, classes etc...) as objects. Every bit of information and code can be given their own properties and actions.Rules applicable to objects are relevant to all constructs of ruby. &amp;lt;ref&amp;gt;https://www.ruby-lang.org/en/about&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that add [http://en.wikipedia.org/wiki/Method_(computer_programming) methods] to numbers and strings.&lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Diplays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object [http://en.wikipedia.org/wiki/Hierarchy Hierarchy] of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &amp;lt;ref&amp;gt; http://www.slideshare.net/cchamnap/ruby-object-model-4978263 &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''“Class”''. Classes are defined in Ruby using the '''class''' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter. In case of more than one word in the class name, the first letter of every word must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as '''''attr_accessor'''''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparision with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected access specifiers for methods.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports [http://en.wikipedia.org/wiki/Inheritance inheritance] of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses [http://en.wikipedia.org/wiki/Interfaces_(computer_science) interfaces] for defining empty methods which are later handled by [http://en.wikipedia.org/wiki/Concrete_class#Abstract_and_Concrete concrete class] objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, [http://en.wikipedia.org/wiki/Constructor_(object-oriented_programming) constructor] is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are [http://en.wikipedia.org/wiki/Immutable_object immutable] (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparision with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behaviour of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a compile-time entity. || A ruby class is a run-time entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| Variables in C++ refer to data members of corresponding classes. || There’s no explicit references in Ruby. Every variable is a name for some object.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| We have to include all the required functionality while defining the class. || We can reopen a class at anytime and add functionality.  &lt;br /&gt;
|- &lt;br /&gt;
|C++ does not need a base class as it supports generic programming. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the opena&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78266</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78266"/>
		<updated>2013-09-18T22:40:00Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* Comparison with Java */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will help us understand the ruby object model, speak about it's comparison to object models of other [http://en.wikipedia.org/wiki/Programming_languages programming languages] and explain it's advantages and disadvantages in detail.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it recognizes all of it's basic constructs ([http://en.wikipedia.org/wiki/Variable_(computer_science) variables], operations, classes etc...) as objects. Every bit of information and code can be given their own properties and actions.Rules applicable to objects are relevant to all constructs of ruby. &amp;lt;ref&amp;gt;https://www.ruby-lang.org/en/about&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that add [http://en.wikipedia.org/wiki/Method_(computer_programming) methods] to numbers and strings.&lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Diplays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object [http://en.wikipedia.org/wiki/Hierarchy Hierarchy] of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &amp;lt;ref&amp;gt; http://www.slideshare.net/cchamnap/ruby-object-model-4978263 &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''“Class”''. Classes are defined in Ruby using the '''class''' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter. In case of more than one word in the class name, the first letter of every word must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as '''''attr_accessor'''''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparision with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected access specifiers for methods.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports [http://en.wikipedia.org/wiki/Inheritance inheritance] of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses [http://en.wikipedia.org/wiki/Interfaces_(computer_science) interfaces] for defining empty methods which are later handled by [http://en.wikipedia.org/wiki/Concrete_class#Abstract_and_Concrete concrete class] objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, constructor is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are immutable (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparision with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behaviour of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a compile-time entity. || A ruby class is a run-time entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| Variables in C++ refer to data members of corresponding classes. || There’s no explicit references in Ruby. Every variable is a name for some object.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| We have to include all the required functionality while defining the class. || We can reopen a class at anytime and add functionality.  &lt;br /&gt;
|- &lt;br /&gt;
|C++ does not need a base class as it supports generic programming. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the opena&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78262</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78262"/>
		<updated>2013-09-18T22:37:52Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* Comparison with Java */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will help us understand the ruby object model, speak about it's comparison to object models of other [http://en.wikipedia.org/wiki/Programming_languages programming languages] and explain it's advantages and disadvantages in detail.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it recognizes all of it's basic constructs ([http://en.wikipedia.org/wiki/Variable_(computer_science) variables], operations, classes etc...) as objects. Every bit of information and code can be given their own properties and actions.Rules applicable to objects are relevant to all constructs of ruby. &amp;lt;ref&amp;gt;https://www.ruby-lang.org/en/about&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that add [http://en.wikipedia.org/wiki/Method_(computer_programming) methods] to numbers and strings.&lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Diplays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object [http://en.wikipedia.org/wiki/Hierarchy Hierarchy] of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &amp;lt;ref&amp;gt; http://www.slideshare.net/cchamnap/ruby-object-model-4978263 &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''“Class”''. Classes are defined in Ruby using the '''class''' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter. In case of more than one word in the class name, the first letter of every word must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as '''''attr_accessor'''''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparision with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected access specifiers for methods.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports [http://en.wikipedia.org/wiki/Inheritance inheritance] of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses interfaces for defining empty methods which are later handled by concrete class objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, constructor is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are immutable (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparision with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behaviour of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a compile-time entity. || A ruby class is a run-time entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| Variables in C++ refer to data members of corresponding classes. || There’s no explicit references in Ruby. Every variable is a name for some object.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| We have to include all the required functionality while defining the class. || We can reopen a class at anytime and add functionality.  &lt;br /&gt;
|- &lt;br /&gt;
|C++ does not need a base class as it supports generic programming. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the opena&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78242</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78242"/>
		<updated>2013-09-18T21:41:40Z</updated>

		<summary type="html">&lt;p&gt;Sandi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will help us understand the ruby object model, speak about it's comparison to object models of other [http://en.wikipedia.org/wiki/Programming_languages programming languages] and explain it's advantages and disadvantages in detail.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it recognizes all of it's basic constructs ([http://en.wikipedia.org/wiki/Variable_(computer_science) variables], operations, classes etc...) as objects. Every bit of information and code can be given their own properties and actions.Rules applicable to objects are relevant to all constructs of ruby. &amp;lt;ref&amp;gt;https://www.ruby-lang.org/en/about&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that add [http://en.wikipedia.org/wiki/Method_(computer_programming) methods] to numbers and strings.&lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Diplays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object [http://en.wikipedia.org/wiki/Hierarchy Hierarchy] of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &amp;lt;ref&amp;gt; http://www.slideshare.net/cchamnap/ruby-object-model-4978263 &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''“Class”''. Classes are defined in Ruby using the '''class''' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter. In case of more than one word in the class name, the first letter of every word must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as '''''attr_accessor'''''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparision with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected access specifiers for methods.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports inheritance of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses interfaces for defining empty methods which are later handled by concrete class objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, constructor is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are immutable (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparision with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behaviour of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a compile-time entity. || A ruby class is a run-time entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| Variables in C++ refer to data members of corresponding classes. || There’s no explicit references in Ruby. Every variable is a name for some object.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| We have to include all the required functionality while defining the class. || We can reopen a class at anytime and add functionality.  &lt;br /&gt;
|- &lt;br /&gt;
|C++ does not need a base class as it supports generic programming. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the opena&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78240</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78240"/>
		<updated>2013-09-18T21:40:43Z</updated>

		<summary type="html">&lt;p&gt;Sandi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will help us understand the ruby object model, speak about it's comparison to object models of other [http://en.wikipedia.org/wiki/Programming_languages programming languages] and explain it's advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it recognizes all of it's basic constructs ([http://en.wikipedia.org/wiki/Variable_(computer_science) variables], operations, classes etc...) as objects. Every bit of information and code can be given their own properties and actions.Rules applicable to objects are relevant to all constructs of ruby. &amp;lt;ref&amp;gt;https://www.ruby-lang.org/en/about&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that add [http://en.wikipedia.org/wiki/Method_(computer_programming) methods] to numbers and strings.&lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Diplays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object [http://en.wikipedia.org/wiki/Hierarchy Hierarchy] of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &amp;lt;ref&amp;gt; http://www.slideshare.net/cchamnap/ruby-object-model-4978263 &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''“Class”''. Classes are defined in Ruby using the '''class''' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter. In case of more than one word in the class name, the first letter of every word must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as '''''attr_accessor'''''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparision with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected access specifiers for methods.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports inheritance of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses interfaces for defining empty methods which are later handled by concrete class objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, constructor is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are immutable (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparision with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behaviour of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a compile-time entity. || A ruby class is a run-time entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| Variables in C++ refer to data members of corresponding classes. || There’s no explicit references in Ruby. Every variable is a name for some object.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| We have to include all the required functionality while defining the class. || We can reopen a class at anytime and add functionality.  &lt;br /&gt;
|- &lt;br /&gt;
|C++ does not need a base class as it supports generic programming. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the opena&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78235</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78235"/>
		<updated>2013-09-18T21:29:23Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* Ruby Object Model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will help us [[understand the ruby object model]], comparison to object models of other [http://en.wikipedia.org/wiki/Programming_languages programming languages] along with it's advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it recognizes all of it's basic constructs ([http://en.wikipedia.org/wiki/Variable_(computer_science) variables], operations, classes etc...) as objects. Every bit of information and code can be given their own properties and actions.Rules applicable to objects are relevant to all constructs of ruby. &amp;lt;ref&amp;gt;https://www.ruby-lang.org/en/about&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that add [http://en.wikipedia.org/wiki/Method_(computer_programming) methods] to numbers and strings.&lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Diplays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object [http://en.wikipedia.org/wiki/Hierarchy Hierarchy] of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &amp;lt;ref&amp;gt; http://www.slideshare.net/cchamnap/ruby-object-model-4978263 &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''“Class”''. Classes are defined in Ruby using the '''class''' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter. In case of more than one word in the class name, the first letter of every word must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as '''''attr_accessor'''''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparision with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected access specifiers for methods.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports inheritance of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses interfaces for defining empty methods which are later handled by concrete class objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, constructor is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are immutable (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparision with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behaviour of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a compile-time entity. || A ruby class is a run-time entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| Variables in C++ refer to data members of corresponding classes. || There’s no explicit references in Ruby. Every variable is a name for some object.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| We have to include all the required functionality while defining the class. || We can reopen a class at anytime and add functionality.  &lt;br /&gt;
|- &lt;br /&gt;
|C++ does not need a base class as it supports generic programming. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the opena&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78232</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78232"/>
		<updated>2013-09-18T21:24:25Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will explain, with illustrative examples, about the Ruby [http://en.wikipedia.org/wiki/Object_model Object-model], it's components, comparison to object models of other [http://en.wikipedia.org/wiki/Programming_languages programming languages] along with it's advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it recognizes all of it's basic constructs ([http://en.wikipedia.org/wiki/Variable_(computer_science) variables], operations, classes etc...) as objects. Every bit of information and code can be given their own properties and actions.Rules applicable to objects are relevant to all constructs of ruby. &amp;lt;ref&amp;gt;https://www.ruby-lang.org/en/about&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that add [http://en.wikipedia.org/wiki/Method_(computer_programming) methods] to numbers and strings.&lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Diplays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object [http://en.wikipedia.org/wiki/Hierarchy Hierarchy] of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &amp;lt;ref&amp;gt; http://www.slideshare.net/cchamnap/ruby-object-model-4978263 &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''“Class”''. Classes are defined in Ruby using the '''class''' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter. In case of more than one word in the class name, the first letter of every word must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as '''''attr_accessor'''''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparision with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected access specifiers for methods.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports inheritance of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses interfaces for defining empty methods which are later handled by concrete class objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, constructor is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are immutable (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparision with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behaviour of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a compile-time entity. || A ruby class is a run-time entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| Variables in C++ refer to data members of corresponding classes. || There’s no explicit references in Ruby. Every variable is a name for some object.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| We have to include all the required functionality while defining the class. || We can reopen a class at anytime and add functionality.  &lt;br /&gt;
|- &lt;br /&gt;
|C++ does not need a base class as it supports generic programming. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the opena&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78231</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78231"/>
		<updated>2013-09-18T21:24:09Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* See Also */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will explain, with illustrative examples, about the Ruby [http://en.wikipedia.org/wiki/Object_model Object-model], it's components, comparison to object models of other [http://en.wikipedia.org/wiki/Programming_languages programming languages] along with it's advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it recognizes all of it's basic constructs ([http://en.wikipedia.org/wiki/Variable_(computer_science) variables], operations, classes etc...) as objects. Every bit of information and code can be given their own properties and actions.Rules applicable to objects are relevant to all constructs of ruby. &amp;lt;ref&amp;gt;https://www.ruby-lang.org/en/about&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that add [http://en.wikipedia.org/wiki/Method_(computer_programming) methods] to numbers and strings.&lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Diplays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object [http://en.wikipedia.org/wiki/Hierarchy Hierarchy] of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &amp;lt;ref&amp;gt; http://www.slideshare.net/cchamnap/ruby-object-model-4978263 &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''“Class”''. Classes are defined in Ruby using the '''class''' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter. In case of more than one word in the class name, the first letter of every word must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as '''''attr_accessor'''''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparision with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected access specifiers for methods.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports inheritance of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses interfaces for defining empty methods which are later handled by concrete class objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, constructor is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are immutable (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparision with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behaviour of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a compile-time entity. || A ruby class is a run-time entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| Variables in C++ refer to data members of corresponding classes. || There’s no explicit references in Ruby. Every variable is a name for some object.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| We have to include all the required functionality while defining the class. || We can reopen a class at anytime and add functionality.  &lt;br /&gt;
|- &lt;br /&gt;
|C++ does not need a base class as it supports generic programming. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the opena&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=See Also  =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78230</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78230"/>
		<updated>2013-09-18T21:23:57Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* Disadvantages of the Ruby Object Model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will explain, with illustrative examples, about the Ruby [http://en.wikipedia.org/wiki/Object_model Object-model], it's components, comparison to object models of other [http://en.wikipedia.org/wiki/Programming_languages programming languages] along with it's advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it recognizes all of it's basic constructs ([http://en.wikipedia.org/wiki/Variable_(computer_science) variables], operations, classes etc...) as objects. Every bit of information and code can be given their own properties and actions.Rules applicable to objects are relevant to all constructs of ruby. &amp;lt;ref&amp;gt;https://www.ruby-lang.org/en/about&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that add [http://en.wikipedia.org/wiki/Method_(computer_programming) methods] to numbers and strings.&lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Diplays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object [http://en.wikipedia.org/wiki/Hierarchy Hierarchy] of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &amp;lt;ref&amp;gt; http://www.slideshare.net/cchamnap/ruby-object-model-4978263 &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''“Class”''. Classes are defined in Ruby using the '''class''' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter. In case of more than one word in the class name, the first letter of every word must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as '''''attr_accessor'''''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparision with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected access specifiers for methods.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports inheritance of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses interfaces for defining empty methods which are later handled by concrete class objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, constructor is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are immutable (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparision with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behaviour of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a compile-time entity. || A ruby class is a run-time entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| Variables in C++ refer to data members of corresponding classes. || There’s no explicit references in Ruby. Every variable is a name for some object.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| We have to include all the required functionality while defining the class. || We can reopen a class at anytime and add functionality.  &lt;br /&gt;
|- &lt;br /&gt;
|C++ does not need a base class as it supports generic programming. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the opena&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==See Also  ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78229</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78229"/>
		<updated>2013-09-18T21:23:41Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* Advantages of the Ruby Object Model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will explain, with illustrative examples, about the Ruby [http://en.wikipedia.org/wiki/Object_model Object-model], it's components, comparison to object models of other [http://en.wikipedia.org/wiki/Programming_languages programming languages] along with it's advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it recognizes all of it's basic constructs ([http://en.wikipedia.org/wiki/Variable_(computer_science) variables], operations, classes etc...) as objects. Every bit of information and code can be given their own properties and actions.Rules applicable to objects are relevant to all constructs of ruby. &amp;lt;ref&amp;gt;https://www.ruby-lang.org/en/about&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that add [http://en.wikipedia.org/wiki/Method_(computer_programming) methods] to numbers and strings.&lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Diplays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object [http://en.wikipedia.org/wiki/Hierarchy Hierarchy] of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &amp;lt;ref&amp;gt; http://www.slideshare.net/cchamnap/ruby-object-model-4978263 &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''“Class”''. Classes are defined in Ruby using the '''class''' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter. In case of more than one word in the class name, the first letter of every word must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as '''''attr_accessor'''''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparision with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected access specifiers for methods.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports inheritance of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses interfaces for defining empty methods which are later handled by concrete class objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, constructor is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are immutable (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparision with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behaviour of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a compile-time entity. || A ruby class is a run-time entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| Variables in C++ refer to data members of corresponding classes. || There’s no explicit references in Ruby. Every variable is a name for some object.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| We have to include all the required functionality while defining the class. || We can reopen a class at anytime and add functionality.  &lt;br /&gt;
|- &lt;br /&gt;
|C++ does not need a base class as it supports generic programming. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Advantages of the Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the opena&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==Disadvantages of the Ruby Object Model==&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==See Also  ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78228</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78228"/>
		<updated>2013-09-18T21:23:13Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* Comparision with other Object-Oriented languages */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will explain, with illustrative examples, about the Ruby [http://en.wikipedia.org/wiki/Object_model Object-model], it's components, comparison to object models of other [http://en.wikipedia.org/wiki/Programming_languages programming languages] along with it's advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it recognizes all of it's basic constructs ([http://en.wikipedia.org/wiki/Variable_(computer_science) variables], operations, classes etc...) as objects. Every bit of information and code can be given their own properties and actions.Rules applicable to objects are relevant to all constructs of ruby. &amp;lt;ref&amp;gt;https://www.ruby-lang.org/en/about&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that add [http://en.wikipedia.org/wiki/Method_(computer_programming) methods] to numbers and strings.&lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Diplays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object [http://en.wikipedia.org/wiki/Hierarchy Hierarchy] of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &amp;lt;ref&amp;gt; http://www.slideshare.net/cchamnap/ruby-object-model-4978263 &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''“Class”''. Classes are defined in Ruby using the '''class''' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter. In case of more than one word in the class name, the first letter of every word must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as '''''attr_accessor'''''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Comparision with other Object-Oriented languages =&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected access specifiers for methods.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports inheritance of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses interfaces for defining empty methods which are later handled by concrete class objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, constructor is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are immutable (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparision with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behaviour of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a compile-time entity. || A ruby class is a run-time entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| Variables in C++ refer to data members of corresponding classes. || There’s no explicit references in Ruby. Every variable is a name for some object.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| We have to include all the required functionality while defining the class. || We can reopen a class at anytime and add functionality.  &lt;br /&gt;
|- &lt;br /&gt;
|C++ does not need a base class as it supports generic programming. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==Advantages of the Ruby Object Model==&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the opena&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==Disadvantages of the Ruby Object Model==&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==See Also  ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78227</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78227"/>
		<updated>2013-09-18T21:22:53Z</updated>

		<summary type="html">&lt;p&gt;Sandi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will explain, with illustrative examples, about the Ruby [http://en.wikipedia.org/wiki/Object_model Object-model], it's components, comparison to object models of other [http://en.wikipedia.org/wiki/Programming_languages programming languages] along with it's advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it recognizes all of it's basic constructs ([http://en.wikipedia.org/wiki/Variable_(computer_science) variables], operations, classes etc...) as objects. Every bit of information and code can be given their own properties and actions.Rules applicable to objects are relevant to all constructs of ruby. &amp;lt;ref&amp;gt;https://www.ruby-lang.org/en/about&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that add [http://en.wikipedia.org/wiki/Method_(computer_programming) methods] to numbers and strings.&lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Diplays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object [http://en.wikipedia.org/wiki/Hierarchy Hierarchy] of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &amp;lt;ref&amp;gt; http://www.slideshare.net/cchamnap/ruby-object-model-4978263 &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''“Class”''. Classes are defined in Ruby using the '''class''' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter. In case of more than one word in the class name, the first letter of every word must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as '''''attr_accessor'''''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Comparision with other Object-Oriented languages ==&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected access specifiers for methods.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports inheritance of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses interfaces for defining empty methods which are later handled by concrete class objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, constructor is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are immutable (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparision with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behaviour of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a compile-time entity. || A ruby class is a run-time entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| Variables in C++ refer to data members of corresponding classes. || There’s no explicit references in Ruby. Every variable is a name for some object.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| We have to include all the required functionality while defining the class. || We can reopen a class at anytime and add functionality.  &lt;br /&gt;
|- &lt;br /&gt;
|C++ does not need a base class as it supports generic programming. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==Advantages of the Ruby Object Model==&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the opena&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==Disadvantages of the Ruby Object Model==&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==See Also  ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78225</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78225"/>
		<updated>2013-09-18T21:20:50Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* Ruby Object Model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will explain, with illustrative examples, about the Ruby [http://en.wikipedia.org/wiki/Object_model Object-model], it's components, comparison to object models of other [http://en.wikipedia.org/wiki/Programming_languages programming languages] along with it's advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it recognizes all of it's basic constructs ([http://en.wikipedia.org/wiki/Variable_(computer_science) variables], operations, classes etc...) as objects. Every bit of information and code can be given their own properties and actions.Rules applicable to objects are relevant to all constructs of ruby. &amp;lt;ref&amp;gt;https://www.ruby-lang.org/en/about&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that add [http://en.wikipedia.org/wiki/Method_(computer_programming) methods] to numbers and strings.&lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Diplays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object [http://en.wikipedia.org/wiki/Hierarchy Hierarchy] of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &amp;lt;ref&amp;gt; http://www.slideshare.net/cchamnap/ruby-object-model-4978263 &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''“Class”''. Classes are defined in Ruby using the '''class''' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter. In case of more than one word in the class name, the first letter of every word must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as '''''attr_accessor'''''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Comparision with other Object-Oriented languages ==&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected access specifiers for methods.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports inheritance of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses interfaces for defining empty methods which are later handled by concrete class objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, constructor is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are immutable (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparision with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behaviour of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a compile-time entity. || A ruby class is a run-time entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| Variables in C++ refer to data members of corresponding classes. || There’s no explicit references in Ruby. Every variable is a name for some object.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| We have to include all the required functionality while defining the class. || We can reopen a class at anytime and add functionality.  &lt;br /&gt;
|- &lt;br /&gt;
|C++ does not need a base class as it supports generic programming. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==Advantages of the Ruby Object Model==&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the opena&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==Disadvantages of the Ruby Object Model==&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==See Also  ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78224</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w14 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w14_st&amp;diff=78224"/>
		<updated>2013-09-18T21:20:34Z</updated>

		<summary type="html">&lt;p&gt;Sandi: /* Ruby Object Model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby Object Model=&lt;br /&gt;
&lt;br /&gt;
&amp;quot;''In [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], everything is an [http://en.wikipedia.org/wiki/Object_(computer_science) object]!''&amp;quot; is one of the most common phrases in the Ruby programming world. This is indeed a very unique feature of Ruby. This article will explain, with illustrative examples, about the Ruby [http://en.wikipedia.org/wiki/Object_model Object-model], it's components, comparison to object models of other [http://en.wikipedia.org/wiki/Programming_languages programming languages] along with it's advantages and disadvantages.&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Understanding the Ruby Object Model=&lt;br /&gt;
Ruby is distinct to other [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming languages in a way that it recognizes all of it's basic constructs ([http://en.wikipedia.org/wiki/Variable_(computer_science) variables], operations, classes etc...) as objects. Every bit of information and code can be given their own properties and actions.Rules applicable to objects are relevant to all constructs of ruby. &amp;lt;ref&amp;gt;https://www.ruby-lang.org/en/about&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In many languages, numbers and other [http://en.wikipedia.org/wiki/Primitive_data_type primitive data-types] are not objects. Ruby’s pure object-oriented approach can be illustrated by the following examples that add [http://en.wikipedia.org/wiki/Method_(computer_programming) methods] to numbers and strings.&lt;br /&gt;
&lt;br /&gt;
 ''' Example: '''  &lt;br /&gt;
     1234.7643.class   ''# Diplays the class to which the object 1234.7643 belongs.'' &lt;br /&gt;
  '''Output :'''  &lt;br /&gt;
     =&amp;gt; Float &lt;br /&gt;
&lt;br /&gt;
Ruby objects can also handle more than one methods at a time. Let's take the following examples :&lt;br /&gt;
&lt;br /&gt;
 ''' Example:''' &lt;br /&gt;
     &amp;quot;Hello&amp;quot;.reverse.upcase.length   ''# Performs the reverse, upcase and length operation sequentially on the string object.''&lt;br /&gt;
 ''' Output:'''&lt;br /&gt;
     =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
   '''Example:'''&lt;br /&gt;
      a=[1,4,5,3,2]&lt;br /&gt;
      a.reverse.sort   ''#reverses first to [2,3,5,4,1] and then sorts''&lt;br /&gt;
   '''Output:'''&lt;br /&gt;
      = &amp;gt; [1,2,3,4,5]  &lt;br /&gt;
&lt;br /&gt;
===Diagramatic Representation===&lt;br /&gt;
&lt;br /&gt;
Let us consider the following Ruby code snippet:&lt;br /&gt;
&lt;br /&gt;
   class Vehicle&lt;br /&gt;
       def tyres(tyre_num)&lt;br /&gt;
           return tyre_num&lt;br /&gt;
       end&lt;br /&gt;
   end &lt;br /&gt;
     car=Vehicle.new()&lt;br /&gt;
        puts car.tyres(4)&lt;br /&gt;
     truck=Vehicle.new()&lt;br /&gt;
        puts truck.tyres(6)&lt;br /&gt;
     bike=Vehicle.new()&lt;br /&gt;
        puts bike.tyres(2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object [http://en.wikipedia.org/wiki/Hierarchy Hierarchy] of the above code will be :-&lt;br /&gt;
&lt;br /&gt;
[[File:RubyObjectModel.jpg]]&lt;br /&gt;
&lt;br /&gt;
''Fig.1'' &lt;br /&gt;
''An illustration of the Ruby Object Model''&amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/Class.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above diagram, the objects car, truck and bike are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the [http://en.wikipedia.org/wiki/Class_(computer_programming) class] Vehicle. Vehicle in itself is an instance of(object of) the class 'Class'. Since in Ruby everything is an object, all the instances of the 'Vehicle' class, the Vehicle class itself and the class 'Class' are all objects of the 'Object' class. &lt;br /&gt;
Object [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inherits] from BasicObject. BasicObject is the parent class of all classes in Ruby. It's an explicit blank class and is used for creating object hierarchies independent of Ruby's object hierarchy. &amp;lt;ref&amp;gt; http://ruby-doc.org/core-1.9.3/BasicObject.html &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objects===&lt;br /&gt;
An object is an instance of a class. It has properties like any physical object in the real-world. In Ruby, everything is an object. To simply explain what an “object” is; it’s a thing that you send a message to. All the action in Ruby happens because you send a message to an object. In order for an object to respond meaningfully to this message, it must possess internal knowledge of the message — a series of computational steps saying what should happen when a particular message arrives, which in Ruby, is done with the help of  a method. To send a particular message to an object is to call that method of the object. &amp;lt;ref&amp;gt;&lt;br /&gt;
http://www.apeth.com/rubyIntro/justenoughruby.html#theobjectorientedstructureofruby &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Object's built-in properties====&lt;br /&gt;
Every object has some built-in properties :- &amp;lt;ref&amp;gt; http://www.slideshare.net/cchamnap/ruby-object-model-4978263 &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* ''' object_id  '''&lt;br /&gt;
object_id returns an unique integer identifier for the object. This integer will be returned on all calls to id for a given object.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    day = “Tuesday”&lt;br /&gt;
    day.object_id&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    =&amp;gt; 19712676&lt;br /&gt;
 &lt;br /&gt;
* '''respond_to?'''&lt;br /&gt;
respond_to? returns true if the object responds to a given method, else if the method is not defined, respond_to_missing? method is called and the result is returned.&lt;br /&gt;
If the method is not implemented, false is returned.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Private_method#Member_accessibility Private and protected methods] are included in the search only if the optional second parameter evaluates to true.&lt;br /&gt;
 &lt;br /&gt;
  '''Syntax:'''   respond_to?(symbol, include_all=false or true[optional])&lt;br /&gt;
&lt;br /&gt;
  '''Example:''' &lt;br /&gt;
     @student.respond_to?('course_work')&lt;br /&gt;
  '''Explanation:''' The code would return true if the Student class has an course_work method on it.&lt;br /&gt;
 &lt;br /&gt;
* '''send ''' &lt;br /&gt;
Send method can be used on any object to invoke a message handler. Additionally, Ruby makes it easier to express messages as we don’t necessarily need to use the send method, we can just use the shortcut ‘.’ (dot) operator.&lt;br /&gt;
 &lt;br /&gt;
   '''Example:'''&lt;br /&gt;
    2.send :+,3  ''same as''   2+3   &lt;br /&gt;
   '''Output:''' =&amp;gt; 5&lt;br /&gt;
&lt;br /&gt;
* ''' methods '''&lt;br /&gt;
Returns a list of the names of public and protected methods of the object which would include all the methods accessible in the object’s ancestors.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
 2.methods  # displays all the methods that the object 2 can call.&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
  =&amp;gt; [:to_s, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===,&lt;br /&gt;
   :&amp;lt;=&amp;gt;, :&amp;gt;, :&amp;gt;=, :&amp;lt;, :&amp;lt;=, :~, :&amp;amp;, :|, :^, :[], :&amp;lt;&amp;lt;, :&amp;gt;&amp;gt;, :to_f, :size, :zero?, :odd?, :even?, :succ,  &lt;br /&gt;
   :ord, :integer?, :upto, :downto, :times, :next, :pred, :chr, :to_i, :to_int, :floor, :ceil, &lt;br /&gt;
   :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, &lt;br /&gt;
   :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step,&lt;br /&gt;
   :to_c,:real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, &lt;br /&gt;
   :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, &lt;br /&gt;
   :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, &lt;br /&gt;
   :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, &lt;br /&gt;
   :instance_variables,:instance_variable_get, :instance_variable_set, :instance_variable_defined?, &lt;br /&gt;
   :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, &lt;br /&gt;
   :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for,&lt;br /&gt;
   :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]&lt;br /&gt;
&lt;br /&gt;
* ''' Instance Variables'''&lt;br /&gt;
Instance variables are created for each class instance and are accessible only within that instance. They are accessed using the @ operator and can be referenced by any method within the class but to access them outside of the class we use public methods which are called accessor methods.&lt;br /&gt;
 &lt;br /&gt;
 '''Example:'''&lt;br /&gt;
    class Lecture&lt;br /&gt;
     def initialize(name, subject, duration)&lt;br /&gt;
       @name = name&lt;br /&gt;
       @subject = subject&lt;br /&gt;
       @duration = duration&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
 '''Explanation:'''  If we take above defined class Lecture then @name, @subject and @duration are instance variables for the class Lecture.&lt;br /&gt;
&lt;br /&gt;
====Conceptual Components==== &lt;br /&gt;
&lt;br /&gt;
Conceptually, Ruby objects consists of the following: &amp;lt;ref&amp;gt; http://www.hokstad.com/ruby-object-model &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A reference to the object's immediate [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass] in the object model hierarchy.&lt;br /&gt;
* A [http://en.wikipedia.org/wiki/Hash_table hash table] of all the associated instance variables.&lt;br /&gt;
* A set of [http://en.wikipedia.org/wiki/Flag_word flags].&lt;br /&gt;
&lt;br /&gt;
===Classes===&lt;br /&gt;
&lt;br /&gt;
Class is an object of the class ''“Class”''. Classes are defined in Ruby using the '''class''' [http://en.wikipedia.org/wiki/Keyword_(computer_programming) keyword] followed by a name. The name of the class must begin with a capital letter. In case of more than one word in the class name, the first letter of every word must begin with a capital letter ([http://en.wikipedia.org/wiki/CamelCase CamelCase]). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context at read time, such as '''''attr_accessor'''''. The class declaration is terminated by the end keyword.&lt;br /&gt;
&lt;br /&gt;
 '''Example:'''&lt;br /&gt;
   class Example&lt;br /&gt;
    def greeting&lt;br /&gt;
      puts &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
  #Using above class to create objects&lt;br /&gt;
 object = Example.new&lt;br /&gt;
 object.greeting&lt;br /&gt;
 &lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Hello World!&lt;br /&gt;
&lt;br /&gt;
The above example defines a class named ‘Example’ with a single method called ‘greeting’ . Then an object which invokes the greeting method is created which prints the string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Object Relationships=&lt;br /&gt;
===Superclass/Subclass Relationship===&lt;br /&gt;
'''Inheritance'''&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) Inheritance] allows you to create a class that is a refinement or specialization of another class. The specialized class is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses subclass] and the parent from which it inherits these properties is called the [http://en.wikipedia.org/wiki/Superclass_(computer_science)#Subclasses_and_superclasses superclass]. The major use of inheritance is re-usability of the code.&lt;br /&gt;
&lt;br /&gt;
 Syntax: Sub-Class &amp;lt; Super-Class&lt;br /&gt;
&lt;br /&gt;
 '''Example:''' &lt;br /&gt;
 class SuperClass&lt;br /&gt;
   def method_1&lt;br /&gt;
    puts “Method 1”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 class SubClass &amp;lt; SuperClass&lt;br /&gt;
   def method_2&lt;br /&gt;
    puts “Method 2”&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 obj=SubClass.new&lt;br /&gt;
 obj.method_1&lt;br /&gt;
 obj.method_2&lt;br /&gt;
 '''Output:'''&lt;br /&gt;
    Method 1&lt;br /&gt;
    Method 2&lt;br /&gt;
&lt;br /&gt;
Thus, the sub-class in this example,'SubClass' inherits 'method_1' from its super-class, which is 'SuperClass',thereby, inheriting the properties of the super-class and extending its own properties.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Comparision with other Object-Oriented languages ==&lt;br /&gt;
===Comparison with Java===&lt;br /&gt;
&lt;br /&gt;
Java objects are similar to Ruby objects in some ways :- &amp;lt;ref name=ref1&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) garbage collector] takes care of memory handling.&lt;br /&gt;
* Objects are strongly typed.&lt;br /&gt;
* Both Ruby and java objects have public, private, and protected access specifiers for methods.&lt;br /&gt;
&lt;br /&gt;
The properties of a java object differ from that of a Ruby object in the following way :- &amp;lt;ref name=ref1 /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border = &amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in java  !! Objects in Ruby &lt;br /&gt;
|- &lt;br /&gt;
| Classes in java are pure definitions of set of inter-related variables and methods. They do not take memory. || Class itself is an object in Ruby and has memory. &lt;br /&gt;
|-&lt;br /&gt;
| Java supports inheritance of classes using the 'extends' keyword. || In Ruby, we use the '&amp;lt;' symbol to show inheritance.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses interfaces for defining empty methods which are later handled by concrete class objects. || Ruby does not support interfaces.&lt;br /&gt;
|-&lt;br /&gt;
| In java, constructor is used as the default method.  || In Ruby, the initialize method solves this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| Java uses the (.) operator to access class variables. || Ruby on the other hand, uses (.) variable to call methods on an object.&lt;br /&gt;
|-&lt;br /&gt;
| String objects in Java are immutable (state cannot be changed) || In Ruby, string objects are mutable.&lt;br /&gt;
|- &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparision with C++===  &lt;br /&gt;
&lt;br /&gt;
Typically, C++ objects are [http://en.wikipedia.org/wiki/Instance_(computer_science) instances] of the classes defined with member [http://en.wikipedia.org/wiki/Variable_(computer_science) variables] and [http://en.wikipedia.org/wiki/Method_(computer_programming) methods]. Let us see how the object properties of Ruby differ from those of C++. &amp;lt;ref&amp;gt; http://www.objs.com/x3h7/cplus.htm &amp;lt;/ref&amp;gt; &amp;lt;ref name=&amp;quot;ref2&amp;quot;&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Objects in C++  !! Objects in Ruby &lt;br /&gt;
|-&lt;br /&gt;
|    In C++, class defines only the blueprint of variables and mehods associated to them. It does not have memory.    ||    In ruby, classes are instances(objects) of the class 'Class'. &lt;br /&gt;
|-&lt;br /&gt;
| We need to declare the types for C++ objects. (statically-typed language) || Ruby objects take the type of the value they are assigned to. (dynamically typed)&lt;br /&gt;
|-&lt;br /&gt;
| Behaviour of an object is defined by it's member methods that are programmed by the user. || Every object in Ruby has a set of predefined methods on itself that can be accessed by using 'object.methods' clause. &lt;br /&gt;
|- &lt;br /&gt;
| In C++, initialization of instance variables of an object is done by a method named 'constructor'. || In Ruby, 'initialize' method is used for the same purpose.&lt;br /&gt;
|- &lt;br /&gt;
| A C++ class is a compile-time entity. || A ruby class is a run-time entity.&lt;br /&gt;
|- &lt;br /&gt;
| An abstract class in C++ has only definition. No objects of this class can be created.|| Ruby doesn't support the concept of abstract classes as a class is an instance in itself.&lt;br /&gt;
|-&lt;br /&gt;
| Variables in C++ refer to data members of corresponding classes. || There’s no explicit references in Ruby. Every variable is a name for some object.&lt;br /&gt;
|-&lt;br /&gt;
| In C++, 'this' keyword is used by object to reference itself. || In Ruby, self is used for this purpose.&lt;br /&gt;
|-&lt;br /&gt;
| We have to include all the required functionality while defining the class. || We can reopen a class at anytime and add functionality.  &lt;br /&gt;
|- &lt;br /&gt;
|C++ does not need a base class as it supports generic programming. || All classes in Ruby however, are instances of the 'Object' class which in turn is a sub-class of 'BasicObject' class.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Comparison with PHP===&lt;br /&gt;
&lt;br /&gt;
When we compare the Ruby object model with [http://en.wikipedia.org/wiki/PHP PHP] objects, the following are some of the distinctions we make :- &amp;lt;ref&amp;gt; https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Because Ruby is a strongly typed language, we will have to call on special methods to convert between strings, numbers and other object types whereas this is taken care of by the language itself in PHP. &lt;br /&gt;
* All arrays, hashes and similar data constructs in Ruby are objects. In PHP these are used as arguments for methods whereas in Ruby, we define methods on these objects. &lt;br /&gt;
* There is no need to use separate '[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]' classes in Ruby as reflection is an inherent property of the object.&lt;br /&gt;
* Unlike PHP, there are no [http://en.wikipedia.org/wiki/Interface_(computing) interfaces] or [http://en.wikipedia.org/wiki/Abstract_type abstract] classes in Ruby.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Variable_(computer_science) Variables] in Ruby are themselves object references.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==Advantages of the Ruby Object Model==&lt;br /&gt;
&lt;br /&gt;
* All objects are created at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) run time]. There is no [http://en.wikipedia.org/wiki/Compile_time compile time] in Ruby.&lt;br /&gt;
* Object properties can be altered during execution making it very flexible for the programmer.&lt;br /&gt;
* Ruby is a much simpler language than it's other object-oriented counterparts due to the absence of certain constructs such as  [http://en.wikipedia.org/wiki/Abstract_type abstract] classes and compile time nuances.&lt;br /&gt;
* Ruby provides callback methods that are called when certain aspects of the object model are changed – such as method added or class created. &amp;lt;ref&amp;gt; http://mastercontrolknob.wordpress.com/2013/01/13/ruby-object-model-part-1-basics/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
* Ruby Objects are strongly typed. &lt;br /&gt;
* If we notice, ruby methods within ruby objects do not require paranthesis. We can end a looping construct or a method within an object using the 'end' keyword. This reduces a lot of confusion in placing the opena&lt;br /&gt;
* Unlike in other programming languages, Ruby provides more flexibility to modify features of it's standard objects. Eg :- [http://en.wikipedia.org/wiki/String_(computer_science) String] objects in Ruby are mutable ie., Ruby defines upcase, lowcase and swapcase methods on them.&lt;br /&gt;
* An object in Ruby can identify it's own class when asked by the user using the '.class' method.&lt;br /&gt;
* It is easier to code in Ruby than in [http://en.wikipedia.org/wiki/C%2B%2B C++] or [http://en.wikipedia.org/wiki/Java_(programming_language) java] because of the simplified [http://en.wikipedia.org/wiki/Syntax_(programming_languages) syntax]. Hence the term &amp;quot;syntactic sugar&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==Disadvantages of the Ruby Object Model==&lt;br /&gt;
&lt;br /&gt;
* Though Ruby programs can be written quickly, there is too much load being shouldered at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime]. Hence, we may expect our Ruby code to execute much more slowly than in other object-oriented languages.&lt;br /&gt;
* Ruby does not support [http://en.wikipedia.org/wiki/Multiple_inheritance multiple inheritance] directly (though it introduces the concept of [http://en.wikipedia.org/wiki/Mixin mixins].)&lt;br /&gt;
*  It gets confusing when dealing with classes because they are also objects.&lt;br /&gt;
* One cannot discover whether a method within an object works or not until runtime. &amp;lt;ref name=ref2 /&amp;gt; &lt;br /&gt;
* There are only two container types for the objects to use : [http://en.wikipedia.org/wiki/Array arrays] and [http://en.wikipedia.org/wiki/Hash_function hashes].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==See Also  ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby programming Language] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_Java_Object Java Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Plain_Old_C%2B%2B_Object C++ Objects]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_model Object Model]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Document_object_model Document Object Model(DOM)]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Sandi</name></author>
	</entry>
</feed>