<?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=Asheikh</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=Asheikh"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Asheikh"/>
	<updated>2026-05-22T01:19:53Z</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_2012/ch2a_2w4_sa&amp;diff=69015</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w4 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w4_sa&amp;diff=69015"/>
		<updated>2012-10-27T08:06:30Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* Objectives */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''V - Model'''&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
[[File:Wiki image.jpg|thumb|420px|The V-model of the Systems Engineering Process.]]&lt;br /&gt;
The V-model also called as Verification and Validation model is a [http://en.wikipedia.org/wiki/Software_development_process software development process] which simplifies the understanding of the complexity associated with the development of a system,  and is an extension to the [http://en.wikipedia.org/wiki/Waterfall_model waterfall model]. Rather than proceeding linearly downwards, after the coding phase, the process steps are bent upwards to form a V shape. This creates an association between the phases in the development and the [http://en.wikipedia.org/wiki/Software_testing_life_cycle testing cycle].&lt;br /&gt;
&lt;br /&gt;
In the diagram, the left arm corresponds to the development phases in the traditional waterfall model and the right to the test phases. Each development activity carried out by the development team has its corresponding validation activity done by the testing team.&lt;br /&gt;
&lt;br /&gt;
=='''From Waterfall to V-Model'''==&lt;br /&gt;
&lt;br /&gt;
Every phase or stage in the waterfall model needs to be completed and signed off before the next phase can start, this rigidity affects the flexibility in iterating back and forth between the [http://www.investopedia.com/terms/d/developmentstage.asp#axzz2AS3WFJBq stages of development] with the result being a poor quality system. The V-Model prevents this by explicitly connecting the development and testing stages.&lt;br /&gt;
&lt;br /&gt;
=='''Objectives'''==&lt;br /&gt;
&lt;br /&gt;
The V-Model facilitates the [http://en.wikipedia.org/wiki/Planning planning] and [http://en.wikipedia.org/wiki/Implementation realization] of projects. The following are the objectives to be achieved during system development:&lt;br /&gt;
&lt;br /&gt;
*Minimizing Project Risks: Early recognition of planning deviations and risks improves process management, thus reducing risks.&lt;br /&gt;
&lt;br /&gt;
*Improving Quality: Defined intermediate results can be checked at an early stage. Uniform product contents will improve readability, understandability and verifiability.&lt;br /&gt;
&lt;br /&gt;
*Reduction of Total Cost: The results obtained should be uniform and easily retraced. This reduces the dependency on the supplier and the effort for subsequent activities.&lt;br /&gt;
&lt;br /&gt;
*Effective Communication between all [http://en.wikipedia.org/wiki/Stakeholder Stakeholders]: The miscommunication between user, supplier and developer is reduced.&lt;br /&gt;
&lt;br /&gt;
=='''Verification phase'''==&lt;br /&gt;
[[File:V model001.jpg|thumb|420px|V-Model in detail.]]&lt;br /&gt;
&lt;br /&gt;
Verification ensures that, the software is being built correctly. The [http://en.wikipedia.org/wiki/International_Software_Testing_Qualifications_Board ISTQB] defines Verification as: “Confirmation by examination and through provision of objective evidence that specified requirements have been fulfilled.&lt;br /&gt;
&lt;br /&gt;
The first part of the definition is the same as for Validation, but the second part is the key. This states that “specified requirements have been fulfilled“. The V-model diagram arrows shows that each produced product is checked against the products or documents that were used to drive the development. This ensures that all aspects have been met. A key problem is ensuring that the user requirements are adequately verified against the customer needs. The Business Case is only likely to contain high level functionality, and not the detail about processes that are essential for determining what is required.&lt;br /&gt;
&lt;br /&gt;
===Requirements Analysis===&lt;br /&gt;
&lt;br /&gt;
Requirements analysis encompasses those tasks that determine the conditions specified by the stakeholders for the product. Its activities are concerned with eliciting, analyzing, documenting, validating and managing system requirements. The requirements have to be documentable, actionable, measurable, testable, traceable, related to the business needs and should include details sufficient for system design.&lt;br /&gt;
&lt;br /&gt;
Requirements analysis includes three types of activities:&lt;br /&gt;
&lt;br /&gt;
*Eliciting requirements: Identifying the various types of requirements from various sources i.e. project and business process documentation along with stakeholder interviews.&lt;br /&gt;
&lt;br /&gt;
*Analyzing requirements: Determining whether the specified requirements are clear, complete and consistent.&lt;br /&gt;
&lt;br /&gt;
*Recording requirements: Requirements can be documented in normal language documents, use cases, user stories, or system specifications.&lt;br /&gt;
&lt;br /&gt;
Requirements analysis is a long process during which many changes can occur over that time period. Technology changes, business requirements changes with many other things, so it is important that the stakeholders are in constant touch with the developers to ensure that they understand the new improved system. It is the responsibility of the analyst to gather information from the customer. System prototypes should be developed to demonstrate a working model to the stakeholders. Analysts employ a combination of various methods to establish the exact requirements of the stakeholders, so that the system developed meets the customer’s needs. The information regarding the product requirements can be classified as: Customer, Architectural, Structural, Behavioral, Functional, Non-functional, Performance, Design, Derived, and Allocated Requirements.&lt;br /&gt;
&lt;br /&gt;
===System Design===&lt;br /&gt;
&lt;br /&gt;
This design process defines the architecture, components, modules, interfaces, and data required by a system to meet the mentioned system requirements. We can say that design is an act of taking the marketing information and creating the products to be manufactured. So, systems design is the process of defining and developing systems specified by the user.&lt;br /&gt;
&lt;br /&gt;
*Softwares that run on generic platforms have enhanced software engineering. &lt;br /&gt;
&lt;br /&gt;
*Object-oriented analysis and design methods are widely used for systems design.&lt;br /&gt;
&lt;br /&gt;
*UML is used for modeling software systems and designing high non-software systems and organizations.&lt;br /&gt;
&lt;br /&gt;
===Architecture Design===&lt;br /&gt;
&lt;br /&gt;
The design of computer and software architecture can be referred to as high-level design. The architecture selected should realize the list of modules, brief functionality of each module, the interface relationships between the modules, dependencies, database tables, architecture diagrams, technology details etc.&lt;br /&gt;
&lt;br /&gt;
Integration testing design is carried out in this phase.&lt;br /&gt;
&lt;br /&gt;
===Module Design===&lt;br /&gt;
&lt;br /&gt;
The module design phase is a low-level design. The designed system is broken up into smaller units and each of them is explained to the programmer. The low level design document will contain a detailed functional logic of the module:&lt;br /&gt;
&lt;br /&gt;
*database tables, with all elements, including their type and size&lt;br /&gt;
&lt;br /&gt;
*all interface details with complete API references&lt;br /&gt;
&lt;br /&gt;
*all dependency issues&lt;br /&gt;
&lt;br /&gt;
*error message listings&lt;br /&gt;
&lt;br /&gt;
*complete input and outputs for a module.&lt;br /&gt;
&lt;br /&gt;
Unit test design is developed in this stage.&lt;br /&gt;
&lt;br /&gt;
=='''Validation phase'''==&lt;br /&gt;
===Importance of Early Testing===&lt;br /&gt;
&lt;br /&gt;
Studies show that catching a fault early in the development stages before the system is released is more cost effective and it takes less resources to fix the system when compared to fixing it after its release. We must also take into account the reputation of the organisation, the cost associated with missing functionality, so in fact the true cost for fixing the system is much higher.&lt;br /&gt;
&lt;br /&gt;
In the waterfall model errors were found very late in the cycle because testing began at the end of the project. In the V-Model testing begins as early as possible. Prior to testing, the testing team works on various activities in parallel to the development activity which helps to get the test deliverable on time which includes creation of test cases, preparation of test strategies, test planning and test scripting.&lt;br /&gt;
&lt;br /&gt;
===Testing Types Matched to Development Stages===&lt;br /&gt;
&lt;br /&gt;
The first noticeable point of the V-Model is that the Test stage of the Waterfall model is bent upwards to make it a “V”. This stage is now separated out into the various types of testing. So this first step visually points out that there is more than one type of testing to consider for system development and like the development steps they build on one another, and have different objectives. The next important part of the “V” is to match each type of testing against the development stage it matches e.g. we have Component Design matched against Component Testing. This means that the testing stage does not start when the Construct Component stage has ended. Instead when each development stage starts, the testing for that stage also starts.&lt;br /&gt;
&lt;br /&gt;
===Unit testing===&lt;br /&gt;
&lt;br /&gt;
Unit testing, tests the low level design i.e. units. A unit is a basic module of the application on which testing is carried out, it may be an individual function or a procedure. These tests are created by the developers (white box testing) to verify the internal logic code. Input data are passed to the unit to test every case of execution.&lt;br /&gt;
&lt;br /&gt;
===Integration testing===&lt;br /&gt;
&lt;br /&gt;
Integration testing tests high level design i.e. components and their interfaces. In Integration testing the basic units will be tested together to check the interaction between them and finds errors in the interfaces. This is generally a black box testing method. Integration testing is  performed by program team leaders.&lt;br /&gt;
&lt;br /&gt;
===System testing===&lt;br /&gt;
&lt;br /&gt;
Once the entire system has been developed, it then has to be tested against the system specifications to validate if it provides the required features. In short, system testing is about checking the system as a whole. System testing involves a number of special types of tests to see if all the functional and nonfunctional requirements have been met. System testing is performed by system testers.&lt;br /&gt;
Reasons for carrying out a system test even after the unit and integration test&lt;br /&gt;
&lt;br /&gt;
*The previous testings were done against the system specifications. The system test, looks at the system from the perspective of the future user.&lt;br /&gt;
&lt;br /&gt;
*Many of the system functions and characteristics results from the interaction of  the modules, and can be tested only at this level. &lt;br /&gt;
&lt;br /&gt;
*Also, keeping in mind that the customer and the end user can be two different groups of people having their own requirements and interests. &lt;br /&gt;
&lt;br /&gt;
===Acceptance testing===&lt;br /&gt;
&lt;br /&gt;
The major purpose of Acceptance Testing is to validate or confirm that the system meets the  business requirements and gives an assurance before it is delivered to the end user. This phase is for testing the software in the real world by the end user to determine whether to accept the system or not.&lt;br /&gt;
&lt;br /&gt;
===Release testing===&lt;br /&gt;
&lt;br /&gt;
This testing phase answers important questions such as&lt;br /&gt;
&lt;br /&gt;
*Is the software suitable for the end user?&lt;br /&gt;
&lt;br /&gt;
*Has the compatibility with other systems been ensured?&lt;br /&gt;
&lt;br /&gt;
*Is the performance of the software optimized?&lt;br /&gt;
&lt;br /&gt;
=='''Advantages'''==&lt;br /&gt;
&lt;br /&gt;
*Early acceptance criteria is the key advantage, they are performed against a specification of requirements.&lt;br /&gt;
&lt;br /&gt;
*60 to 70 percent of all faults are in the system before the component construction and test stages start, which is taken care of. &lt;br /&gt;
&lt;br /&gt;
*At an early stage we can feed back to catch a fault before it is built into the system.&lt;br /&gt;
&lt;br /&gt;
*Specifies test requirements and expected results prior to performing the actual tests.&lt;br /&gt;
&lt;br /&gt;
*Defines who is responsible for performing the testing and provides a focus for defining the testing that takes place at each stage. &lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages'''==&lt;br /&gt;
&lt;br /&gt;
*Too simple to reflect the development process.&lt;br /&gt;
&lt;br /&gt;
*Leads project managers to a false sense of security.&lt;br /&gt;
&lt;br /&gt;
*Inflexible and no ability to respond to change.&lt;br /&gt;
&lt;br /&gt;
*Produces inefficient testing methodologies&lt;br /&gt;
&lt;br /&gt;
*The placing of contracts for services is not regulated.&lt;br /&gt;
&lt;br /&gt;
*The organization and execution of operation, maintenance, repair and disposal of the system are not covered by the V-Model. &lt;br /&gt;
&lt;br /&gt;
*The V-Model addresses software development within a project rather than a whole organization.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
&lt;br /&gt;
Testing in the development process is critical. The earlier a fault is found, the cheaper it is to fix. The V model extends testing to the beginning of the life-cycle. The explicit recognition of testing in the V-model makes it very useful in planning and executing information system development. The V-Model has evolved over time and supports flexibility and agility throughout the development process. Static testing techniques, such as inspections and walkthroughs, can be used to find faults in the functional specification, as well as defining test cases that are subsequently executed in system testing.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&lt;br /&gt;
*http://www.softwaretestingclass.com/v-model/&lt;br /&gt;
&lt;br /&gt;
*http://en.wikipedia.org/wiki/V-Model_(software_development)&lt;br /&gt;
&lt;br /&gt;
*http://en.wikipedia.org/wiki/V-Model&lt;br /&gt;
&lt;br /&gt;
*http://www.careerride.com/testing-v-model.aspx&lt;br /&gt;
&lt;br /&gt;
*http://www.softwaretestingmentor.com/sdlc/vmodel.php&lt;br /&gt;
&lt;br /&gt;
*http://www.bucanac.com/documents/The_V-Model.pdf&lt;br /&gt;
&lt;br /&gt;
*http://www.compensationanalytics.com/_resources/vtestingmodel.pdf&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
&lt;br /&gt;
*Dual Vee Model - http://en.wikipedia.org/wiki/Dual_Vee_Model&lt;br /&gt;
&lt;br /&gt;
*System Development Lifecycle - http://en.wikipedia.org/wiki/Systems_Development_Life_Cycle&lt;br /&gt;
&lt;br /&gt;
*Product Lifecycle Management - http://en.wikipedia.org/wiki/Product_lifecycle_management&lt;br /&gt;
&lt;br /&gt;
*Portal: Software Testing - http://en.wikipedia.org/wiki/Portal:Software_Testing&lt;br /&gt;
&lt;br /&gt;
*IBM RUP - http://en.wikipedia.org/wiki/RUP&lt;br /&gt;
&lt;br /&gt;
*Systems Architecture - http://en.wikipedia.org/wiki/Systems_architecture&lt;br /&gt;
&lt;br /&gt;
*System Analysis - http://en.wikipedia.org/wiki/Systems_analysis&lt;br /&gt;
&lt;br /&gt;
*System Design - http://en.wikipedia.org/wiki/Systems_design&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w4_sa&amp;diff=69014</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w4 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w4_sa&amp;diff=69014"/>
		<updated>2012-10-27T08:05:48Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* Objectives */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''V - Model'''&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
[[File:Wiki image.jpg|thumb|420px|The V-model of the Systems Engineering Process.]]&lt;br /&gt;
The V-model also called as Verification and Validation model is a [http://en.wikipedia.org/wiki/Software_development_process software development process] which simplifies the understanding of the complexity associated with the development of a system,  and is an extension to the [http://en.wikipedia.org/wiki/Waterfall_model waterfall model]. Rather than proceeding linearly downwards, after the coding phase, the process steps are bent upwards to form a V shape. This creates an association between the phases in the development and the [http://en.wikipedia.org/wiki/Software_testing_life_cycle testing cycle].&lt;br /&gt;
&lt;br /&gt;
In the diagram, the left arm corresponds to the development phases in the traditional waterfall model and the right to the test phases. Each development activity carried out by the development team has its corresponding validation activity done by the testing team.&lt;br /&gt;
&lt;br /&gt;
=='''From Waterfall to V-Model'''==&lt;br /&gt;
&lt;br /&gt;
Every phase or stage in the waterfall model needs to be completed and signed off before the next phase can start, this rigidity affects the flexibility in iterating back and forth between the [http://www.investopedia.com/terms/d/developmentstage.asp#axzz2AS3WFJBq stages of development] with the result being a poor quality system. The V-Model prevents this by explicitly connecting the development and testing stages.&lt;br /&gt;
&lt;br /&gt;
=='''Objectives'''==&lt;br /&gt;
&lt;br /&gt;
The V-Model facilitates the [http://en.wikipedia.org/wiki/Planning planning] and [http://en.wikipedia.org/wiki/Implementation realization] of projects. The following are the objectives to be achieved during system development:&lt;br /&gt;
&lt;br /&gt;
*Minimizing Project Risks: Early recognition of planning deviations and risks improves process management, thus reducing risks.&lt;br /&gt;
&lt;br /&gt;
*Improving Quality: Defined interim results can be checked at an early stage. Uniform product contents will improve readability, understandability and verifiability.&lt;br /&gt;
&lt;br /&gt;
*Reduction of Total Cost: The results obtained should be uniform and easily retraced. This reduces the dependency on the supplier and the effort for subsequent activities.&lt;br /&gt;
&lt;br /&gt;
*Effective Communication between all [http://en.wikipedia.org/wiki/Stakeholder Stakeholders]: The miscommunication between user, supplier and developer is reduced.&lt;br /&gt;
&lt;br /&gt;
=='''Verification phase'''==&lt;br /&gt;
[[File:V model001.jpg|thumb|420px|V-Model in detail.]]&lt;br /&gt;
&lt;br /&gt;
Verification ensures that, the software is being built correctly. The [http://en.wikipedia.org/wiki/International_Software_Testing_Qualifications_Board ISTQB] defines Verification as: “Confirmation by examination and through provision of objective evidence that specified requirements have been fulfilled.&lt;br /&gt;
&lt;br /&gt;
The first part of the definition is the same as for Validation, but the second part is the key. This states that “specified requirements have been fulfilled“. The V-model diagram arrows shows that each produced product is checked against the products or documents that were used to drive the development. This ensures that all aspects have been met. A key problem is ensuring that the user requirements are adequately verified against the customer needs. The Business Case is only likely to contain high level functionality, and not the detail about processes that are essential for determining what is required.&lt;br /&gt;
&lt;br /&gt;
===Requirements Analysis===&lt;br /&gt;
&lt;br /&gt;
Requirements analysis encompasses those tasks that determine the conditions specified by the stakeholders for the product. Its activities are concerned with eliciting, analyzing, documenting, validating and managing system requirements. The requirements have to be documentable, actionable, measurable, testable, traceable, related to the business needs and should include details sufficient for system design.&lt;br /&gt;
&lt;br /&gt;
Requirements analysis includes three types of activities:&lt;br /&gt;
&lt;br /&gt;
*Eliciting requirements: Identifying the various types of requirements from various sources i.e. project and business process documentation along with stakeholder interviews.&lt;br /&gt;
&lt;br /&gt;
*Analyzing requirements: Determining whether the specified requirements are clear, complete and consistent.&lt;br /&gt;
&lt;br /&gt;
*Recording requirements: Requirements can be documented in normal language documents, use cases, user stories, or system specifications.&lt;br /&gt;
&lt;br /&gt;
Requirements analysis is a long process during which many changes can occur over that time period. Technology changes, business requirements changes with many other things, so it is important that the stakeholders are in constant touch with the developers to ensure that they understand the new improved system. It is the responsibility of the analyst to gather information from the customer. System prototypes should be developed to demonstrate a working model to the stakeholders. Analysts employ a combination of various methods to establish the exact requirements of the stakeholders, so that the system developed meets the customer’s needs. The information regarding the product requirements can be classified as: Customer, Architectural, Structural, Behavioral, Functional, Non-functional, Performance, Design, Derived, and Allocated Requirements.&lt;br /&gt;
&lt;br /&gt;
===System Design===&lt;br /&gt;
&lt;br /&gt;
This design process defines the architecture, components, modules, interfaces, and data required by a system to meet the mentioned system requirements. We can say that design is an act of taking the marketing information and creating the products to be manufactured. So, systems design is the process of defining and developing systems specified by the user.&lt;br /&gt;
&lt;br /&gt;
*Softwares that run on generic platforms have enhanced software engineering. &lt;br /&gt;
&lt;br /&gt;
*Object-oriented analysis and design methods are widely used for systems design.&lt;br /&gt;
&lt;br /&gt;
*UML is used for modeling software systems and designing high non-software systems and organizations.&lt;br /&gt;
&lt;br /&gt;
===Architecture Design===&lt;br /&gt;
&lt;br /&gt;
The design of computer and software architecture can be referred to as high-level design. The architecture selected should realize the list of modules, brief functionality of each module, the interface relationships between the modules, dependencies, database tables, architecture diagrams, technology details etc.&lt;br /&gt;
&lt;br /&gt;
Integration testing design is carried out in this phase.&lt;br /&gt;
&lt;br /&gt;
===Module Design===&lt;br /&gt;
&lt;br /&gt;
The module design phase is a low-level design. The designed system is broken up into smaller units and each of them is explained to the programmer. The low level design document will contain a detailed functional logic of the module:&lt;br /&gt;
&lt;br /&gt;
*database tables, with all elements, including their type and size&lt;br /&gt;
&lt;br /&gt;
*all interface details with complete API references&lt;br /&gt;
&lt;br /&gt;
*all dependency issues&lt;br /&gt;
&lt;br /&gt;
*error message listings&lt;br /&gt;
&lt;br /&gt;
*complete input and outputs for a module.&lt;br /&gt;
&lt;br /&gt;
Unit test design is developed in this stage.&lt;br /&gt;
&lt;br /&gt;
=='''Validation phase'''==&lt;br /&gt;
===Importance of Early Testing===&lt;br /&gt;
&lt;br /&gt;
Studies show that catching a fault early in the development stages before the system is released is more cost effective and it takes less resources to fix the system when compared to fixing it after its release. We must also take into account the reputation of the organisation, the cost associated with missing functionality, so in fact the true cost for fixing the system is much higher.&lt;br /&gt;
&lt;br /&gt;
In the waterfall model errors were found very late in the cycle because testing began at the end of the project. In the V-Model testing begins as early as possible. Prior to testing, the testing team works on various activities in parallel to the development activity which helps to get the test deliverable on time which includes creation of test cases, preparation of test strategies, test planning and test scripting.&lt;br /&gt;
&lt;br /&gt;
===Testing Types Matched to Development Stages===&lt;br /&gt;
&lt;br /&gt;
The first noticeable point of the V-Model is that the Test stage of the Waterfall model is bent upwards to make it a “V”. This stage is now separated out into the various types of testing. So this first step visually points out that there is more than one type of testing to consider for system development and like the development steps they build on one another, and have different objectives. The next important part of the “V” is to match each type of testing against the development stage it matches e.g. we have Component Design matched against Component Testing. This means that the testing stage does not start when the Construct Component stage has ended. Instead when each development stage starts, the testing for that stage also starts.&lt;br /&gt;
&lt;br /&gt;
===Unit testing===&lt;br /&gt;
&lt;br /&gt;
Unit testing, tests the low level design i.e. units. A unit is a basic module of the application on which testing is carried out, it may be an individual function or a procedure. These tests are created by the developers (white box testing) to verify the internal logic code. Input data are passed to the unit to test every case of execution.&lt;br /&gt;
&lt;br /&gt;
===Integration testing===&lt;br /&gt;
&lt;br /&gt;
Integration testing tests high level design i.e. components and their interfaces. In Integration testing the basic units will be tested together to check the interaction between them and finds errors in the interfaces. This is generally a black box testing method. Integration testing is  performed by program team leaders.&lt;br /&gt;
&lt;br /&gt;
===System testing===&lt;br /&gt;
&lt;br /&gt;
Once the entire system has been developed, it then has to be tested against the system specifications to validate if it provides the required features. In short, system testing is about checking the system as a whole. System testing involves a number of special types of tests to see if all the functional and nonfunctional requirements have been met. System testing is performed by system testers.&lt;br /&gt;
Reasons for carrying out a system test even after the unit and integration test&lt;br /&gt;
&lt;br /&gt;
*The previous testings were done against the system specifications. The system test, looks at the system from the perspective of the future user.&lt;br /&gt;
&lt;br /&gt;
*Many of the system functions and characteristics results from the interaction of  the modules, and can be tested only at this level. &lt;br /&gt;
&lt;br /&gt;
*Also, keeping in mind that the customer and the end user can be two different groups of people having their own requirements and interests. &lt;br /&gt;
&lt;br /&gt;
===Acceptance testing===&lt;br /&gt;
&lt;br /&gt;
The major purpose of Acceptance Testing is to validate or confirm that the system meets the  business requirements and gives an assurance before it is delivered to the end user. This phase is for testing the software in the real world by the end user to determine whether to accept the system or not.&lt;br /&gt;
&lt;br /&gt;
===Release testing===&lt;br /&gt;
&lt;br /&gt;
This testing phase answers important questions such as&lt;br /&gt;
&lt;br /&gt;
*Is the software suitable for the end user?&lt;br /&gt;
&lt;br /&gt;
*Has the compatibility with other systems been ensured?&lt;br /&gt;
&lt;br /&gt;
*Is the performance of the software optimized?&lt;br /&gt;
&lt;br /&gt;
=='''Advantages'''==&lt;br /&gt;
&lt;br /&gt;
*Early acceptance criteria is the key advantage, they are performed against a specification of requirements.&lt;br /&gt;
&lt;br /&gt;
*60 to 70 percent of all faults are in the system before the component construction and test stages start, which is taken care of. &lt;br /&gt;
&lt;br /&gt;
*At an early stage we can feed back to catch a fault before it is built into the system.&lt;br /&gt;
&lt;br /&gt;
*Specifies test requirements and expected results prior to performing the actual tests.&lt;br /&gt;
&lt;br /&gt;
*Defines who is responsible for performing the testing and provides a focus for defining the testing that takes place at each stage. &lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages'''==&lt;br /&gt;
&lt;br /&gt;
*Too simple to reflect the development process.&lt;br /&gt;
&lt;br /&gt;
*Leads project managers to a false sense of security.&lt;br /&gt;
&lt;br /&gt;
*Inflexible and no ability to respond to change.&lt;br /&gt;
&lt;br /&gt;
*Produces inefficient testing methodologies&lt;br /&gt;
&lt;br /&gt;
*The placing of contracts for services is not regulated.&lt;br /&gt;
&lt;br /&gt;
*The organization and execution of operation, maintenance, repair and disposal of the system are not covered by the V-Model. &lt;br /&gt;
&lt;br /&gt;
*The V-Model addresses software development within a project rather than a whole organization.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
&lt;br /&gt;
Testing in the development process is critical. The earlier a fault is found, the cheaper it is to fix. The V model extends testing to the beginning of the life-cycle. The explicit recognition of testing in the V-model makes it very useful in planning and executing information system development. The V-Model has evolved over time and supports flexibility and agility throughout the development process. Static testing techniques, such as inspections and walkthroughs, can be used to find faults in the functional specification, as well as defining test cases that are subsequently executed in system testing.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&lt;br /&gt;
*http://www.softwaretestingclass.com/v-model/&lt;br /&gt;
&lt;br /&gt;
*http://en.wikipedia.org/wiki/V-Model_(software_development)&lt;br /&gt;
&lt;br /&gt;
*http://en.wikipedia.org/wiki/V-Model&lt;br /&gt;
&lt;br /&gt;
*http://www.careerride.com/testing-v-model.aspx&lt;br /&gt;
&lt;br /&gt;
*http://www.softwaretestingmentor.com/sdlc/vmodel.php&lt;br /&gt;
&lt;br /&gt;
*http://www.bucanac.com/documents/The_V-Model.pdf&lt;br /&gt;
&lt;br /&gt;
*http://www.compensationanalytics.com/_resources/vtestingmodel.pdf&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
&lt;br /&gt;
*Dual Vee Model - http://en.wikipedia.org/wiki/Dual_Vee_Model&lt;br /&gt;
&lt;br /&gt;
*System Development Lifecycle - http://en.wikipedia.org/wiki/Systems_Development_Life_Cycle&lt;br /&gt;
&lt;br /&gt;
*Product Lifecycle Management - http://en.wikipedia.org/wiki/Product_lifecycle_management&lt;br /&gt;
&lt;br /&gt;
*Portal: Software Testing - http://en.wikipedia.org/wiki/Portal:Software_Testing&lt;br /&gt;
&lt;br /&gt;
*IBM RUP - http://en.wikipedia.org/wiki/RUP&lt;br /&gt;
&lt;br /&gt;
*Systems Architecture - http://en.wikipedia.org/wiki/Systems_architecture&lt;br /&gt;
&lt;br /&gt;
*System Analysis - http://en.wikipedia.org/wiki/Systems_analysis&lt;br /&gt;
&lt;br /&gt;
*System Design - http://en.wikipedia.org/wiki/Systems_design&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w4_sa&amp;diff=68176</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w4 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w4_sa&amp;diff=68176"/>
		<updated>2012-10-25T11:57:38Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''V - Model'''&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
&lt;br /&gt;
The V-model also called as Verification and Validation model is a software development process which simplifies the understanding of the complexity associated with the development of a system,  and is an extension to the waterfall model. Rather than proceeding linearly downwards, after the coding phase, the process steps are bent upwards to form a V shape. This creates an association between the phases in the development and the testing cycle.&lt;br /&gt;
&lt;br /&gt;
In the diagram, the left arm corresponds to the development phases in the traditional waterfall model and the right to the test phases. Each development activity carried out by the development team has its corresponding validation activity done by the testing team.&lt;br /&gt;
&lt;br /&gt;
=='''From Waterfall to V-Model'''==&lt;br /&gt;
&lt;br /&gt;
Every phase or stage in the waterfall model needs to be completed and signed off before the next phase can start, this rigidity affects the flexibility in iterating back and forth between the stages of development with the result being a poor quality system. The V-Model prevents this by explicitly connecting the development and testing stages.&lt;br /&gt;
&lt;br /&gt;
=='''Objectives'''==&lt;br /&gt;
&lt;br /&gt;
The V-Model facilitates the planning and realization of projects. The following are the objectives to be achieved during system development:&lt;br /&gt;
&lt;br /&gt;
*Minimizing Project Risks: Early recognition of planning deviations and risks improves process management, thus reducing risks.&lt;br /&gt;
&lt;br /&gt;
*Improving Quality: Defined interim results can be checked at an early stage. Uniform product contents will improve readability, understandability and verifiability.&lt;br /&gt;
&lt;br /&gt;
*Reduction of Total Cost: The results obtained should be uniform and easily retraced. This reduces the dependency on the supplier and the effort for subsequent activities.&lt;br /&gt;
&lt;br /&gt;
*Effective Communication between all Stakeholders: The miscommunication between user, supplier and developer is reduced.&lt;br /&gt;
&lt;br /&gt;
=='''Verification phase'''==&lt;br /&gt;
&lt;br /&gt;
Verification ensures that, the software is being built correctly. The ISTQB defines Verification as: “Confirmation by examination and through provision of objective evidence that specified requirements have been fulfilled.“&lt;br /&gt;
&lt;br /&gt;
The first part of the definition is the same as for Validation, but the second part is the key. This states that “specified requirements have been fulfilled“. The V-model diagram arrows shows that each produced product is checked against the products or documents that were used to drive the development. This ensures that all aspects have been met. A key problem is ensuring that the user requirements are adequately verified against the customer needs. The Business Case is only likely to contain high level functionality, and not the detail about processes that are essential for determining what is required.&lt;br /&gt;
&lt;br /&gt;
===Requirements Analysis===&lt;br /&gt;
&lt;br /&gt;
Requirements analysis encompasses those tasks that determine the conditions specified by the stakeholders for the product. Its activities are concerned with eliciting, analyzing, documenting, validating and managing system requirements. The requirements have to be documentable, actionable, measurable, testable, traceable, related to the business needs and should include details sufficient for system design.&lt;br /&gt;
&lt;br /&gt;
Requirements analysis includes three types of activities:&lt;br /&gt;
&lt;br /&gt;
*Eliciting requirements: Identifying the various types of requirements from various sources i.e. project and business process documentation along with stakeholder interviews.&lt;br /&gt;
&lt;br /&gt;
*Analyzing requirements: Determining whether the specified requirements are clear, complete and consistent.&lt;br /&gt;
&lt;br /&gt;
*Recording requirements: Requirements can be documented in normal language documents, use cases, user stories, or system specifications.&lt;br /&gt;
&lt;br /&gt;
Requirements analysis is a long process during which many changes can occur over that time period. Technology changes, business requirements changes with many other things, so it is important that the stakeholders are in constant touch with the developers to ensure that they understand the new improved system. It is the responsibility of the analyst to gather information from the customer. System prototypes should be developed to demonstrate a working model to the stakeholders. Analysts employ a combination of various methods to establish the exact requirements of the stakeholders, so that the system developed meets the customer’s needs. The information regarding the product requirements can be classified as: Customer, Architectural, Structural, Behavioral, Functional, Non-functional, Performance, Design, Derived, and Allocated Requirements.&lt;br /&gt;
&lt;br /&gt;
===System Design===&lt;br /&gt;
&lt;br /&gt;
This design process defines the architecture, components, modules, interfaces, and data required by a system to meet the mentioned system requirements. We can say that design is an act of taking the marketing information and creating the products to be manufactured. So, systems design is the process of defining and developing systems specified by the user.&lt;br /&gt;
&lt;br /&gt;
*Softwares that run on generic platforms have enhanced software engineering. &lt;br /&gt;
&lt;br /&gt;
*Object-oriented analysis and design methods are widely used for systems design.&lt;br /&gt;
&lt;br /&gt;
*UML is used for modeling software systems and designing high non-software systems and organizations.&lt;br /&gt;
&lt;br /&gt;
===Architecture Design===&lt;br /&gt;
&lt;br /&gt;
The design of computer and software architecture can be referred to as high-level design. The architecture selected should realize the list of modules, brief functionality of each module, the interface relationships between the modules, dependencies, database tables, architecture diagrams, technology details etc.&lt;br /&gt;
&lt;br /&gt;
Integration testing design is carried out in this phase.&lt;br /&gt;
&lt;br /&gt;
===Module Design===&lt;br /&gt;
&lt;br /&gt;
The module design phase is a low-level design. The designed system is broken up into smaller units and each of them is explained to the programmer. The low level design document will contain a detailed functional logic of the module:&lt;br /&gt;
&lt;br /&gt;
*database tables, with all elements, including their type and size&lt;br /&gt;
&lt;br /&gt;
*all interface details with complete API references&lt;br /&gt;
&lt;br /&gt;
*all dependency issues&lt;br /&gt;
&lt;br /&gt;
*error message listings&lt;br /&gt;
&lt;br /&gt;
*complete input and outputs for a module.&lt;br /&gt;
&lt;br /&gt;
Unit test design is developed in this stage.&lt;br /&gt;
&lt;br /&gt;
=='''Coding'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Validation phase'''==&lt;br /&gt;
===Importance of Early Testing===&lt;br /&gt;
&lt;br /&gt;
Studies show that catching a fault early in the development stages before the system is released is more cost effective and it takes less resources to fix the system when compared to fixing it after its release. We must also take into account the reputation of the organisation, the cost associated with missing functionality, so in fact the true cost for fixing the system is much higher.&lt;br /&gt;
&lt;br /&gt;
In the waterfall model errors were found very late in the cycle because testing began at the end of the project. In the V-Model testing begins as early as possible. Prior to testing, the testing team works on various activities in parallel to the development activity which helps to get the test deliverable on time which includes creation of test cases, preparation of test strategies, test planning and test scripting.&lt;br /&gt;
&lt;br /&gt;
===Testing Types Matched to Development Stages===&lt;br /&gt;
&lt;br /&gt;
The first noticeable point of the V-Model is that the Test stage of the Waterfall model is bent upwards to make it a “V”. This stage is now separated out into the various types of testing. So this first step visually points out that there is more than one type of testing to consider for system development and like the development steps they build on one another, and have different objectives. The next important part of the “V” is to match each type of testing against the development stage it matches e.g. we have Component Design matched against Component Testing. This means that the testing stage does not start when the Construct Component stage has ended. Instead when each development stage starts, the testing for that stage also starts.&lt;br /&gt;
&lt;br /&gt;
===Unit testing===&lt;br /&gt;
&lt;br /&gt;
Unit testing, tests the low level design i.e. units. A unit is a basic module of the application on which testing is carried out, it may be an individual function or a procedure. These tests are created by the developers (white box testing) to verify the internal logic code. Input data are passed to the unit to test every case of execution.&lt;br /&gt;
&lt;br /&gt;
===Integration testing===&lt;br /&gt;
&lt;br /&gt;
Integration testing tests high level design i.e. components and their interfaces. In Integration testing the basic units will be tested together to check the interaction between them and finds errors in the interfaces. This is generally a black box testing method. Integration testing is  performed by program team leaders.&lt;br /&gt;
&lt;br /&gt;
===System testing===&lt;br /&gt;
&lt;br /&gt;
Once the entire system has been developed, it then has to be tested against the system specifications to validate if it provides the required features. In short, system testing is about checking the system as a whole. System testing involves a number of special types of tests to see if all the functional and nonfunctional requirements have been met. System testing is performed by system testers.&lt;br /&gt;
Reasons for carrying out a system test even after the unit and integration test&lt;br /&gt;
&lt;br /&gt;
*The previous testings were done against the system specifications. The system test, looks at the system from the perspective of the future user.&lt;br /&gt;
&lt;br /&gt;
*Many of the system functions and characteristics results from the interaction of  the modules, and can be tested only at this level. &lt;br /&gt;
&lt;br /&gt;
*Also, keeping in mind that the customer and the end user can be two different groups of people having their own requirements and interests. &lt;br /&gt;
&lt;br /&gt;
===Acceptance testing===&lt;br /&gt;
&lt;br /&gt;
The major purpose of Acceptance Testing is to validate or confirm that the system meets the  business requirements and gives an assurance before it is delivered to the end user. This phase is for testing the software in the real world by the end user to determine whether to accept the system or not.&lt;br /&gt;
&lt;br /&gt;
===Release testing===&lt;br /&gt;
&lt;br /&gt;
This testing phase answers important questions such as&lt;br /&gt;
&lt;br /&gt;
*Is the software suitable for the end user?&lt;br /&gt;
&lt;br /&gt;
*Has the compatibility with other systems been ensured?&lt;br /&gt;
&lt;br /&gt;
*Is the performance of the software optimized?&lt;br /&gt;
&lt;br /&gt;
=='''Advantages'''==&lt;br /&gt;
&lt;br /&gt;
*Early acceptance criteria is the key advantage, they are performed against a specification of requirements.&lt;br /&gt;
&lt;br /&gt;
*60 to 70 percent of all faults are in the system before the component construction and test stages start, which is taken care of. &lt;br /&gt;
&lt;br /&gt;
*At an early stage we can feed back to catch a fault before it is built into the system.&lt;br /&gt;
&lt;br /&gt;
*Specifies test requirements and expected results prior to performing the actual tests.&lt;br /&gt;
&lt;br /&gt;
*Defines who is responsible for performing the testing and provides a focus for defining the testing that takes place at each stage. &lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages'''==&lt;br /&gt;
&lt;br /&gt;
*Too simple to reflect the development process.&lt;br /&gt;
&lt;br /&gt;
*Leads project managers to a false sense of security.&lt;br /&gt;
&lt;br /&gt;
*Inflexible and no ability to respond to change.&lt;br /&gt;
&lt;br /&gt;
*Produces inefficient testing methodologies&lt;br /&gt;
&lt;br /&gt;
*The placing of contracts for services is not regulated.&lt;br /&gt;
&lt;br /&gt;
*The organization and execution of operation, maintenance, repair and disposal of the system are not covered by the V-Model. &lt;br /&gt;
&lt;br /&gt;
*The V-Model addresses software development within a project rather than a whole organization.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
&lt;br /&gt;
Testing in the development process is critical. The earlier a fault is found, the cheaper it is to fix. The V model extends testing to the beginning of the lifecycle. The explicit recognition of testing in the V model makes it very useful in planning and executing information system development. The V-Model has evolved over time and supports flexibility and agility throughout the development process. Static testing techniques, such as inspections and walkthroughs, can be used to find faults in the functional specification, as well as defining test cases that are subsequently executed in system testing.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*http://www.softwaretestingclass.com/v-model/&lt;br /&gt;
&lt;br /&gt;
*http://en.wikipedia.org/wiki/V-Model_(software_development)&lt;br /&gt;
&lt;br /&gt;
*http://en.wikipedia.org/wiki/V-Model&lt;br /&gt;
&lt;br /&gt;
*http://www.careerride.com/testing-v-model.aspx&lt;br /&gt;
&lt;br /&gt;
*http://www.softwaretestingmentor.com/sdlc/vmodel.php&lt;br /&gt;
&lt;br /&gt;
*http://www.bucanac.com/documents/The_V-Model.pdf&lt;br /&gt;
&lt;br /&gt;
*http://www.compensationanalytics.com/_resources/vtestingmodel.pdf&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
&lt;br /&gt;
*Dual Vee Model - http://en.wikipedia.org/wiki/Dual_Vee_Model&lt;br /&gt;
&lt;br /&gt;
*System Development Lifecycle - http://en.wikipedia.org/wiki/Systems_Development_Life_Cycle&lt;br /&gt;
&lt;br /&gt;
*Product Lifecycle Management - http://en.wikipedia.org/wiki/Product_lifecycle_management&lt;br /&gt;
&lt;br /&gt;
*Portal: Software Testing - http://en.wikipedia.org/wiki/Portal:Software_Testing&lt;br /&gt;
&lt;br /&gt;
*IBM RUP - http://en.wikipedia.org/wiki/RUP&lt;br /&gt;
&lt;br /&gt;
*Systems Architecture - http://en.wikipedia.org/wiki/Systems_architecture&lt;br /&gt;
&lt;br /&gt;
*System Analysis - http://en.wikipedia.org/wiki/Systems_analysis&lt;br /&gt;
&lt;br /&gt;
*System Design - http://en.wikipedia.org/wiki/Systems_design&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w4_sa&amp;diff=68175</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w4 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w4_sa&amp;diff=68175"/>
		<updated>2012-10-25T11:16:16Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''V - Model'''&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
&lt;br /&gt;
The V-model also called as Verification and Validation model is a software development process which simplifies the understanding of the complexity associated with the development of a system,  and is an extension to the waterfall model. Rather than proceeding linearly downwards, after the coding phase, the process steps are bent upwards to form a V shape. This creates an association between the phases in the development and the testing cycle.&lt;br /&gt;
&lt;br /&gt;
In the diagram, the left arm corresponds to the development phases in the traditional waterfall model and the right to the test phases. Each development activity carried out by the development team has its corresponding validation activity done by the testing team.&lt;br /&gt;
&lt;br /&gt;
=='''From Waterfall to V-Model'''==&lt;br /&gt;
&lt;br /&gt;
Every phase or stage in the waterfall model needs to be completed and signed off before the next phase can start, this rigidity affects the flexibility in iterating back and forth between the stages of development with the result being a poor quality system. The V-Model prevents this by explicitly connecting the development and testing stages.&lt;br /&gt;
&lt;br /&gt;
=='''Objectives'''==&lt;br /&gt;
&lt;br /&gt;
The V-Model facilitates the planning and realization of projects. The following are the objectives to be achieved during system development:&lt;br /&gt;
&lt;br /&gt;
*Minimizing Project Risks: Early recognition of planning deviations and risks improves process management, thus reducing risks.&lt;br /&gt;
&lt;br /&gt;
*Improving Quality: Defined interim results can be checked at an early stage. Uniform product contents will improve readability, understandability and verifiability.&lt;br /&gt;
&lt;br /&gt;
*Reduction of Total Cost: The results obtained should be uniform and easily retraced. This reduces the dependency on the supplier and the effort for subsequent activities.&lt;br /&gt;
&lt;br /&gt;
*Effective Communication between all Stakeholders: The miscommunication between user, supplier and developer is reduced.&lt;br /&gt;
&lt;br /&gt;
=='''Verification phase'''==&lt;br /&gt;
&lt;br /&gt;
Verification ensures that, the software is being built correctly. The ISTQB defines Verification as: “Confirmation by examination and through provision of objective evidence that specified requirements have been fulfilled.“&lt;br /&gt;
&lt;br /&gt;
The first part of the definition is the same as for Validation, but the second part is the key. This states that “specified requirements have been fulfilled“. The V-model diagram arrows shows that each produced product is checked against the products or documents that were used to drive the development. This ensures that all aspects have been met. A key problem is ensuring that the user requirements are adequately verified against the customer needs. The Business Case is only likely to contain high level functionality, and not the detail about processes that are essential for determining what is required.&lt;br /&gt;
&lt;br /&gt;
===Requirements Analysis===&lt;br /&gt;
&lt;br /&gt;
Requirements analysis encompasses those tasks that determine the conditions specified by the stakeholders for the product. Its activities are concerned with eliciting, analyzing, documenting, validating and managing system requirements. The requirements have to be documentable, actionable, measurable, testable, traceable, related to the business needs and should include details sufficient for system design.&lt;br /&gt;
&lt;br /&gt;
Requirements analysis includes three types of activities:&lt;br /&gt;
&lt;br /&gt;
*Eliciting requirements: Identifying the various types of requirements from various sources i.e. project and business process documentation along with stakeholder interviews.&lt;br /&gt;
&lt;br /&gt;
*Analyzing requirements: Determining whether the specified requirements are clear, complete and consistent.&lt;br /&gt;
&lt;br /&gt;
*Recording requirements: Requirements can be documented in normal language documents, use cases, user stories, or system specifications.&lt;br /&gt;
&lt;br /&gt;
Requirements analysis is a long process during which many changes can occur over that time period. Technology changes, business requirements changes with many other things, so it is important that the stakeholders are in constant touch with the developers to ensure that they understand the new improved system. It is the responsibility of the analyst to gather information from the customer. System prototypes should be developed to demonstrate a working model to the stakeholders. Analysts employ a combination of various methods to establish the exact requirements of the stakeholders, so that the system developed meets the customer’s needs. The information regarding the product requirements can be classified as: Customer, Architectural, Structural, Behavioral, Functional, Non-functional, Performance, Design, Derived, and Allocated Requirements.&lt;br /&gt;
&lt;br /&gt;
===System Design===&lt;br /&gt;
&lt;br /&gt;
This design process defines the architecture, components, modules, interfaces, and data required by a system to meet the mentioned system requirements. We can say that design is an act of taking the marketing information and creating the products to be manufactured. So, systems design is the process of defining and developing systems specified by the user.&lt;br /&gt;
&lt;br /&gt;
*Softwares that run on generic platforms have enhanced software engineering. &lt;br /&gt;
&lt;br /&gt;
*Object-oriented analysis and design methods are widely used for systems design.&lt;br /&gt;
&lt;br /&gt;
*UML is used for modeling software systems and designing high non-software systems and organizations.&lt;br /&gt;
&lt;br /&gt;
===Architecture Design===&lt;br /&gt;
&lt;br /&gt;
The design of computer and software architecture can be referred to as high-level design. The architecture selected should realize the list of modules, brief functionality of each module, the interface relationships between the modules, dependencies, database tables, architecture diagrams, technology details etc.&lt;br /&gt;
&lt;br /&gt;
Integration testing design is carried out in this phase.&lt;br /&gt;
&lt;br /&gt;
===Module Design===&lt;br /&gt;
&lt;br /&gt;
The module design phase is a low-level design. The designed system is broken up into smaller units and each of them is explained to the programmer. The low level design document will contain a detailed functional logic of the module:&lt;br /&gt;
&lt;br /&gt;
*database tables, with all elements, including their type and size&lt;br /&gt;
&lt;br /&gt;
*all interface details with complete API references&lt;br /&gt;
&lt;br /&gt;
*all dependency issues&lt;br /&gt;
&lt;br /&gt;
*error message listings&lt;br /&gt;
&lt;br /&gt;
*complete input and outputs for a module.&lt;br /&gt;
&lt;br /&gt;
Unit test design is developed in this stage.&lt;br /&gt;
&lt;br /&gt;
=='''Coding'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Validation phase'''==&lt;br /&gt;
===Importance of Early Testing===&lt;br /&gt;
&lt;br /&gt;
Studies show that catching a fault early in the development stages before the system is released is more cost effective and it takes less resources to fix the system when compared to fixing it after its release. We must also take into account the reputation of the organisation, the cost associated with missing functionality, so in fact the true cost for fixing the system is much higher.&lt;br /&gt;
&lt;br /&gt;
In the waterfall model errors were found very late in the cycle because testing began at the end of the project. In the V-Model testing begins as early as possible. Prior to testing, the testing team works on various activities in parallel to the development activity which helps to get the test deliverable on time which includes creation of test cases, preparation of test strategies, test planning and test scripting.&lt;br /&gt;
&lt;br /&gt;
===Testing Types Matched to Development Stages===&lt;br /&gt;
&lt;br /&gt;
The first noticeable point of the V-Model is that the Test stage of the Waterfall model is bent upwards to make it a “V”. This stage is now separated out into the various types of testing. So this first step visually points out that there is more than one type of testing to consider for system development and like the development steps they build on one another, and have different objectives. The next important part of the “V” is to match each type of testing against the development stage it matches e.g. we have Component Design matched against Component Testing. This means that the testing stage does not start when the Construct Component stage has ended. Instead when each development stage starts, the testing for that stage also starts.&lt;br /&gt;
&lt;br /&gt;
===Unit testing===&lt;br /&gt;
&lt;br /&gt;
Unit testing, tests the low level design i.e. units. A unit is a basic module of the application on which testing is carried out, it may be an individual function or a procedure. These tests are created by the developers (white box testing) to verify the internal logic code. Input data are passed to the unit to test every case of execution.&lt;br /&gt;
&lt;br /&gt;
===Integration testing===&lt;br /&gt;
&lt;br /&gt;
Integration testing tests high level design i.e. components and their interfaces. In Integration testing the basic units will be tested together to check the interaction between them and finds errors in the interfaces. This is generally a black box testing method. Integration testing is  performed by program team leaders.&lt;br /&gt;
&lt;br /&gt;
===System testing===&lt;br /&gt;
&lt;br /&gt;
Once the entire system has been developed, it then has to be tested against the system specifications to validate if it provides the required features. In short, system testing is about checking the system as a whole. System testing involves a number of special types of tests to see if all the functional and nonfunctional requirements have been met. System testing is performed by system testers.&lt;br /&gt;
Reasons for carrying out a system test even after the unit and integration test&lt;br /&gt;
&lt;br /&gt;
*The previous testings were done against the system specifications. The system test, looks at the system from the perspective of the future user.&lt;br /&gt;
&lt;br /&gt;
*Many of the system functions and characteristics results from the interaction of  the modules, and can be tested only at this level. &lt;br /&gt;
&lt;br /&gt;
*Also, keeping in mind that the customer and the end user can be two different groups of people having their own requirements and interests. &lt;br /&gt;
&lt;br /&gt;
===Acceptance testing===&lt;br /&gt;
&lt;br /&gt;
The major purpose of Acceptance Testing is to validate or confirm that the system meets the  business requirements and gives an assurance before it is delivered to the end user. This phase is for testing the software in the real world by the end user to determine whether to accept the system or not.&lt;br /&gt;
&lt;br /&gt;
===Release testing===&lt;br /&gt;
&lt;br /&gt;
This testing phase answers important questions such as&lt;br /&gt;
&lt;br /&gt;
*Is the software suitable for the end user?&lt;br /&gt;
&lt;br /&gt;
*Has the compatibility with other systems been ensured?&lt;br /&gt;
&lt;br /&gt;
*Is the performance of the software optimized?&lt;br /&gt;
&lt;br /&gt;
=='''Advantages'''==&lt;br /&gt;
&lt;br /&gt;
*Early acceptance criteria is the key advantage, they are performed against a specification of requirements.&lt;br /&gt;
&lt;br /&gt;
*60 to 70 percent of all faults are in the system before the component construction and test stages start, which is taken care of. &lt;br /&gt;
&lt;br /&gt;
*At an early stage we can feed back to catch a fault before it is built into the system.&lt;br /&gt;
&lt;br /&gt;
*Specifies test requirements and expected results prior to performing the actual tests.&lt;br /&gt;
&lt;br /&gt;
*Defines who is responsible for performing the testing and provides a focus for defining the testing that takes place at each stage. &lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages'''==&lt;br /&gt;
&lt;br /&gt;
*Too simple to reflect the development process.&lt;br /&gt;
&lt;br /&gt;
*Leads project managers to a false sense of security.&lt;br /&gt;
&lt;br /&gt;
*Inflexible and no ability to respond to change.&lt;br /&gt;
&lt;br /&gt;
*Produces inefficient testing methodologies&lt;br /&gt;
&lt;br /&gt;
*The placing of contracts for services is not regulated.&lt;br /&gt;
&lt;br /&gt;
*The organization and execution of operation, maintenance, repair and disposal of the system are not covered by the V-Model. &lt;br /&gt;
&lt;br /&gt;
*The V-Model addresses software development within a project rather than a whole organization.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
&lt;br /&gt;
Testing in the development process is critical. The earlier a fault is found, the cheaper it is to fix. The V model extends testing to the beginning of the lifecycle. The explicit recognition of testing in the V model makes it very useful in planning and executing information system development. The V-Model has evolved over time and supports flexibility and agility throughout the development process. Static testing techniques, such as inspections and walkthroughs, can be used to find faults in the functional specification, as well as defining test cases that are subsequently executed in system testing.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
http://www.softwaretestingclass.com/v-model/&lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/V-Model_(software_development)&lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/V-Model&lt;br /&gt;
&lt;br /&gt;
http://www.careerride.com/testing-v-model.aspx&lt;br /&gt;
&lt;br /&gt;
http://www.softwaretestingmentor.com/sdlc/vmodel.php&lt;br /&gt;
&lt;br /&gt;
http://www.bucanac.com/documents/The_V-Model.pdf&lt;br /&gt;
&lt;br /&gt;
http://www.compensationanalytics.com/_resources/vtestingmodel.pdf&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
&lt;br /&gt;
*Dual Vee Model - http://en.wikipedia.org/wiki/Dual_Vee_Model&lt;br /&gt;
&lt;br /&gt;
*System Development Lifecycle - http://en.wikipedia.org/wiki/Systems_Development_Life_Cycle&lt;br /&gt;
&lt;br /&gt;
*Product Lifecycle Management - http://en.wikipedia.org/wiki/Product_lifecycle_management&lt;br /&gt;
&lt;br /&gt;
*Portal: Software Testing - http://en.wikipedia.org/wiki/Portal:Software_Testing&lt;br /&gt;
&lt;br /&gt;
*IBM RUP - http://en.wikipedia.org/wiki/RUP&lt;br /&gt;
&lt;br /&gt;
*Systems Architecture - http://en.wikipedia.org/wiki/Systems_architecture&lt;br /&gt;
&lt;br /&gt;
*System Analysis - http://en.wikipedia.org/wiki/Systems_analysis&lt;br /&gt;
&lt;br /&gt;
*System Design - http://en.wikipedia.org/wiki/Systems_design&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w4_sa&amp;diff=68174</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w4 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w4_sa&amp;diff=68174"/>
		<updated>2012-10-25T11:15:20Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''V - Model'''&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
&lt;br /&gt;
The V-model also called as Verification and Validation model is a software development process which simplifies the understanding of the complexity associated with the development of a system,  and is an extension to the waterfall model. Rather than proceeding linearly downwards, after the coding phase, the process steps are bent upwards to form a V shape. This creates an association between the phases in the development and the testing cycle.&lt;br /&gt;
&lt;br /&gt;
In the diagram, the left arm corresponds to the development phases in the traditional waterfall model and the right to the test phases. Each development activity carried out by the development team has its corresponding validation activity done by the testing team.&lt;br /&gt;
&lt;br /&gt;
=='''From Waterfall to V-Model'''==&lt;br /&gt;
&lt;br /&gt;
Every phase or stage in the waterfall model needs to be completed and signed off before the next phase can start, this rigidity affects the flexibility in iterating back and forth between the stages of development with the result being a poor quality system. The V-Model prevents this by explicitly connecting the development and testing stages.&lt;br /&gt;
&lt;br /&gt;
=='''Objectives'''==&lt;br /&gt;
&lt;br /&gt;
The V-Model facilitates the planning and realization of projects. The following are the objectives to be achieved during system development:&lt;br /&gt;
&lt;br /&gt;
*Minimizing Project Risks: Early recognition of planning deviations and risks improves process management, thus reducing risks.&lt;br /&gt;
&lt;br /&gt;
*Improving Quality: Defined interim results can be checked at an early stage. Uniform product contents will improve readability, understandability and verifiability.&lt;br /&gt;
&lt;br /&gt;
*Reduction of Total Cost: The results obtained should be uniform and easily retraced. This reduces the dependency on the supplier and the effort for subsequent activities.&lt;br /&gt;
&lt;br /&gt;
*Effective Communication between all Stakeholders: The miscommunication between user, supplier and developer is reduced.&lt;br /&gt;
&lt;br /&gt;
=='''Verification phase'''==&lt;br /&gt;
&lt;br /&gt;
Verification ensures that, the software is being built correctly. The ISTQB defines Verification as: “Confirmation by examination and through provision of objective evidence that specified requirements have been fulfilled.“&lt;br /&gt;
&lt;br /&gt;
The first part of the definition is the same as for Validation, but the second part is the key. This states that “specified requirements have been fulfilled“. The V-model diagram arrows shows that each produced product is checked against the products or documents that were used to drive the development. This ensures that all aspects have been met. A key problem is ensuring that the user requirements are adequately verified against the customer needs. The Business Case is only likely to contain high level functionality, and not the detail about processes that are essential for determining what is required.&lt;br /&gt;
&lt;br /&gt;
===Requirements Analysis===&lt;br /&gt;
&lt;br /&gt;
Requirements analysis encompasses those tasks that determine the conditions specified by the stakeholders for the product. Its activities are concerned with eliciting, analyzing, documenting, validating and managing system requirements. The requirements have to be documentable, actionable, measurable, testable, traceable, related to the business needs and should include details sufficient for system design.&lt;br /&gt;
&lt;br /&gt;
Requirements analysis includes three types of activities:&lt;br /&gt;
&lt;br /&gt;
*Eliciting requirements: Identifying the various types of requirements from various sources i.e. project and business process documentation along with stakeholder interviews.&lt;br /&gt;
&lt;br /&gt;
*Analyzing requirements: Determining whether the specified requirements are clear, complete and consistent.&lt;br /&gt;
&lt;br /&gt;
*Recording requirements: Requirements can be documented in normal language documents, use cases, user stories, or system specifications.&lt;br /&gt;
&lt;br /&gt;
Requirements analysis is a long process during which many changes can occur over that time period. Technology changes, business requirements changes with many other things, so it is important that the stakeholders are in constant touch with the developers to ensure that they understand the new improved system. It is the responsibility of the analyst to gather information from the customer. System prototypes should be developed to demonstrate a working model to the stakeholders. Analysts employ a combination of various methods to establish the exact requirements of the stakeholders, so that the system developed meets the customer’s needs. The information regarding the product requirements can be classified as: Customer, Architectural, Structural, Behavioral, Functional, Non-functional, Performance, Design, Derived, and Allocated Requirements.&lt;br /&gt;
&lt;br /&gt;
===System Design===&lt;br /&gt;
&lt;br /&gt;
This design process defines the architecture, components, modules, interfaces, and data required by a system to meet the mentioned system requirements. We can say that design is an act of taking the marketing information and creating the products to be manufactured. So, systems design is the process of defining and developing systems specified by the user.&lt;br /&gt;
&lt;br /&gt;
*Softwares that run on generic platforms have enhanced software engineering. &lt;br /&gt;
&lt;br /&gt;
*Object-oriented analysis and design methods are widely used for systems design.&lt;br /&gt;
&lt;br /&gt;
*UML is used for modeling software systems and designing high non-software systems and organizations.&lt;br /&gt;
&lt;br /&gt;
===Architecture Design===&lt;br /&gt;
&lt;br /&gt;
The design of computer and software architecture can be referred to as high-level design. The architecture selected should realize the list of modules, brief functionality of each module, the interface relationships between the modules, dependencies, database tables, architecture diagrams, technology details etc.&lt;br /&gt;
&lt;br /&gt;
Integration testing design is carried out in this phase.&lt;br /&gt;
&lt;br /&gt;
===Module Design===&lt;br /&gt;
&lt;br /&gt;
The module design phase is a low-level design. The designed system is broken up into smaller units and each of them is explained to the programmer. The low level design document will contain a detailed functional logic of the module:&lt;br /&gt;
&lt;br /&gt;
*database tables, with all elements, including their type and size&lt;br /&gt;
&lt;br /&gt;
*all interface details with complete API references&lt;br /&gt;
&lt;br /&gt;
*all dependency issues&lt;br /&gt;
&lt;br /&gt;
*error message listings&lt;br /&gt;
&lt;br /&gt;
*complete input and outputs for a module.&lt;br /&gt;
&lt;br /&gt;
Unit test design is developed in this stage.&lt;br /&gt;
&lt;br /&gt;
=='''Coding'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Validation phase'''==&lt;br /&gt;
===Importance of Early Testing===&lt;br /&gt;
&lt;br /&gt;
Studies show that catching a fault early in the development stages before the system is released is more cost effective and it takes less resources to fix the system when compared to fixing it after its release. We must also take into account the reputation of the organisation, the cost associated with missing functionality, so in fact the true cost for fixing the system is much higher.&lt;br /&gt;
&lt;br /&gt;
In the waterfall model errors were found very late in the cycle because testing began at the end of the project. In the V-Model testing begins as early as possible. Prior to testing, the testing team works on various activities in parallel to the development activity which helps to get the test deliverable on time which includes creation of test cases, preparation of test strategies, test planning and test scripting.&lt;br /&gt;
&lt;br /&gt;
===Testing Types Matched to Development Stages===&lt;br /&gt;
&lt;br /&gt;
The first noticeable point of the V-Model is that the Test stage of the Waterfall model is bent upwards to make it a “V”. This stage is now separated out into the various types of testing. So this first step visually points out that there is more than one type of testing to consider for system development and like the development steps they build on one another, and have different objectives. The next important part of the “V” is to match each type of testing against the development stage it matches e.g. we have Component Design matched against Component Testing. This means that the testing stage does not start when the Construct Component stage has ended. Instead when each development stage starts, the testing for that stage also starts.&lt;br /&gt;
&lt;br /&gt;
===Unit testing===&lt;br /&gt;
&lt;br /&gt;
Unit testing, tests the low level design i.e. units. A unit is a basic module of the application on which testing is carried out, it may be an individual function or a procedure. These tests are created by the developers (white box testing) to verify the internal logic code. Input data are passed to the unit to test every case of execution.&lt;br /&gt;
&lt;br /&gt;
===Integration testing===&lt;br /&gt;
&lt;br /&gt;
Integration testing tests high level design i.e. components and their interfaces. In Integration testing the basic units will be tested together to check the interaction between them and finds errors in the interfaces. This is generally a black box testing method. Integration testing is  performed by program team leaders.&lt;br /&gt;
&lt;br /&gt;
===System testing===&lt;br /&gt;
&lt;br /&gt;
Once the entire system has been developed, it then has to be tested against the system specifications to validate if it provides the required features. In short, system testing is about checking the system as a whole. System testing involves a number of special types of tests to see if all the functional and nonfunctional requirements have been met. System testing is performed by system testers.&lt;br /&gt;
Reasons for carrying out a system test even after the unit and integration test&lt;br /&gt;
&lt;br /&gt;
*The previous testings were done against the system specifications. The system test, looks at the system from the perspective of the future user.&lt;br /&gt;
&lt;br /&gt;
*Many of the system functions and characteristics results from the interaction of  the modules, and can be tested only at this level. &lt;br /&gt;
&lt;br /&gt;
*Also, keeping in mind that the customer and the end user can be two different groups of people having their own requirements and interests. &lt;br /&gt;
&lt;br /&gt;
===Acceptance testing===&lt;br /&gt;
&lt;br /&gt;
The major purpose of Acceptance Testing is to validate or confirm that the system meets the  business requirements and gives an assurance before it is delivered to the end user. This phase is for testing the software in the real world by the end user to determine whether to accept the system or not.&lt;br /&gt;
&lt;br /&gt;
===Release testing===&lt;br /&gt;
&lt;br /&gt;
This testing phase answers important questions such as&lt;br /&gt;
&lt;br /&gt;
*Is the software suitable for the end user?&lt;br /&gt;
&lt;br /&gt;
*Has the compatibility with other systems been ensured?&lt;br /&gt;
&lt;br /&gt;
*Is the performance of the software optimized?&lt;br /&gt;
&lt;br /&gt;
=='''Advantages'''==&lt;br /&gt;
&lt;br /&gt;
*Early acceptance criteria is the key advantage, they are performed against a specification of requirements.&lt;br /&gt;
&lt;br /&gt;
*60 to 70 percent of all faults are in the system before the component construction and test stages start, which is taken care of. &lt;br /&gt;
&lt;br /&gt;
*At an early stage we can feed back to catch a fault before it is built into the system.&lt;br /&gt;
&lt;br /&gt;
*Specifies test requirements and expected results prior to performing the actual tests.&lt;br /&gt;
&lt;br /&gt;
*Defines who is responsible for performing the testing and provides a focus for defining the testing that takes place at each stage. &lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages'''==&lt;br /&gt;
&lt;br /&gt;
*Too simple to reflect the development process.&lt;br /&gt;
&lt;br /&gt;
*Leads project managers to a false sense of security.&lt;br /&gt;
&lt;br /&gt;
*Inflexible and no ability to respond to change.&lt;br /&gt;
&lt;br /&gt;
*Produces inefficient testing methodologies&lt;br /&gt;
&lt;br /&gt;
*The placing of contracts for services is not regulated.&lt;br /&gt;
&lt;br /&gt;
*The organization and execution of operation, maintenance, repair and disposal of the system are not covered by the V-Model. &lt;br /&gt;
&lt;br /&gt;
*The V-Model addresses software development within a project rather than a whole organization.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
&lt;br /&gt;
Testing in the development process is critical. The earlier a fault is found, the cheaper it is to fix. The V model extends testing to the beginning of the lifecycle. The explicit recognition of testing in the V model makes it very useful in planning and executing information system development. The V-Model has evolved over time and supports flexibility and agility throughout the development process. Static testing techniques, such as inspections and walkthroughs, can be used to find faults in the functional specification, as well as defining test cases that are subsequently executed in system testing.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
http://www.softwaretestingclass.com/v-model/&lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/V-Model_(software_development)&lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/V-Model&lt;br /&gt;
&lt;br /&gt;
http://www.careerride.com/testing-v-model.aspx&lt;br /&gt;
&lt;br /&gt;
http://www.softwaretestingmentor.com/sdlc/vmodel.php&lt;br /&gt;
&lt;br /&gt;
http://www.bucanac.com/documents/The_V-Model.pdf&lt;br /&gt;
&lt;br /&gt;
http://www.compensationanalytics.com/_resources/vtestingmodel.pdf&lt;br /&gt;
&lt;br /&gt;
http://www.google.co.in/search?q=v+model&amp;amp;hl=en&amp;amp;biw=1241&amp;amp;bih=606&amp;amp;prmd=imvnsb&amp;amp;tbm=isch&amp;amp;tbo=u&amp;amp;source=univ&amp;amp;sa=X&amp;amp;ei=XVd8UICgNYem9gSa4oCYDA&amp;amp;sqi=2&amp;amp;ved=0CC8QsAQ&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
&lt;br /&gt;
*Dual Vee Model - http://en.wikipedia.org/wiki/Dual_Vee_Model&lt;br /&gt;
&lt;br /&gt;
*System Development Lifecycle - http://en.wikipedia.org/wiki/Systems_Development_Life_Cycle&lt;br /&gt;
&lt;br /&gt;
*Product Lifecycle Management - http://en.wikipedia.org/wiki/Product_lifecycle_management&lt;br /&gt;
&lt;br /&gt;
*Portal: Software Testing - http://en.wikipedia.org/wiki/Portal:Software_Testing&lt;br /&gt;
&lt;br /&gt;
*IBM RUP - http://en.wikipedia.org/wiki/RUP&lt;br /&gt;
&lt;br /&gt;
*Systems Architecture - http://en.wikipedia.org/wiki/Systems_architecture&lt;br /&gt;
&lt;br /&gt;
*System Analysis - http://en.wikipedia.org/wiki/Systems_analysis&lt;br /&gt;
&lt;br /&gt;
*System Design - http://en.wikipedia.org/wiki/Systems_design&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w4_sa&amp;diff=68173</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w4 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w4_sa&amp;diff=68173"/>
		<updated>2012-10-25T11:14:15Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''V - Model'''&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
&lt;br /&gt;
The V-model also called as Verification and Validation model is a software development process which simplifies the understanding of the complexity associated with the development of a system,  and is an extension to the waterfall model. Rather than proceeding linearly downwards, after the coding phase, the process steps are bent upwards to form a V shape. This creates an association between the phases in the development and the testing cycle.&lt;br /&gt;
&lt;br /&gt;
In the diagram, the left arm corresponds to the development phases in the traditional waterfall model and the right to the test phases. Each development activity carried out by the development team has its corresponding validation activity done by the testing team.&lt;br /&gt;
&lt;br /&gt;
=='''From Waterfall to V-Model'''==&lt;br /&gt;
&lt;br /&gt;
Every phase or stage in the waterfall model needs to be completed and signed off before the next phase can start, this rigidity affects the flexibility in iterating back and forth between the stages of development with the result being a poor quality system. The V-Model prevents this by explicitly connecting the development and testing stages.&lt;br /&gt;
&lt;br /&gt;
=='''Objectives'''==&lt;br /&gt;
&lt;br /&gt;
The V-Model facilitates the planning and realization of projects. The following are the objectives to be achieved during system development:&lt;br /&gt;
&lt;br /&gt;
*Minimizing Project Risks: Early recognition of planning deviations and risks improves process management, thus reducing risks.&lt;br /&gt;
&lt;br /&gt;
*Improving Quality: Defined interim results can be checked at an early stage. Uniform product contents will improve readability, understandability and verifiability.&lt;br /&gt;
&lt;br /&gt;
*Reduction of Total Cost: The results obtained should be uniform and easily retraced. This reduces the dependency on the supplier and the effort for subsequent activities.&lt;br /&gt;
&lt;br /&gt;
*Effective Communication between all Stakeholders: The miscommunication between user, supplier and developer is reduced.&lt;br /&gt;
&lt;br /&gt;
==='''Verification phase'''===&lt;br /&gt;
&lt;br /&gt;
Verification ensures that, the software is being built correctly. The ISTQB defines Verification as: “Confirmation by examination and through provision of objective evidence that specified requirements have been fulfilled.“&lt;br /&gt;
&lt;br /&gt;
The first part of the definition is the same as for Validation, but the second part is the key. This states that “specified requirements have been fulfilled“. The V-model diagram arrows shows that each produced product is checked against the products or documents that were used to drive the development. This ensures that all aspects have been met. A key problem is ensuring that the user requirements are adequately verified against the customer needs. The Business Case is only likely to contain high level functionality, and not the detail about processes that are essential for determining what is required.&lt;br /&gt;
&lt;br /&gt;
===Requirements Analysis===&lt;br /&gt;
&lt;br /&gt;
Requirements analysis encompasses those tasks that determine the conditions specified by the stakeholders for the product. Its activities are concerned with eliciting, analyzing, documenting, validating and managing system requirements. The requirements have to be documentable, actionable, measurable, testable, traceable, related to the business needs and should include details sufficient for system design.&lt;br /&gt;
&lt;br /&gt;
Requirements analysis includes three types of activities:&lt;br /&gt;
&lt;br /&gt;
*Eliciting requirements: Identifying the various types of requirements from various sources i.e. project and business process documentation along with stakeholder interviews.&lt;br /&gt;
&lt;br /&gt;
*Analyzing requirements: Determining whether the specified requirements are clear, complete and consistent.&lt;br /&gt;
&lt;br /&gt;
*Recording requirements: Requirements can be documented in normal language documents, use cases, user stories, or system specifications.&lt;br /&gt;
&lt;br /&gt;
Requirements analysis is a long process during which many changes can occur over that time period. Technology changes, business requirements changes with many other things, so it is important that the stakeholders are in constant touch with the developers to ensure that they understand the new improved system. It is the responsibility of the analyst to gather information from the customer. System prototypes should be developed to demonstrate a working model to the stakeholders. Analysts employ a combination of various methods to establish the exact requirements of the stakeholders, so that the system developed meets the customer’s needs. The information regarding the product requirements can be classified as: Customer, Architectural, Structural, Behavioral, Functional, Non-functional, Performance, Design, Derived, and Allocated Requirements.&lt;br /&gt;
&lt;br /&gt;
===System Design===&lt;br /&gt;
&lt;br /&gt;
This design process defines the architecture, components, modules, interfaces, and data required by a system to meet the mentioned system requirements. We can say that design is an act of taking the marketing information and creating the products to be manufactured. So, systems design is the process of defining and developing systems specified by the user.&lt;br /&gt;
&lt;br /&gt;
*Softwares that run on generic platforms have enhanced software engineering. &lt;br /&gt;
&lt;br /&gt;
*Object-oriented analysis and design methods are widely used for systems design.&lt;br /&gt;
&lt;br /&gt;
*UML is used for modeling software systems and designing high non-software systems and organizations.&lt;br /&gt;
&lt;br /&gt;
===Architecture Design===&lt;br /&gt;
&lt;br /&gt;
The design of computer and software architecture can be referred to as high-level design. The architecture selected should realize the list of modules, brief functionality of each module, the interface relationships between the modules, dependencies, database tables, architecture diagrams, technology details etc.&lt;br /&gt;
&lt;br /&gt;
Integration testing design is carried out in this phase.&lt;br /&gt;
&lt;br /&gt;
===Module Design===&lt;br /&gt;
&lt;br /&gt;
The module design phase is a low-level design. The designed system is broken up into smaller units and each of them is explained to the programmer. The low level design document will contain a detailed functional logic of the module:&lt;br /&gt;
&lt;br /&gt;
*database tables, with all elements, including their type and size&lt;br /&gt;
&lt;br /&gt;
*all interface details with complete API references&lt;br /&gt;
&lt;br /&gt;
*all dependency issues&lt;br /&gt;
&lt;br /&gt;
*error message listings&lt;br /&gt;
&lt;br /&gt;
*complete input and outputs for a module.&lt;br /&gt;
&lt;br /&gt;
Unit test design is developed in this stage.&lt;br /&gt;
&lt;br /&gt;
=='''Coding'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Validation phase'''==&lt;br /&gt;
===Importance of Early Testing===&lt;br /&gt;
&lt;br /&gt;
Studies show that catching a fault early in the development stages before the system is released is more cost effective and it takes less resources to fix the system when compared to fixing it after its release. We must also take into account the reputation of the organisation, the cost associated with missing functionality, so in fact the true cost for fixing the system is much higher.&lt;br /&gt;
&lt;br /&gt;
In the waterfall model errors were found very late in the cycle because testing began at the end of the project. In the V-Model testing begins as early as possible. Prior to testing, the testing team works on various activities in parallel to the development activity which helps to get the test deliverable on time which includes creation of test cases, preparation of test strategies, test planning and test scripting.&lt;br /&gt;
&lt;br /&gt;
===Testing Types Matched to Development Stages===&lt;br /&gt;
&lt;br /&gt;
The first noticeable point of the V-Model is that the Test stage of the Waterfall model is bent upwards to make it a “V”. This stage is now separated out into the various types of testing. So this first step visually points out that there is more than one type of testing to consider for system development and like the development steps they build on one another, and have different objectives. The next important part of the “V” is to match each type of testing against the development stage it matches e.g. we have Component Design matched against Component Testing. This means that the testing stage does not start when the Construct Component stage has ended. Instead when each development stage starts, the testing for that stage also starts.&lt;br /&gt;
&lt;br /&gt;
===Unit testing===&lt;br /&gt;
&lt;br /&gt;
Unit testing, tests the low level design i.e. units. A unit is a basic module of the application on which testing is carried out, it may be an individual function or a procedure. These tests are created by the developers (white box testing) to verify the internal logic code. Input data are passed to the unit to test every case of execution.&lt;br /&gt;
&lt;br /&gt;
===Integration testing===&lt;br /&gt;
&lt;br /&gt;
Integration testing tests high level design i.e. components and their interfaces. In Integration testing the basic units will be tested together to check the interaction between them and finds errors in the interfaces. This is generally a black box testing method. Integration testing is  performed by program team leaders.&lt;br /&gt;
&lt;br /&gt;
===System testing===&lt;br /&gt;
&lt;br /&gt;
Once the entire system has been developed, it then has to be tested against the system specifications to validate if it provides the required features. In short, system testing is about checking the system as a whole. System testing involves a number of special types of tests to see if all the functional and nonfunctional requirements have been met. System testing is performed by system testers.&lt;br /&gt;
Reasons for carrying out a system test even after the unit and integration test&lt;br /&gt;
&lt;br /&gt;
*The previous testings were done against the system specifications. The system test, looks at the system from the perspective of the future user.&lt;br /&gt;
&lt;br /&gt;
*Many of the system functions and characteristics results from the interaction of  the modules, and can be tested only at this level. &lt;br /&gt;
&lt;br /&gt;
*Also, keeping in mind that the customer and the end user can be two different groups of people having their own requirements and interests. &lt;br /&gt;
&lt;br /&gt;
===Acceptance testing===&lt;br /&gt;
&lt;br /&gt;
The major purpose of Acceptance Testing is to validate or confirm that the system meets the  business requirements and gives an assurance before it is delivered to the end user. This phase is for testing the software in the real world by the end user to determine whether to accept the system or not.&lt;br /&gt;
&lt;br /&gt;
===Release testing===&lt;br /&gt;
&lt;br /&gt;
This testing phase answers important questions such as&lt;br /&gt;
&lt;br /&gt;
*Is the software suitable for the end user?&lt;br /&gt;
&lt;br /&gt;
*Has the compatibility with other systems been ensured?&lt;br /&gt;
&lt;br /&gt;
*Is the performance of the software optimized?&lt;br /&gt;
&lt;br /&gt;
=='''Advantages'''==&lt;br /&gt;
&lt;br /&gt;
*Early acceptance criteria is the key advantage, they are performed against a specification of requirements.&lt;br /&gt;
&lt;br /&gt;
*60 to 70 percent of all faults are in the system before the component construction and test stages start, which is taken care of. &lt;br /&gt;
&lt;br /&gt;
*At an early stage we can feed back to catch a fault before it is built into the system.&lt;br /&gt;
&lt;br /&gt;
*Specifies test requirements and expected results prior to performing the actual tests.&lt;br /&gt;
&lt;br /&gt;
*Defines who is responsible for performing the testing and provides a focus for defining the testing that takes place at each stage. &lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages'''==&lt;br /&gt;
&lt;br /&gt;
*Too simple to reflect the development process.&lt;br /&gt;
&lt;br /&gt;
*Leads project managers to a false sense of security.&lt;br /&gt;
&lt;br /&gt;
*Inflexible and no ability to respond to change.&lt;br /&gt;
&lt;br /&gt;
*Produces inefficient testing methodologies&lt;br /&gt;
&lt;br /&gt;
*The placing of contracts for services is not regulated.&lt;br /&gt;
&lt;br /&gt;
*The organization and execution of operation, maintenance, repair and disposal of the system are not covered by the V-Model. &lt;br /&gt;
&lt;br /&gt;
*The V-Model addresses software development within a project rather than a whole organization.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
&lt;br /&gt;
Testing in the development process is critical. The earlier a fault is found, the cheaper it is to fix. The V model extends testing to the beginning of the lifecycle. The explicit recognition of testing in the V model makes it very useful in planning and executing information system development. The V-Model has evolved over time and supports flexibility and agility throughout the development process. Static testing techniques, such as inspections and walkthroughs, can be used to find faults in the functional specification, as well as defining test cases that are subsequently executed in system testing.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
http://www.softwaretestingclass.com/v-model/&lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/V-Model_(software_development)&lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/V-Model&lt;br /&gt;
&lt;br /&gt;
http://www.careerride.com/testing-v-model.aspx&lt;br /&gt;
&lt;br /&gt;
http://www.softwaretestingmentor.com/sdlc/vmodel.php&lt;br /&gt;
&lt;br /&gt;
http://www.bucanac.com/documents/The_V-Model.pdf&lt;br /&gt;
&lt;br /&gt;
http://www.compensationanalytics.com/_resources/vtestingmodel.pdf&lt;br /&gt;
&lt;br /&gt;
http://www.google.co.in/search?q=v+model&amp;amp;hl=en&amp;amp;biw=1241&amp;amp;bih=606&amp;amp;prmd=imvnsb&amp;amp;tbm=isch&amp;amp;tbo=u&amp;amp;source=univ&amp;amp;sa=X&amp;amp;ei=XVd8UICgNYem9gSa4oCYDA&amp;amp;sqi=2&amp;amp;ved=0CC8QsAQ&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
&lt;br /&gt;
*Dual Vee Model - http://en.wikipedia.org/wiki/Dual_Vee_Model&lt;br /&gt;
&lt;br /&gt;
*System Development Lifecycle - http://en.wikipedia.org/wiki/Systems_Development_Life_Cycle&lt;br /&gt;
&lt;br /&gt;
*Product Lifecycle Management - http://en.wikipedia.org/wiki/Product_lifecycle_management&lt;br /&gt;
&lt;br /&gt;
*Portal: Software Testing - http://en.wikipedia.org/wiki/Portal:Software_Testing&lt;br /&gt;
&lt;br /&gt;
*IBM RUP - http://en.wikipedia.org/wiki/RUP&lt;br /&gt;
&lt;br /&gt;
*Systems Architecture - http://en.wikipedia.org/wiki/Systems_architecture&lt;br /&gt;
&lt;br /&gt;
*System Analysis - http://en.wikipedia.org/wiki/Systems_analysis&lt;br /&gt;
&lt;br /&gt;
*System Design - http://en.wikipedia.org/wiki/Systems_design&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w4_sa&amp;diff=68172</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w4 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w4_sa&amp;diff=68172"/>
		<updated>2012-10-25T11:12:39Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''V - Model'''&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
&lt;br /&gt;
The V-model also called as Verification and Validation model is a software development process which simplifies the understanding of the complexity associated with the development of a system,  and is an extension to the waterfall model. Rather than proceeding linearly downwards, after the coding phase, the process steps are bent upwards to form a V shape. This creates an association between the phases in the development and the testing cycle.&lt;br /&gt;
&lt;br /&gt;
In the diagram, the left arm corresponds to the development phases in the traditional waterfall model and the right to the test phases. Each development activity carried out by the development team has its corresponding validation activity done by the testing team.&lt;br /&gt;
&lt;br /&gt;
=='''From Waterfall to V-Model'''==&lt;br /&gt;
&lt;br /&gt;
Every phase or stage in the waterfall model needs to be completed and signed off before the next phase can start, this rigidity affects the flexibility in iterating back and forth between the stages of development with the result being a poor quality system. The V-Model prevents this by explicitly connecting the development and testing stages.&lt;br /&gt;
&lt;br /&gt;
=='''Objectives'''==&lt;br /&gt;
&lt;br /&gt;
The V-Model facilitates the planning and realization of projects. The following are the objectives to be achieved during system development:&lt;br /&gt;
&lt;br /&gt;
*Minimizing Project Risks: Early recognition of planning deviations and risks improves process management, thus reducing risks.&lt;br /&gt;
&lt;br /&gt;
*Improving Quality: Defined interim results can be checked at an early stage. Uniform product contents will improve readability, understandability and verifiability.&lt;br /&gt;
&lt;br /&gt;
*Reduction of Total Cost: The results obtained should be uniform and easily retraced. This reduces the dependency on the supplier and the effort for subsequent activities.&lt;br /&gt;
&lt;br /&gt;
*Effective Communication between all Stakeholders: The miscommunication between user, supplier and developer is reduced.&lt;br /&gt;
&lt;br /&gt;
==='Verification phase'''===&lt;br /&gt;
&lt;br /&gt;
Verification ensures that, the software is being built correctly. The ISTQB defines Verification as: “Confirmation by examination and through provision of objective evidence that specified requirements have been fulfilled.“&lt;br /&gt;
&lt;br /&gt;
The first part of the definition is the same as for Validation, but the second part is the key. This states that “specified requirements have been fulfilled“. The V-model diagram arrows shows that each produced product is checked against the products or documents that were used to drive the development. This ensures that all aspects have been met. A key problem is ensuring that the user requirements are adequately verified against the customer needs. The Business Case is only likely to contain high level functionality, and not the detail about processes that are essential for determining what is required.&lt;br /&gt;
&lt;br /&gt;
==Requirements Analysis==&lt;br /&gt;
&lt;br /&gt;
Requirements analysis encompasses those tasks that determine the conditions specified by the stakeholders for the product. Its activities are concerned with eliciting, analyzing, documenting, validating and managing system requirements. The requirements have to be documentable, actionable, measurable, testable, traceable, related to the business needs and should include details sufficient for system design.&lt;br /&gt;
&lt;br /&gt;
Requirements analysis includes three types of activities:&lt;br /&gt;
&lt;br /&gt;
*Eliciting requirements: Identifying the various types of requirements from various sources i.e. project and business process documentation along with stakeholder interviews.&lt;br /&gt;
&lt;br /&gt;
*Analyzing requirements: Determining whether the specified requirements are clear, complete and consistent.&lt;br /&gt;
&lt;br /&gt;
*Recording requirements: Requirements can be documented in normal language documents, use cases, user stories, or system specifications.&lt;br /&gt;
&lt;br /&gt;
Requirements analysis is a long process during which many changes can occur over that time period. Technology changes, business requirements changes with many other things, so it is important that the stakeholders are in constant touch with the developers to ensure that they understand the new improved system. It is the responsibility of the analyst to gather information from the customer. System prototypes should be developed to demonstrate a working model to the stakeholders. Analysts employ a combination of various methods to establish the exact requirements of the stakeholders, so that the system developed meets the customer’s needs. The information regarding the product requirements can be classified as: Customer, Architectural, Structural, Behavioral, Functional, Non-functional, Performance, Design, Derived, and Allocated Requirements.&lt;br /&gt;
&lt;br /&gt;
==System Design==&lt;br /&gt;
&lt;br /&gt;
This design process defines the architecture, components, modules, interfaces, and data required by a system to meet the mentioned system requirements. We can say that design is an act of taking the marketing information and creating the products to be manufactured. So, systems design is the process of defining and developing systems specified by the user.&lt;br /&gt;
&lt;br /&gt;
*Softwares that run on generic platforms have enhanced software engineering. &lt;br /&gt;
&lt;br /&gt;
*Object-oriented analysis and design methods are widely used for systems design.&lt;br /&gt;
&lt;br /&gt;
*UML is used for modeling software systems and designing high non-software systems and organizations.&lt;br /&gt;
&lt;br /&gt;
==Architecture Design==&lt;br /&gt;
&lt;br /&gt;
The design of computer and software architecture can be referred to as high-level design. The architecture selected should realize the list of modules, brief functionality of each module, the interface relationships between the modules, dependencies, database tables, architecture diagrams, technology details etc.&lt;br /&gt;
&lt;br /&gt;
Integration testing design is carried out in this phase.&lt;br /&gt;
&lt;br /&gt;
==Module Design==&lt;br /&gt;
&lt;br /&gt;
The module design phase is a low-level design. The designed system is broken up into smaller units and each of them is explained to the programmer. The low level design document will contain a detailed functional logic of the module:&lt;br /&gt;
&lt;br /&gt;
*database tables, with all elements, including their type and size&lt;br /&gt;
&lt;br /&gt;
*all interface details with complete API references&lt;br /&gt;
&lt;br /&gt;
*all dependency issues&lt;br /&gt;
&lt;br /&gt;
*error message listings&lt;br /&gt;
&lt;br /&gt;
*complete input and outputs for a module.&lt;br /&gt;
&lt;br /&gt;
Unit test design is developed in this stage.&lt;br /&gt;
&lt;br /&gt;
=='''Coding'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Validation phase'''==&lt;br /&gt;
===Importance of Early Testing===&lt;br /&gt;
&lt;br /&gt;
Studies show that catching a fault early in the development stages before the system is released is more cost effective and it takes less resources to fix the system when compared to fixing it after its release. We must also take into account the reputation of the organisation, the cost associated with missing functionality, so in fact the true cost for fixing the system is much higher.&lt;br /&gt;
&lt;br /&gt;
In the waterfall model errors were found very late in the cycle because testing began at the end of the project. In the V-Model testing begins as early as possible. Prior to testing, the testing team works on various activities in parallel to the development activity which helps to get the test deliverable on time which includes creation of test cases, preparation of test strategies, test planning and test scripting.&lt;br /&gt;
&lt;br /&gt;
===Testing Types Matched to Development Stages===&lt;br /&gt;
&lt;br /&gt;
The first noticeable point of the V-Model is that the Test stage of the Waterfall model is bent upwards to make it a “V”. This stage is now separated out into the various types of testing. So this first step visually points out that there is more than one type of testing to consider for system development and like the development steps they build on one another, and have different objectives. The next important part of the “V” is to match each type of testing against the development stage it matches e.g. we have Component Design matched against Component Testing. This means that the testing stage does not start when the Construct Component stage has ended. Instead when each development stage starts, the testing for that stage also starts.&lt;br /&gt;
&lt;br /&gt;
===Unit testing===&lt;br /&gt;
&lt;br /&gt;
Unit testing, tests the low level design i.e. units. A unit is a basic module of the application on which testing is carried out, it may be an individual function or a procedure. These tests are created by the developers (white box testing) to verify the internal logic code. Input data are passed to the unit to test every case of execution.&lt;br /&gt;
&lt;br /&gt;
===Integration testing===&lt;br /&gt;
&lt;br /&gt;
Integration testing tests high level design i.e. components and their interfaces. In Integration testing the basic units will be tested together to check the interaction between them and finds errors in the interfaces. This is generally a black box testing method. Integration testing is  performed by program team leaders.&lt;br /&gt;
&lt;br /&gt;
===System testing===&lt;br /&gt;
&lt;br /&gt;
Once the entire system has been developed, it then has to be tested against the system specifications to validate if it provides the required features. In short, system testing is about checking the system as a whole. System testing involves a number of special types of tests to see if all the functional and nonfunctional requirements have been met. System testing is performed by system testers.&lt;br /&gt;
Reasons for carrying out a system test even after the unit and integration test&lt;br /&gt;
&lt;br /&gt;
*The previous testings were done against the system specifications. The system test, looks at the system from the perspective of the future user.&lt;br /&gt;
&lt;br /&gt;
*Many of the system functions and characteristics results from the interaction of  the modules, and can be tested only at this level. &lt;br /&gt;
&lt;br /&gt;
*Also, keeping in mind that the customer and the end user can be two different groups of people having their own requirements and interests. &lt;br /&gt;
&lt;br /&gt;
===Acceptance testing===&lt;br /&gt;
&lt;br /&gt;
The major purpose of Acceptance Testing is to validate or confirm that the system meets the  business requirements and gives an assurance before it is delivered to the end user. This phase is for testing the software in the real world by the end user to determine whether to accept the system or not.&lt;br /&gt;
&lt;br /&gt;
===Release testing===&lt;br /&gt;
&lt;br /&gt;
This testing phase answers important questions such as&lt;br /&gt;
&lt;br /&gt;
*Is the software suitable for the end user?&lt;br /&gt;
&lt;br /&gt;
*Has the compatibility with other systems been ensured?&lt;br /&gt;
&lt;br /&gt;
*Is the performance of the software optimized?&lt;br /&gt;
&lt;br /&gt;
=='''Advantages'''==&lt;br /&gt;
&lt;br /&gt;
*Early acceptance criteria is the key advantage, they are performed against a specification of requirements.&lt;br /&gt;
&lt;br /&gt;
*60 to 70 percent of all faults are in the system before the component construction and test stages start, which is taken care of. &lt;br /&gt;
&lt;br /&gt;
*At an early stage we can feed back to catch a fault before it is built into the system.&lt;br /&gt;
&lt;br /&gt;
*Specifies test requirements and expected results prior to performing the actual tests.&lt;br /&gt;
&lt;br /&gt;
*Defines who is responsible for performing the testing and provides a focus for defining the testing that takes place at each stage. &lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages'''==&lt;br /&gt;
&lt;br /&gt;
*Too simple to reflect the development process.&lt;br /&gt;
&lt;br /&gt;
*Leads project managers to a false sense of security.&lt;br /&gt;
&lt;br /&gt;
*Inflexible and no ability to respond to change.&lt;br /&gt;
&lt;br /&gt;
*Produces inefficient testing methodologies&lt;br /&gt;
&lt;br /&gt;
*The placing of contracts for services is not regulated.&lt;br /&gt;
&lt;br /&gt;
*The organization and execution of operation, maintenance, repair and disposal of the system are not covered by the V-Model. &lt;br /&gt;
&lt;br /&gt;
*The V-Model addresses software development within a project rather than a whole organization.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
&lt;br /&gt;
Testing in the development process is critical. The earlier a fault is found, the cheaper it is to fix. The V model extends testing to the beginning of the lifecycle. The explicit recognition of testing in the V model makes it very useful in planning and executing information system development. The V-Model has evolved over time and supports flexibility and agility throughout the development process. Static testing techniques, such as inspections and walkthroughs, can be used to find faults in the functional specification, as well as defining test cases that are subsequently executed in system testing.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
http://www.softwaretestingclass.com/v-model/&lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/V-Model_(software_development)&lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/V-Model&lt;br /&gt;
&lt;br /&gt;
http://www.careerride.com/testing-v-model.aspx&lt;br /&gt;
&lt;br /&gt;
http://www.softwaretestingmentor.com/sdlc/vmodel.php&lt;br /&gt;
&lt;br /&gt;
http://www.bucanac.com/documents/The_V-Model.pdf&lt;br /&gt;
&lt;br /&gt;
http://www.compensationanalytics.com/_resources/vtestingmodel.pdf&lt;br /&gt;
&lt;br /&gt;
http://www.google.co.in/search?q=v+model&amp;amp;hl=en&amp;amp;biw=1241&amp;amp;bih=606&amp;amp;prmd=imvnsb&amp;amp;tbm=isch&amp;amp;tbo=u&amp;amp;source=univ&amp;amp;sa=X&amp;amp;ei=XVd8UICgNYem9gSa4oCYDA&amp;amp;sqi=2&amp;amp;ved=0CC8QsAQ&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
&lt;br /&gt;
*Dual Vee Model - http://en.wikipedia.org/wiki/Dual_Vee_Model&lt;br /&gt;
&lt;br /&gt;
*System Development Lifecycle - http://en.wikipedia.org/wiki/Systems_Development_Life_Cycle&lt;br /&gt;
&lt;br /&gt;
*Product Lifecycle Management - http://en.wikipedia.org/wiki/Product_lifecycle_management&lt;br /&gt;
&lt;br /&gt;
*Portal: Software Testing - http://en.wikipedia.org/wiki/Portal:Software_Testing&lt;br /&gt;
&lt;br /&gt;
*IBM RUP - http://en.wikipedia.org/wiki/RUP&lt;br /&gt;
&lt;br /&gt;
*Systems Architecture - http://en.wikipedia.org/wiki/Systems_architecture&lt;br /&gt;
&lt;br /&gt;
*System Analysis - http://en.wikipedia.org/wiki/Systems_analysis&lt;br /&gt;
&lt;br /&gt;
*System Design - http://en.wikipedia.org/wiki/Systems_design&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w4_sa&amp;diff=68171</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w4 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w4_sa&amp;diff=68171"/>
		<updated>2012-10-25T11:11:13Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''V - Model'''&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
&lt;br /&gt;
The V-model also called as Verification and Validation model is a software development process which simplifies the understanding of the complexity associated with the development of a system,  and is an extension to the waterfall model. Rather than proceeding linearly downwards, after the coding phase, the process steps are bent upwards to form a V shape. This creates an association between the phases in the development and the testing cycle.&lt;br /&gt;
&lt;br /&gt;
In the diagram, the left arm corresponds to the development phases in the traditional waterfall model and the right to the test phases. Each development activity carried out by the development team has its corresponding validation activity done by the testing team.&lt;br /&gt;
&lt;br /&gt;
=='''From Waterfall to V-Model'''==&lt;br /&gt;
&lt;br /&gt;
Every phase or stage in the waterfall model needs to be completed and signed off before the next phase can start, this rigidity affects the flexibility in iterating back and forth between the stages of development with the result being a poor quality system. The V-Model prevents this by explicitly connecting the development and testing stages.&lt;br /&gt;
&lt;br /&gt;
=='''Objectives'''==&lt;br /&gt;
&lt;br /&gt;
The V-Model facilitates the planning and realization of projects. The following are the objectives to be achieved during system development:&lt;br /&gt;
&lt;br /&gt;
*Minimizing Project Risks: Early recognition of planning deviations and risks improves process management, thus reducing risks.&lt;br /&gt;
&lt;br /&gt;
*Improving Quality: Defined interim results can be checked at an early stage. Uniform product contents will improve readability, understandability and verifiability.&lt;br /&gt;
&lt;br /&gt;
*Reduction of Total Cost: The results obtained should be uniform and easily retraced. This reduces the dependency on the supplier and the effort for subsequent activities.&lt;br /&gt;
&lt;br /&gt;
*Effective Communication between all Stakeholders: The miscommunication between user, supplier and developer is reduced.&lt;br /&gt;
&lt;br /&gt;
=='''Verification phase'''==&lt;br /&gt;
&lt;br /&gt;
Verification ensures that, the software is being built correctly. The ISTQB defines Verification as: “Confirmation by examination and through provision of objective evidence that specified requirements have been fulfilled.“&lt;br /&gt;
&lt;br /&gt;
The first part of the definition is the same as for Validation, but the second part is the key. This states that “specified requirements have been fulfilled“. The V-model diagram arrows shows that each produced product is checked against the products or documents that were used to drive the development. This ensures that all aspects have been met. A key problem is ensuring that the user requirements are adequately verified against the customer needs. The Business Case is only likely to contain high level functionality, and not the detail about processes that are essential for determining what is required.&lt;br /&gt;
&lt;br /&gt;
=='''Requirements Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Requirements analysis encompasses those tasks that determine the conditions specified by the stakeholders for the product. Its activities are concerned with eliciting, analyzing, documenting, validating and managing system requirements. The requirements have to be documentable, actionable, measurable, testable, traceable, related to the business needs and should include details sufficient for system design.&lt;br /&gt;
&lt;br /&gt;
Requirements analysis includes three types of activities:&lt;br /&gt;
&lt;br /&gt;
*Eliciting requirements: Identifying the various types of requirements from various sources i.e. project and business process documentation along with stakeholder interviews.&lt;br /&gt;
&lt;br /&gt;
*Analyzing requirements: Determining whether the specified requirements are clear, complete and consistent.&lt;br /&gt;
&lt;br /&gt;
*Recording requirements: Requirements can be documented in normal language documents, use cases, user stories, or system specifications.&lt;br /&gt;
&lt;br /&gt;
Requirements analysis is a long process during which many changes can occur over that time period. Technology changes, business requirements changes with many other things, so it is important that the stakeholders are in constant touch with the developers to ensure that they understand the new improved system. It is the responsibility of the analyst to gather information from the customer. System prototypes should be developed to demonstrate a working model to the stakeholders. Analysts employ a combination of various methods to establish the exact requirements of the stakeholders, so that the system developed meets the customer’s needs. The information regarding the product requirements can be classified as: Customer, Architectural, Structural, Behavioral, Functional, Non-functional, Performance, Design, Derived, and Allocated Requirements.&lt;br /&gt;
&lt;br /&gt;
=='''System Design'''==&lt;br /&gt;
&lt;br /&gt;
This design process defines the architecture, components, modules, interfaces, and data required by a system to meet the mentioned system requirements. We can say that design is an act of taking the marketing information and creating the products to be manufactured. So, systems design is the process of defining and developing systems specified by the user.&lt;br /&gt;
&lt;br /&gt;
*Softwares that run on generic platforms have enhanced software engineering. &lt;br /&gt;
&lt;br /&gt;
*Object-oriented analysis and design methods are widely used for systems design.&lt;br /&gt;
&lt;br /&gt;
*UML is used for modeling software systems and designing high non-software systems and organizations.&lt;br /&gt;
&lt;br /&gt;
=='''Architecture Design'''==&lt;br /&gt;
&lt;br /&gt;
The design of computer and software architecture can be referred to as high-level design. The architecture selected should realize the list of modules, brief functionality of each module, the interface relationships between the modules, dependencies, database tables, architecture diagrams, technology details etc.&lt;br /&gt;
&lt;br /&gt;
Integration testing design is carried out in this phase.&lt;br /&gt;
&lt;br /&gt;
=='''Module Design'''==&lt;br /&gt;
&lt;br /&gt;
The module design phase is a low-level design. The designed system is broken up into smaller units and each of them is explained to the programmer. The low level design document will contain a detailed functional logic of the module:&lt;br /&gt;
&lt;br /&gt;
*database tables, with all elements, including their type and size&lt;br /&gt;
&lt;br /&gt;
*all interface details with complete API references&lt;br /&gt;
&lt;br /&gt;
*all dependency issues&lt;br /&gt;
&lt;br /&gt;
*error message listings&lt;br /&gt;
&lt;br /&gt;
*complete input and outputs for a module.&lt;br /&gt;
&lt;br /&gt;
Unit test design is developed in this stage.&lt;br /&gt;
&lt;br /&gt;
=='''Coding'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Validation phase'''==&lt;br /&gt;
===Importance of Early Testing===&lt;br /&gt;
&lt;br /&gt;
Studies show that catching a fault early in the development stages before the system is released is more cost effective and it takes less resources to fix the system when compared to fixing it after its release. We must also take into account the reputation of the organisation, the cost associated with missing functionality, so in fact the true cost for fixing the system is much higher.&lt;br /&gt;
&lt;br /&gt;
In the waterfall model errors were found very late in the cycle because testing began at the end of the project. In the V-Model testing begins as early as possible. Prior to testing, the testing team works on various activities in parallel to the development activity which helps to get the test deliverable on time which includes creation of test cases, preparation of test strategies, test planning and test scripting.&lt;br /&gt;
&lt;br /&gt;
===Testing Types Matched to Development Stages===&lt;br /&gt;
&lt;br /&gt;
The first noticeable point of the V-Model is that the Test stage of the Waterfall model is bent upwards to make it a “V”. This stage is now separated out into the various types of testing. So this first step visually points out that there is more than one type of testing to consider for system development and like the development steps they build on one another, and have different objectives. The next important part of the “V” is to match each type of testing against the development stage it matches e.g. we have Component Design matched against Component Testing. This means that the testing stage does not start when the Construct Component stage has ended. Instead when each development stage starts, the testing for that stage also starts.&lt;br /&gt;
&lt;br /&gt;
===Unit testing===&lt;br /&gt;
&lt;br /&gt;
Unit testing, tests the low level design i.e. units. A unit is a basic module of the application on which testing is carried out, it may be an individual function or a procedure. These tests are created by the developers (white box testing) to verify the internal logic code. Input data are passed to the unit to test every case of execution.&lt;br /&gt;
&lt;br /&gt;
===Integration testing===&lt;br /&gt;
&lt;br /&gt;
Integration testing tests high level design i.e. components and their interfaces. In Integration testing the basic units will be tested together to check the interaction between them and finds errors in the interfaces. This is generally a black box testing method. Integration testing is  performed by program team leaders.&lt;br /&gt;
&lt;br /&gt;
===System testing===&lt;br /&gt;
&lt;br /&gt;
Once the entire system has been developed, it then has to be tested against the system specifications to validate if it provides the required features. In short, system testing is about checking the system as a whole. System testing involves a number of special types of tests to see if all the functional and nonfunctional requirements have been met. System testing is performed by system testers.&lt;br /&gt;
Reasons for carrying out a system test even after the unit and integration test&lt;br /&gt;
&lt;br /&gt;
*The previous testings were done against the system specifications. The system test, looks at the system from the perspective of the future user.&lt;br /&gt;
&lt;br /&gt;
*Many of the system functions and characteristics results from the interaction of  the modules, and can be tested only at this level. &lt;br /&gt;
&lt;br /&gt;
*Also, keeping in mind that the customer and the end user can be two different groups of people having their own requirements and interests. &lt;br /&gt;
&lt;br /&gt;
===Acceptance testing===&lt;br /&gt;
&lt;br /&gt;
The major purpose of Acceptance Testing is to validate or confirm that the system meets the  business requirements and gives an assurance before it is delivered to the end user. This phase is for testing the software in the real world by the end user to determine whether to accept the system or not.&lt;br /&gt;
&lt;br /&gt;
===Release testing===&lt;br /&gt;
&lt;br /&gt;
This testing phase answers important questions such as&lt;br /&gt;
&lt;br /&gt;
*Is the software suitable for the end user?&lt;br /&gt;
&lt;br /&gt;
*Has the compatibility with other systems been ensured?&lt;br /&gt;
&lt;br /&gt;
*Is the performance of the software optimized?&lt;br /&gt;
&lt;br /&gt;
=='''Advantages'''==&lt;br /&gt;
&lt;br /&gt;
*Early acceptance criteria is the key advantage, they are performed against a specification of requirements.&lt;br /&gt;
&lt;br /&gt;
*60 to 70 percent of all faults are in the system before the component construction and test stages start, which is taken care of. &lt;br /&gt;
&lt;br /&gt;
*At an early stage we can feed back to catch a fault before it is built into the system.&lt;br /&gt;
&lt;br /&gt;
*Specifies test requirements and expected results prior to performing the actual tests.&lt;br /&gt;
&lt;br /&gt;
*Defines who is responsible for performing the testing and provides a focus for defining the testing that takes place at each stage. &lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages'''==&lt;br /&gt;
&lt;br /&gt;
*Too simple to reflect the development process.&lt;br /&gt;
&lt;br /&gt;
*Leads project managers to a false sense of security.&lt;br /&gt;
&lt;br /&gt;
*Inflexible and no ability to respond to change.&lt;br /&gt;
&lt;br /&gt;
*Produces inefficient testing methodologies&lt;br /&gt;
&lt;br /&gt;
*The placing of contracts for services is not regulated.&lt;br /&gt;
&lt;br /&gt;
*The organization and execution of operation, maintenance, repair and disposal of the system are not covered by the V-Model. &lt;br /&gt;
&lt;br /&gt;
*The V-Model addresses software development within a project rather than a whole organization.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
&lt;br /&gt;
Testing in the development process is critical. The earlier a fault is found, the cheaper it is to fix. The V model extends testing to the beginning of the lifecycle. The explicit recognition of testing in the V model makes it very useful in planning and executing information system development. The V-Model has evolved over time and supports flexibility and agility throughout the development process. Static testing techniques, such as inspections and walkthroughs, can be used to find faults in the functional specification, as well as defining test cases that are subsequently executed in system testing.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
http://www.softwaretestingclass.com/v-model/&lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/V-Model_(software_development)&lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/V-Model&lt;br /&gt;
&lt;br /&gt;
http://www.careerride.com/testing-v-model.aspx&lt;br /&gt;
&lt;br /&gt;
http://www.softwaretestingmentor.com/sdlc/vmodel.php&lt;br /&gt;
&lt;br /&gt;
http://www.bucanac.com/documents/The_V-Model.pdf&lt;br /&gt;
&lt;br /&gt;
http://www.compensationanalytics.com/_resources/vtestingmodel.pdf&lt;br /&gt;
&lt;br /&gt;
http://www.google.co.in/search?q=v+model&amp;amp;hl=en&amp;amp;biw=1241&amp;amp;bih=606&amp;amp;prmd=imvnsb&amp;amp;tbm=isch&amp;amp;tbo=u&amp;amp;source=univ&amp;amp;sa=X&amp;amp;ei=XVd8UICgNYem9gSa4oCYDA&amp;amp;sqi=2&amp;amp;ved=0CC8QsAQ&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
&lt;br /&gt;
*Dual Vee Model - http://en.wikipedia.org/wiki/Dual_Vee_Model&lt;br /&gt;
&lt;br /&gt;
*System Development Lifecycle - http://en.wikipedia.org/wiki/Systems_Development_Life_Cycle&lt;br /&gt;
&lt;br /&gt;
*Product Lifecycle Management - http://en.wikipedia.org/wiki/Product_lifecycle_management&lt;br /&gt;
&lt;br /&gt;
*Portal: Software Testing - http://en.wikipedia.org/wiki/Portal:Software_Testing&lt;br /&gt;
&lt;br /&gt;
*IBM RUP - http://en.wikipedia.org/wiki/RUP&lt;br /&gt;
&lt;br /&gt;
*Systems Architecture - http://en.wikipedia.org/wiki/Systems_architecture&lt;br /&gt;
&lt;br /&gt;
*System Analysis - http://en.wikipedia.org/wiki/Systems_analysis&lt;br /&gt;
&lt;br /&gt;
*System Design - http://en.wikipedia.org/wiki/Systems_design&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w4_sa&amp;diff=68170</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w4 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w4_sa&amp;diff=68170"/>
		<updated>2012-10-25T11:10:37Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''V - Model'''&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
&lt;br /&gt;
The V-model also called as Verification and Validation model is a software development process which simplifies the understanding of the complexity associated with the development of a system,  and is an extension to the waterfall model. Rather than proceeding linearly downwards, after the coding phase, the process steps are bent upwards to form a V shape. This creates an association between the phases in the development and the testing cycle.&lt;br /&gt;
&lt;br /&gt;
In the diagram, the left arm corresponds to the development phases in the traditional waterfall model and the right to the test phases. Each development activity carried out by the development team has its corresponding validation activity done by the testing team.&lt;br /&gt;
&lt;br /&gt;
=='''From Waterfall to V-Model'''==&lt;br /&gt;
&lt;br /&gt;
Every phase or stage in the waterfall model needs to be completed and signed off before the next phase can start, this rigidity affects the flexibility in iterating back and forth between the stages of development with the result being a poor quality system. The V-Model prevents this by explicitly connecting the development and testing stages.&lt;br /&gt;
&lt;br /&gt;
=='''Objectives'''==&lt;br /&gt;
&lt;br /&gt;
The V-Model facilitates the planning and realization of projects. The following are the objectives to be achieved during system development:&lt;br /&gt;
&lt;br /&gt;
*Minimizing Project Risks: Early recognition of planning deviations and risks improves process management, thus reducing risks.&lt;br /&gt;
&lt;br /&gt;
*Improving Quality: Defined interim results can be checked at an early stage. Uniform product contents will improve readability, understandability and verifiability.&lt;br /&gt;
&lt;br /&gt;
*Reduction of Total Cost: The results obtained should be uniform and easily retraced. This reduces the dependency on the supplier and the effort for subsequent activities.&lt;br /&gt;
&lt;br /&gt;
*Effective Communication between all Stakeholders: The miscommunication between user, supplier and developer is reduced.&lt;br /&gt;
&lt;br /&gt;
=='''Verification phase'''==&lt;br /&gt;
&lt;br /&gt;
Verification ensures that, the software is being built correctly. The ISTQB defines Verification as: “Confirmation by examination and through provision of objective evidence that specified requirements have been fulfilled.“&lt;br /&gt;
&lt;br /&gt;
The first part of the definition is the same as for Validation, but the second part is the key. This states that “specified requirements have been fulfilled“. The V-model diagram arrows shows that each produced product is checked against the products or documents that were used to drive the development. This ensures that all aspects have been met. A key problem is ensuring that the user requirements are adequately verified against the customer needs. The Business Case is only likely to contain high level functionality, and not the detail about processes that are essential for determining what is required.&lt;br /&gt;
&lt;br /&gt;
=='''Requirements Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Requirements analysis encompasses those tasks that determine the conditions specified by the stakeholders for the product. Its activities are concerned with eliciting, analyzing, documenting, validating and managing system requirements. The requirements have to be documentable, actionable, measurable, testable, traceable, related to the business needs and should include details sufficient for system design.&lt;br /&gt;
&lt;br /&gt;
Requirements analysis includes three types of activities:&lt;br /&gt;
&lt;br /&gt;
*Eliciting requirements: Identifying the various types of requirements from various sources i.e. project and business process documentation along with stakeholder interviews.&lt;br /&gt;
&lt;br /&gt;
*Analyzing requirements: Determining whether the specified requirements are clear, complete and consistent.&lt;br /&gt;
&lt;br /&gt;
*Recording requirements: Requirements can be documented in normal language documents, use cases, user stories, or system specifications.&lt;br /&gt;
&lt;br /&gt;
Requirements analysis is a long process during which many changes can occur over that time period. Technology changes, business requirements changes with many other things, so it is important that the stakeholders are in constant touch with the developers to ensure that they understand the new improved system. It is the responsibility of the analyst to gather information from the customer. System prototypes should be developed to demonstrate a working model to the stakeholders. Analysts employ a combination of various methods to establish the exact requirements of the stakeholders, so that the system developed meets the customer’s needs. The information regarding the product requirements can be classified as: Customer, Architectural, Structural, Behavioral, Functional, Non-functional, Performance, Design, Derived, and Allocated Requirements.&lt;br /&gt;
&lt;br /&gt;
=='''System Design'''==&lt;br /&gt;
&lt;br /&gt;
This design process defines the architecture, components, modules, interfaces, and data required by a system to meet the mentioned system requirements. We can say that design is an act of taking the marketing information and creating the products to be manufactured. So, systems design is the process of defining and developing systems specified by the user.&lt;br /&gt;
&lt;br /&gt;
*Softwares that run on generic platforms have enhanced software engineering. &lt;br /&gt;
&lt;br /&gt;
*Object-oriented analysis and design methods are widely used for systems design.&lt;br /&gt;
&lt;br /&gt;
*UML is used for modeling software systems and designing high non-software systems and organizations.&lt;br /&gt;
&lt;br /&gt;
=='''Architecture Design'''==&lt;br /&gt;
&lt;br /&gt;
The design of computer and software architecture can be referred to as high-level design. The architecture selected should realize the list of modules, brief functionality of each module, the interface relationships between the modules, dependencies, database tables, architecture diagrams, technology details etc.&lt;br /&gt;
&lt;br /&gt;
Integration testing design is carried out in this phase.&lt;br /&gt;
&lt;br /&gt;
=='''Module Design'''==&lt;br /&gt;
&lt;br /&gt;
The module design phase is a low-level design. The designed system is broken up into smaller units and each of them is explained to the programmer. The low level design document will contain a detailed functional logic of the module:&lt;br /&gt;
&lt;br /&gt;
*database tables, with all elements, including their type and size&lt;br /&gt;
&lt;br /&gt;
*all interface details with complete API references&lt;br /&gt;
&lt;br /&gt;
*all dependency issues&lt;br /&gt;
&lt;br /&gt;
*error message listings&lt;br /&gt;
&lt;br /&gt;
*complete input and outputs for a module.&lt;br /&gt;
&lt;br /&gt;
Unit test design is developed in this stage.&lt;br /&gt;
&lt;br /&gt;
=='''Coding'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Validation phase'''==&lt;br /&gt;
===Importance of Early Testing===&lt;br /&gt;
&lt;br /&gt;
Studies show that catching a fault early in the development stages before the system is released is more cost effective and it takes less resources to fix the system when compared to fixing it after its release. We must also take into account the reputation of the organisation, the cost associated with missing functionality, so in fact the true cost for fixing the system is much higher.&lt;br /&gt;
&lt;br /&gt;
In the waterfall model errors were found very late in the cycle because testing began at the end of the project. In the V-Model testing begins as early as possible. Prior to testing, the testing team works on various activities in parallel to the development activity which helps to get the test deliverable on time which includes creation of test cases, preparation of test strategies, test planning and test scripting.&lt;br /&gt;
&lt;br /&gt;
===Testing Types Matched to Development Stages===&lt;br /&gt;
&lt;br /&gt;
The first noticeable point of the V-Model is that the Test stage of the Waterfall model is bent upwards to make it a “V”. This stage is now separated out into the various types of testing. So this first step visually points out that there is more than one type of testing to consider for system development and like the development steps they build on one another, and have different objectives. The next important part of the “V” is to match each type of testing against the development stage it matches e.g. we have Component Design matched against Component Testing. This means that the testing stage does not start when the Construct Component stage has ended. Instead when each development stage starts, the testing for that stage also starts.&lt;br /&gt;
&lt;br /&gt;
===Unit testing===&lt;br /&gt;
&lt;br /&gt;
Unit testing, tests the low level design i.e. units. A unit is a basic module of the application on which testing is carried out, it may be an individual function or a procedure. These tests are created by the developers (white box testing) to verify the internal logic code. Input data are passed to the unit to test every case of execution.&lt;br /&gt;
&lt;br /&gt;
===Integration testing===&lt;br /&gt;
&lt;br /&gt;
Integration testing tests high level design i.e. components and their interfaces. In Integration testing the basic units will be tested together to check the interaction between them and finds errors in the interfaces. This is generally a black box testing method. Integration testing is  performed by program team leaders.&lt;br /&gt;
&lt;br /&gt;
===System testing===&lt;br /&gt;
&lt;br /&gt;
Once the entire system has been developed, it then has to be tested against the system specifications to validate if it provides the required features. In short, system testing is about checking the system as a whole. System testing involves a number of special types of tests to see if all the functional and nonfunctional requirements have been met. System testing is performed by system testers.&lt;br /&gt;
Reasons for carrying out a system test even after the unit and integration test&lt;br /&gt;
&lt;br /&gt;
*The previous testings were done against the system specifications. The system test, looks at the system from the perspective of the future user.&lt;br /&gt;
&lt;br /&gt;
*Many of the system functions and characteristics results from the interaction of  the modules, and can be tested only at this level. &lt;br /&gt;
&lt;br /&gt;
*Also, keeping in mind that the customer and the end user can be two different groups of people having their own requirements and interests. &lt;br /&gt;
&lt;br /&gt;
===Acceptance testing===&lt;br /&gt;
&lt;br /&gt;
The major purpose of Acceptance Testing is to validate or confirm that the system meets the  business requirements and gives an assurance before it is delivered to the end user. This phase is for testing the software in the real world by the end user to determine whether to accept the system or not.&lt;br /&gt;
&lt;br /&gt;
===Release testing===&lt;br /&gt;
&lt;br /&gt;
This testing phase answers important questions such as&lt;br /&gt;
&lt;br /&gt;
*Is the software suitable for the end user?&lt;br /&gt;
&lt;br /&gt;
*Has the compatibility with other systems been ensured?&lt;br /&gt;
&lt;br /&gt;
*Is the performance of the software optimized?&lt;br /&gt;
&lt;br /&gt;
=='''Advantages'''==&lt;br /&gt;
&lt;br /&gt;
*Early acceptance criteria is the key advantage, they are performed against a specification of requirements.&lt;br /&gt;
&lt;br /&gt;
*60 to 70 percent of all faults are in the system before the component construction and test stages start, which is taken care of. &lt;br /&gt;
&lt;br /&gt;
*At an early stage we can feed back to catch a fault before it is built into the system.&lt;br /&gt;
&lt;br /&gt;
*Specifies test requirements and expected results prior to performing the actual tests.&lt;br /&gt;
&lt;br /&gt;
*Defines who is responsible for performing the testing and provides a focus for defining the testing that takes place at each stage. &lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages'''==&lt;br /&gt;
&lt;br /&gt;
*Too simple to reflect the development process.&lt;br /&gt;
&lt;br /&gt;
*Leads project managers to a false sense of security.&lt;br /&gt;
&lt;br /&gt;
*Inflexible and no ability to respond to change.&lt;br /&gt;
&lt;br /&gt;
*Produces inefficient testing methodologies&lt;br /&gt;
&lt;br /&gt;
*The placing of contracts for services is not regulated.&lt;br /&gt;
&lt;br /&gt;
*The organization and execution of operation, maintenance, repair and disposal of the system are not covered by the V-Model. &lt;br /&gt;
&lt;br /&gt;
*The V-Model addresses software development within a project rather than a whole organization.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
&lt;br /&gt;
Testing in the development process is critical. The earlier a fault is found, the cheaper it is to fix. The V model extends testing to the beginning of the lifecycle. The explicit recognition of testing in the V model makes it very useful in planning and executing information system development. The V-Model has evolved over time and supports flexibility and agility throughout the development process. Static testing techniques, such as inspections and walkthroughs, can be used to find faults in the functional specification, as well as defining test cases that are subsequently executed in system testing.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
http://www.softwaretestingclass.com/v-model/&lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/V-Model_(software_development)&lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/V-Model&lt;br /&gt;
&lt;br /&gt;
http://www.careerride.com/testing-v-model.aspx&lt;br /&gt;
&lt;br /&gt;
http://www.softwaretestingmentor.com/sdlc/vmodel.php&lt;br /&gt;
&lt;br /&gt;
http://www.bucanac.com/documents/The_V-Model.pdf&lt;br /&gt;
&lt;br /&gt;
http://www.compensationanalytics.com/_resources/vtestingmodel.pdf&lt;br /&gt;
&lt;br /&gt;
http://www.google.co.in/search?q=v+model&amp;amp;hl=en&amp;amp;biw=1241&amp;amp;bih=606&amp;amp;prmd=imvnsb&amp;amp;tbm=isch&amp;amp;tbo=u&amp;amp;source=univ&amp;amp;sa=X&amp;amp;ei=XVd8UICgNYem9gSa4oCYDA&amp;amp;sqi=2&amp;amp;ved=0CC8QsAQ&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
&lt;br /&gt;
*Dual Vee Model - http://en.wikipedia.org/wiki/Dual_Vee_Model&lt;br /&gt;
&lt;br /&gt;
*System Development Lifecycle - http://en.wikipedia.org/wiki/Systems_Development_Life_Cycle&lt;br /&gt;
&lt;br /&gt;
*Product Lifecycle Management - http://en.wikipedia.org/wiki/Product_lifecycle_management&lt;br /&gt;
&lt;br /&gt;
*Portal: Software Testing - http://en.wikipedia.org/wiki/Portal:Software_Testing&lt;br /&gt;
&lt;br /&gt;
*IBM RUP - http://en.wikipedia.org/wiki/RUP&lt;br /&gt;
&lt;br /&gt;
*Systems Architecture - http://en.wikipedia.org/wiki/Systems_architecture&lt;br /&gt;
&lt;br /&gt;
*System Analysis - http://en.wikipedia.org/wiki/Systems_analysis&lt;br /&gt;
&lt;br /&gt;
*System Design - http://en.wikipedia.org/wiki/Systems_design&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w4_sa&amp;diff=68169</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w4 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w4_sa&amp;diff=68169"/>
		<updated>2012-10-25T11:10:10Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''V - Model'''&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
&lt;br /&gt;
The V-model also called as Verification and Validation model is a software development process which simplifies the understanding of the complexity associated with the development of a system,  and is an extension to the waterfall model. Rather than proceeding linearly downwards, after the coding phase, the process steps are bent upwards to form a V shape. This creates an association between the phases in the development and the testing cycle.&lt;br /&gt;
&lt;br /&gt;
In the diagram, the left arm corresponds to the development phases in the traditional waterfall model and the right to the test phases. Each development activity carried out by the development team has its corresponding validation activity done by the testing team.&lt;br /&gt;
&lt;br /&gt;
=='''From Waterfall to V-Model'''==&lt;br /&gt;
&lt;br /&gt;
Every phase or stage in the waterfall model needs to be completed and signed off before the next phase can start, this rigidity affects the flexibility in iterating back and forth between the stages of development with the result being a poor quality system. The V-Model prevents this by explicitly connecting the development and testing stages.&lt;br /&gt;
&lt;br /&gt;
=='''Objectives'''==&lt;br /&gt;
&lt;br /&gt;
The V-Model facilitates the planning and realization of projects. The following are the objectives to be achieved during system development:&lt;br /&gt;
&lt;br /&gt;
*Minimizing Project Risks: Early recognition of planning deviations and risks improves process management, thus reducing risks.&lt;br /&gt;
&lt;br /&gt;
*Improving Quality: Defined interim results can be checked at an early stage. Uniform product contents will improve readability, understandability and verifiability.&lt;br /&gt;
&lt;br /&gt;
*Reduction of Total Cost: The results obtained should be uniform and easily retraced. This reduces the dependency on the supplier and the effort for subsequent activities.&lt;br /&gt;
&lt;br /&gt;
*Effective Communication between all Stakeholders: The miscommunication between user, supplier and developer is reduced.&lt;br /&gt;
&lt;br /&gt;
=='''Verification phase'''==&lt;br /&gt;
&lt;br /&gt;
Verification ensures that, the software is being built correctly. The ISTQB defines Verification as: “Confirmation by examination and through provision of objective evidence that specified requirements have been fulfilled.“&lt;br /&gt;
&lt;br /&gt;
The first part of the definition is the same as for Validation, but the second part is the key. This states that “specified requirements have been fulfilled“. The V-model diagram arrows shows that each produced product is checked against the products or documents that were used to drive the development. This ensures that all aspects have been met. A key problem is ensuring that the user requirements are adequately verified against the customer needs. The Business Case is only likely to contain high level functionality, and not the detail about processes that are essential for determining what is required.&lt;br /&gt;
&lt;br /&gt;
=='''Requirements Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Requirements analysis encompasses those tasks that determine the conditions specified by the stakeholders for the product. Its activities are concerned with eliciting, analyzing, documenting, validating and managing system requirements. The requirements have to be documentable, actionable, measurable, testable, traceable, related to the business needs and should include details sufficient for system design.&lt;br /&gt;
&lt;br /&gt;
Requirements analysis includes three types of activities:&lt;br /&gt;
&lt;br /&gt;
*Eliciting requirements: Identifying the various types of requirements from various sources i.e. project and business process documentation along with stakeholder interviews.&lt;br /&gt;
&lt;br /&gt;
*Analyzing requirements: Determining whether the specified requirements are clear, complete and consistent.&lt;br /&gt;
&lt;br /&gt;
*Recording requirements: Requirements can be documented in normal language documents, use cases, user stories, or system specifications.&lt;br /&gt;
&lt;br /&gt;
Requirements analysis is a long process during which many changes can occur over that time period. Technology changes, business requirements changes with many other things, so it is important that the stakeholders are in constant touch with the developers to ensure that they understand the new improved system. It is the responsibility of the analyst to gather information from the customer. System prototypes should be developed to demonstrate a working model to the stakeholders. Analysts employ a combination of various methods to establish the exact requirements of the stakeholders, so that the system developed meets the customer’s needs. The information regarding the product requirements can be classified as: Customer, Architectural, Structural, Behavioral, Functional, Non-functional, Performance, Design, Derived, and Allocated Requirements.&lt;br /&gt;
&lt;br /&gt;
=='''System Design'''==&lt;br /&gt;
&lt;br /&gt;
This design process defines the architecture, components, modules, interfaces, and data required by a system to meet the mentioned system requirements. We can say that design is an act of taking the marketing information and creating the products to be manufactured. So, systems design is the process of defining and developing systems specified by the user.&lt;br /&gt;
&lt;br /&gt;
*Softwares that run on generic platforms have enhanced software engineering. &lt;br /&gt;
&lt;br /&gt;
*Object-oriented analysis and design methods are widely used for systems design.&lt;br /&gt;
&lt;br /&gt;
*UML is used for modeling software systems and designing high non-software systems and organizations.&lt;br /&gt;
&lt;br /&gt;
=='''Architecture Design'''==&lt;br /&gt;
&lt;br /&gt;
The design of computer and software architecture can be referred to as high-level design. The architecture selected should realize the list of modules, brief functionality of each module, the interface relationships between the modules, dependencies, database tables, architecture diagrams, technology details etc.&lt;br /&gt;
&lt;br /&gt;
Integration testing design is carried out in this phase.&lt;br /&gt;
&lt;br /&gt;
=='''Module Design'''==&lt;br /&gt;
&lt;br /&gt;
The module design phase is a low-level design. The designed system is broken up into smaller units and each of them is explained to the programmer. The low level design document will contain a detailed functional logic of the module:&lt;br /&gt;
&lt;br /&gt;
*database tables, with all elements, including their type and size&lt;br /&gt;
&lt;br /&gt;
*all interface details with complete API references&lt;br /&gt;
&lt;br /&gt;
*all dependency issues&lt;br /&gt;
&lt;br /&gt;
*error message listings&lt;br /&gt;
&lt;br /&gt;
*complete input and outputs for a module.&lt;br /&gt;
&lt;br /&gt;
Unit test design is developed in this stage.&lt;br /&gt;
&lt;br /&gt;
=='''Coding'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Validation phase'''==&lt;br /&gt;
===Importance of Early Testing===&lt;br /&gt;
&lt;br /&gt;
Studies show that catching a fault early in the development stages before the system is released is more cost effective and it takes less resources to fix the system when compared to fixing it after its release. We must also take into account the reputation of the organisation, the cost associated with missing functionality, so in fact the true cost for fixing the system is much higher.&lt;br /&gt;
&lt;br /&gt;
In the waterfall model errors were found very late in the cycle because testing began at the end of the project. In the V-Model testing begins as early as possible. Prior to testing, the testing team works on various activities in parallel to the development activity which helps to get the test deliverable on time which includes creation of test cases, preparation of test strategies, test planning and test scripting.&lt;br /&gt;
&lt;br /&gt;
===Testing Types Matched to Development Stages===&lt;br /&gt;
&lt;br /&gt;
The first noticeable point of the V-Model is that the Test stage of the Waterfall model is bent upwards to make it a “V”. This stage is now separated out into the various types of testing. So this first step visually points out that there is more than one type of testing to consider for system development and like the development steps they build on one another, and have different objectives. The next important part of the “V” is to match each type of testing against the development stage it matches e.g. we have Component Design matched against Component Testing. This means that the testing stage does not start when the Construct Component stage has ended. Instead when each development stage starts, the testing for that stage also starts.&lt;br /&gt;
&lt;br /&gt;
===Unit testing===&lt;br /&gt;
&lt;br /&gt;
Unit testing, tests the low level design i.e. units. A unit is a basic module of the application on which testing is carried out, it may be an individual function or a procedure. These tests are created by the developers (white box testing) to verify the internal logic code. Input data are passed to the unit to test every case of execution.&lt;br /&gt;
&lt;br /&gt;
===Integration testing===&lt;br /&gt;
&lt;br /&gt;
Integration testing tests high level design i.e. components and their interfaces. In Integration testing the basic units will be tested together to check the interaction between them and finds errors in the interfaces. This is generally a black box testing method. Integration testing is  performed by program team leaders.&lt;br /&gt;
&lt;br /&gt;
===System testing===&lt;br /&gt;
&lt;br /&gt;
Once the entire system has been developed, it then has to be tested against the system specifications to validate if it provides the required features. In short, system testing is about checking the system as a whole. System testing involves a number of special types of tests to see if all the functional and nonfunctional requirements have been met. System testing is performed by system testers.&lt;br /&gt;
Reasons for carrying out a system test even after the unit and integration test&lt;br /&gt;
&lt;br /&gt;
*The previous testings were done against the system specifications. The system test, looks at the system from the perspective of the future user.&lt;br /&gt;
&lt;br /&gt;
*Many of the system functions and characteristics results from the interaction of  the modules, and can be tested only at this level. &lt;br /&gt;
&lt;br /&gt;
*Also, keeping in mind that the customer and the end user can be two different groups of people having their own requirements and interests. &lt;br /&gt;
&lt;br /&gt;
===Acceptance testing===&lt;br /&gt;
&lt;br /&gt;
The major purpose of Acceptance Testing is to validate or confirm that the system meets the  business requirements and gives an assurance before it is delivered to the end user. This phase is for testing the software in the real world by the end user to determine whether to accept the system or not.&lt;br /&gt;
&lt;br /&gt;
===Release testing===&lt;br /&gt;
&lt;br /&gt;
This testing phase answers important questions such as&lt;br /&gt;
&lt;br /&gt;
*Is the software suitable for the end user?&lt;br /&gt;
&lt;br /&gt;
*Has the compatibility with other systems been ensured?&lt;br /&gt;
&lt;br /&gt;
*Is the performance of the software optimized?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Advantages'''==&lt;br /&gt;
&lt;br /&gt;
*Early acceptance criteria is the key advantage, they are performed against a specification of requirements.&lt;br /&gt;
&lt;br /&gt;
*60 to 70 percent of all faults are in the system before the component construction and test stages start, which is taken care of. &lt;br /&gt;
&lt;br /&gt;
*At an early stage we can feed back to catch a fault before it is built into the system.&lt;br /&gt;
&lt;br /&gt;
*Specifies test requirements and expected results prior to performing the actual tests.&lt;br /&gt;
&lt;br /&gt;
*Defines who is responsible for performing the testing and provides a focus for defining the testing that takes place at each stage. &lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages'''==&lt;br /&gt;
&lt;br /&gt;
*Too simple to reflect the development process.&lt;br /&gt;
&lt;br /&gt;
*Leads project managers to a false sense of security.&lt;br /&gt;
&lt;br /&gt;
*Inflexible and no ability to respond to change.&lt;br /&gt;
&lt;br /&gt;
*Produces inefficient testing methodologies&lt;br /&gt;
&lt;br /&gt;
*The placing of contracts for services is not regulated.&lt;br /&gt;
&lt;br /&gt;
*The organization and execution of operation, maintenance, repair and disposal of the system are not covered by the V-Model. &lt;br /&gt;
&lt;br /&gt;
*The V-Model addresses software development within a project rather than a whole organization.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
&lt;br /&gt;
Testing in the development process is critical. The earlier a fault is found, the cheaper it is to fix. The V model extends testing to the beginning of the lifecycle. The explicit recognition of testing in the V model makes it very useful in planning and executing information system development. The V-Model has evolved over time and supports flexibility and agility throughout the development process. Static testing techniques, such as inspections and walkthroughs, can be used to find faults in the functional specification, as well as defining test cases that are subsequently executed in system testing.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
http://www.softwaretestingclass.com/v-model/&lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/V-Model_(software_development)&lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/V-Model&lt;br /&gt;
&lt;br /&gt;
http://www.careerride.com/testing-v-model.aspx&lt;br /&gt;
&lt;br /&gt;
http://www.softwaretestingmentor.com/sdlc/vmodel.php&lt;br /&gt;
&lt;br /&gt;
http://www.bucanac.com/documents/The_V-Model.pdf&lt;br /&gt;
&lt;br /&gt;
http://www.compensationanalytics.com/_resources/vtestingmodel.pdf&lt;br /&gt;
&lt;br /&gt;
http://www.google.co.in/search?q=v+model&amp;amp;hl=en&amp;amp;biw=1241&amp;amp;bih=606&amp;amp;prmd=imvnsb&amp;amp;tbm=isch&amp;amp;tbo=u&amp;amp;source=univ&amp;amp;sa=X&amp;amp;ei=XVd8UICgNYem9gSa4oCYDA&amp;amp;sqi=2&amp;amp;ved=0CC8QsAQ&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
&lt;br /&gt;
*Dual Vee Model - http://en.wikipedia.org/wiki/Dual_Vee_Model&lt;br /&gt;
&lt;br /&gt;
*System Development Lifecycle - http://en.wikipedia.org/wiki/Systems_Development_Life_Cycle&lt;br /&gt;
&lt;br /&gt;
*Product Lifecycle Management - http://en.wikipedia.org/wiki/Product_lifecycle_management&lt;br /&gt;
&lt;br /&gt;
*Portal: Software Testing - http://en.wikipedia.org/wiki/Portal:Software_Testing&lt;br /&gt;
&lt;br /&gt;
*IBM RUP - http://en.wikipedia.org/wiki/RUP&lt;br /&gt;
&lt;br /&gt;
*Systems Architecture - http://en.wikipedia.org/wiki/Systems_architecture&lt;br /&gt;
&lt;br /&gt;
*System Analysis - http://en.wikipedia.org/wiki/Systems_analysis&lt;br /&gt;
&lt;br /&gt;
*System Design - http://en.wikipedia.org/wiki/Systems_design&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w4_sa&amp;diff=68168</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w4 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w4_sa&amp;diff=68168"/>
		<updated>2012-10-25T11:09:06Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''V - Model'''&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
&lt;br /&gt;
The V-model also called as Verification and Validation model is a software development process which simplifies the understanding of the complexity associated with the development of a system,  and is an extension to the waterfall model. Rather than proceeding linearly downwards, after the coding phase, the process steps are bent upwards to form a V shape. This creates an association between the phases in the development and the testing cycle.&lt;br /&gt;
&lt;br /&gt;
In the diagram, the left arm corresponds to the development phases in the traditional waterfall model and the right to the test phases. Each development activity carried out by the development team has its corresponding validation activity done by the testing team.&lt;br /&gt;
&lt;br /&gt;
=='''From Waterfall to V-Model'''==&lt;br /&gt;
&lt;br /&gt;
Every phase or stage in the waterfall model needs to be completed and signed off before the next phase can start, this rigidity affects the flexibility in iterating back and forth between the stages of development with the result being a poor quality system. The V-Model prevents this by explicitly connecting the development and testing stages.&lt;br /&gt;
&lt;br /&gt;
=='''Objectives'''==&lt;br /&gt;
&lt;br /&gt;
The V-Model facilitates the planning and realization of projects. The following are the objectives to be achieved during system development:&lt;br /&gt;
&lt;br /&gt;
*Minimizing Project Risks: Early recognition of planning deviations and risks improves process management, thus reducing risks.&lt;br /&gt;
&lt;br /&gt;
*Improving Quality: Defined interim results can be checked at an early stage. Uniform product contents will improve readability, understandability and verifiability.&lt;br /&gt;
&lt;br /&gt;
*Reduction of Total Cost: The results obtained should be uniform and easily retraced. This reduces the dependency on the supplier and the effort for subsequent activities.&lt;br /&gt;
&lt;br /&gt;
*Effective Communication between all Stakeholders: The miscommunication between user, supplier and developer is reduced.&lt;br /&gt;
&lt;br /&gt;
=='''Verification phase'''==&lt;br /&gt;
&lt;br /&gt;
Verification ensures that, the software is being built correctly. The ISTQB defines Verification as: “Confirmation by examination and through provision of objective evidence that specified requirements have been fulfilled.“&lt;br /&gt;
&lt;br /&gt;
The first part of the definition is the same as for Validation, but the second part is the key. This states that “specified requirements have been fulfilled“. The V-model diagram arrows shows that each produced product is checked against the products or documents that were used to drive the development. This ensures that all aspects have been met. A key problem is ensuring that the user requirements are adequately verified against the customer needs. The Business Case is only likely to contain high level functionality, and not the detail about processes that are essential for determining what is required.&lt;br /&gt;
&lt;br /&gt;
=='''Requirements Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Requirements analysis encompasses those tasks that determine the conditions specified by the stakeholders for the product. Its activities are concerned with eliciting, analyzing, documenting, validating and managing system requirements. The requirements have to be documentable, actionable, measurable, testable, traceable, related to the business needs and should include details sufficient for system design.&lt;br /&gt;
&lt;br /&gt;
Requirements analysis includes three types of activities:&lt;br /&gt;
&lt;br /&gt;
*Eliciting requirements: Identifying the various types of requirements from various sources i.e. project and business process documentation along with stakeholder interviews.&lt;br /&gt;
&lt;br /&gt;
*Analyzing requirements: Determining whether the specified requirements are clear, complete and consistent.&lt;br /&gt;
&lt;br /&gt;
*Recording requirements: Requirements can be documented in normal language documents, use cases, user stories, or system specifications.&lt;br /&gt;
&lt;br /&gt;
Requirements analysis is a long process during which many changes can occur over that time period. Technology changes, business requirements changes with many other things, so it is important that the stakeholders are in constant touch with the developers to ensure that they understand the new improved system. It is the responsibility of the analyst to gather information from the customer. System prototypes should be developed to demonstrate a working model to the stakeholders. Analysts employ a combination of various methods to establish the exact requirements of the stakeholders, so that the system developed meets the customer’s needs. The information regarding the product requirements can be classified as: Customer, Architectural, Structural, Behavioral, Functional, Non-functional, Performance, Design, Derived, and Allocated Requirements.&lt;br /&gt;
&lt;br /&gt;
=='''System Design'''==&lt;br /&gt;
&lt;br /&gt;
This design process defines the architecture, components, modules, interfaces, and data required by a system to meet the mentioned system requirements. We can say that design is an act of taking the marketing information and creating the products to be manufactured. So, systems design is the process of defining and developing systems specified by the user.&lt;br /&gt;
&lt;br /&gt;
*Softwares that run on generic platforms have enhanced software engineering. &lt;br /&gt;
&lt;br /&gt;
*Object-oriented analysis and design methods are widely used for systems design.&lt;br /&gt;
&lt;br /&gt;
*UML is used for modeling software systems and designing high non-software systems and organizations.&lt;br /&gt;
&lt;br /&gt;
=='''Architecture Design'''==&lt;br /&gt;
&lt;br /&gt;
The design of computer and software architecture can be referred to as high-level design. The architecture selected should realize the list of modules, brief functionality of each module, the interface relationships between the modules, dependencies, database tables, architecture diagrams, technology details etc.&lt;br /&gt;
&lt;br /&gt;
Integration testing design is carried out in this phase.&lt;br /&gt;
&lt;br /&gt;
=='''Module Design'''==&lt;br /&gt;
&lt;br /&gt;
The module design phase is a low-level design. The designed system is broken up into smaller units and each of them is explained to the programmer. The low level design document will contain a detailed functional logic of the module:&lt;br /&gt;
&lt;br /&gt;
*database tables, with all elements, including their type and size&lt;br /&gt;
&lt;br /&gt;
*all interface details with complete API references&lt;br /&gt;
&lt;br /&gt;
*all dependency issues&lt;br /&gt;
&lt;br /&gt;
*error message listings&lt;br /&gt;
&lt;br /&gt;
*complete input and outputs for a module.&lt;br /&gt;
&lt;br /&gt;
Unit test design is developed in this stage.&lt;br /&gt;
&lt;br /&gt;
=='''Coding'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Validation phase'''==&lt;br /&gt;
===Importance of Early Testing===&lt;br /&gt;
&lt;br /&gt;
Studies show that catching a fault early in the development stages before the system is released is more cost effective and it takes less resources to fix the system when compared to fixing it after its release. We must also take into account the reputation of the organisation, the cost associated with missing functionality, so in fact the true cost for fixing the system is much higher.&lt;br /&gt;
&lt;br /&gt;
In the waterfall model errors were found very late in the cycle because testing began at the end of the project. In the V-Model testing begins as early as possible. Prior to testing, the testing team works on various activities in parallel to the development activity which helps to get the test deliverable on time which includes creation of test cases, preparation of test strategies, test planning and test scripting.&lt;br /&gt;
&lt;br /&gt;
===Testing Types Matched to Development Stages===&lt;br /&gt;
&lt;br /&gt;
The first noticeable point of the V-Model is that the Test stage of the Waterfall model is bent upwards to make it a “V”. This stage is now separated out into the various types of testing. So this first step visually points out that there is more than one type of testing to consider for system development and like the development steps they build on one another, and have different objectives. The next important part of the “V” is to match each type of testing against the development stage it matches e.g. we have Component Design matched against Component Testing. This means that the testing stage does not start when the Construct Component stage has ended. Instead when each development stage starts, the testing for that stage also starts.&lt;br /&gt;
&lt;br /&gt;
===Unit testing===&lt;br /&gt;
&lt;br /&gt;
Unit testing, tests the low level design i.e. units. A unit is a basic module of the application on which testing is carried out, it may be an individual function or a procedure. These tests are created by the developers (white box testing) to verify the internal logic code. Input data are passed to the unit to test every case of execution.&lt;br /&gt;
&lt;br /&gt;
===Integration testing===&lt;br /&gt;
&lt;br /&gt;
Integration testing tests high level design i.e. components and their interfaces. In Integration testing the basic units will be tested together to check the interaction between them and finds errors in the interfaces. This is generally a black box testing method. Integration testing is  performed by program team leaders.&lt;br /&gt;
&lt;br /&gt;
===System testing===&lt;br /&gt;
&lt;br /&gt;
Once the entire system has been developed, it then has to be tested against the system specifications to validate if it provides the required features. In short, system testing is about checking the system as a whole. System testing involves a number of special types of tests to see if all the functional and nonfunctional requirements have been met. System testing is performed by system testers.&lt;br /&gt;
Reasons for carrying out a system test even after the unit and integration test&lt;br /&gt;
&lt;br /&gt;
*The previous testings were done against the system specifications. The system test, looks at the system from the perspective of the future user.&lt;br /&gt;
&lt;br /&gt;
*Many of the system functions and characteristics results from the interaction of  the modules, and can be tested only at this level. &lt;br /&gt;
&lt;br /&gt;
*Also, keeping in mind that the customer and the end user can be two different groups of people having their own requirements and interests. &lt;br /&gt;
&lt;br /&gt;
===Acceptance testing===&lt;br /&gt;
&lt;br /&gt;
The major purpose of Acceptance Testing is to validate or confirm that the system meets the  business requirements and gives an assurance before it is delivered to the end user. This phase is for testing the software in the real world by the end user to determine whether to accept the system or not.&lt;br /&gt;
&lt;br /&gt;
===Release testing===&lt;br /&gt;
&lt;br /&gt;
This testing phase answers important questions such as&lt;br /&gt;
&lt;br /&gt;
*Is the software suitable for the end user?&lt;br /&gt;
&lt;br /&gt;
*Has the compatibility with other systems been ensured?&lt;br /&gt;
&lt;br /&gt;
*Is the performance of the software optimized?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Advantages===&lt;br /&gt;
&lt;br /&gt;
*Early acceptance criteria is the key advantage, they are performed against a specification of requirements.&lt;br /&gt;
&lt;br /&gt;
*60 to 70 percent of all faults are in the system before the component construction and test stages start, which is taken care of. &lt;br /&gt;
&lt;br /&gt;
*At an early stage we can feed back to catch a fault before it is built into the system.&lt;br /&gt;
&lt;br /&gt;
*Specifies test requirements and expected results prior to performing the actual tests.&lt;br /&gt;
&lt;br /&gt;
*Defines who is responsible for performing the testing and provides a focus for defining the testing that takes place at each stage. &lt;br /&gt;
&lt;br /&gt;
===Disadvantages===&lt;br /&gt;
&lt;br /&gt;
*Too simple to reflect the development process.&lt;br /&gt;
&lt;br /&gt;
*Leads project managers to a false sense of security.&lt;br /&gt;
&lt;br /&gt;
*Inflexible and no ability to respond to change.&lt;br /&gt;
&lt;br /&gt;
*Produces inefficient testing methodologies&lt;br /&gt;
&lt;br /&gt;
*The placing of contracts for services is not regulated.&lt;br /&gt;
&lt;br /&gt;
*The organization and execution of operation, maintenance, repair and disposal of the system are not covered by the V-Model. &lt;br /&gt;
&lt;br /&gt;
*The V-Model addresses software development within a project rather than a whole organization.&lt;br /&gt;
&lt;br /&gt;
===Conclusion===&lt;br /&gt;
&lt;br /&gt;
Testing in the development process is critical. The earlier a fault is found, the cheaper it is to fix. The V model extends testing to the beginning of the lifecycle. The explicit recognition of testing in the V model makes it very useful in planning and executing information system development. The V-Model has evolved over time and supports flexibility and agility throughout the development process. Static testing techniques, such as inspections and walkthroughs, can be used to find faults in the functional specification, as well as defining test cases that are subsequently executed in system testing.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
http://www.softwaretestingclass.com/v-model/&lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/V-Model_(software_development)&lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/V-Model&lt;br /&gt;
&lt;br /&gt;
http://www.careerride.com/testing-v-model.aspx&lt;br /&gt;
&lt;br /&gt;
http://www.softwaretestingmentor.com/sdlc/vmodel.php&lt;br /&gt;
&lt;br /&gt;
http://www.bucanac.com/documents/The_V-Model.pdf&lt;br /&gt;
&lt;br /&gt;
http://www.compensationanalytics.com/_resources/vtestingmodel.pdf&lt;br /&gt;
&lt;br /&gt;
http://www.google.co.in/search?q=v+model&amp;amp;hl=en&amp;amp;biw=1241&amp;amp;bih=606&amp;amp;prmd=imvnsb&amp;amp;tbm=isch&amp;amp;tbo=u&amp;amp;source=univ&amp;amp;sa=X&amp;amp;ei=XVd8UICgNYem9gSa4oCYDA&amp;amp;sqi=2&amp;amp;ved=0CC8QsAQ&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
&lt;br /&gt;
*Dual Vee Model - http://en.wikipedia.org/wiki/Dual_Vee_Model&lt;br /&gt;
&lt;br /&gt;
*System Development Lifecycle - http://en.wikipedia.org/wiki/Systems_Development_Life_Cycle&lt;br /&gt;
&lt;br /&gt;
*Product Lifecycle Management - http://en.wikipedia.org/wiki/Product_lifecycle_management&lt;br /&gt;
&lt;br /&gt;
*Portal: Software Testing - http://en.wikipedia.org/wiki/Portal:Software_Testing&lt;br /&gt;
&lt;br /&gt;
*IBM RUP - http://en.wikipedia.org/wiki/RUP&lt;br /&gt;
&lt;br /&gt;
*Systems Architecture - http://en.wikipedia.org/wiki/Systems_architecture&lt;br /&gt;
&lt;br /&gt;
*System Analysis - http://en.wikipedia.org/wiki/Systems_analysis&lt;br /&gt;
&lt;br /&gt;
*System Design - http://en.wikipedia.org/wiki/Systems_design&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w4_sa&amp;diff=68167</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w4 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w4_sa&amp;diff=68167"/>
		<updated>2012-10-25T11:08:12Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''V - Model'''&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
&lt;br /&gt;
The V-model also called as Verification and Validation model is a software development process which simplifies the understanding of the complexity associated with the development of a system,  and is an extension to the waterfall model. Rather than proceeding linearly downwards, after the coding phase, the process steps are bent upwards to form a V shape. This creates an association between the phases in the development and the testing cycle.&lt;br /&gt;
&lt;br /&gt;
In the diagram, the left arm corresponds to the development phases in the traditional waterfall model and the right to the test phases. Each development activity carried out by the development team has its corresponding validation activity done by the testing team.&lt;br /&gt;
&lt;br /&gt;
=='''From Waterfall to V-Model'''==&lt;br /&gt;
&lt;br /&gt;
Every phase or stage in the waterfall model needs to be completed and signed off before the next phase can start, this rigidity affects the flexibility in iterating back and forth between the stages of development with the result being a poor quality system. The V-Model prevents this by explicitly connecting the development and testing stages.&lt;br /&gt;
&lt;br /&gt;
=='''Objectives'''==&lt;br /&gt;
&lt;br /&gt;
The V-Model facilitates the planning and realization of projects. The following are the objectives to be achieved during system development:&lt;br /&gt;
&lt;br /&gt;
*Minimizing Project Risks: Early recognition of planning deviations and risks improves process management, thus reducing risks.&lt;br /&gt;
&lt;br /&gt;
*Improving Quality: Defined interim results can be checked at an early stage. Uniform product contents will improve readability, understandability and verifiability.&lt;br /&gt;
&lt;br /&gt;
*Reduction of Total Cost: The results obtained should be uniform and easily retraced. This reduces the dependency on the supplier and the effort for subsequent activities.&lt;br /&gt;
&lt;br /&gt;
*Effective Communication between all Stakeholders: The miscommunication between user, supplier and developer is reduced.&lt;br /&gt;
&lt;br /&gt;
=='''Verification phase'''==&lt;br /&gt;
&lt;br /&gt;
Verification ensures that, the software is being built correctly. The ISTQB defines Verification as: “Confirmation by examination and through provision of objective evidence that specified requirements have been fulfilled.“&lt;br /&gt;
&lt;br /&gt;
The first part of the definition is the same as for Validation, but the second part is the key. This states that “specified requirements have been fulfilled“. The V-model diagram arrows shows that each produced product is checked against the products or documents that were used to drive the development. This ensures that all aspects have been met. A key problem is ensuring that the user requirements are adequately verified against the customer needs. The Business Case is only likely to contain high level functionality, and not the detail about processes that are essential for determining what is required.&lt;br /&gt;
&lt;br /&gt;
=='''Requirements Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Requirements analysis encompasses those tasks that determine the conditions specified by the stakeholders for the product. Its activities are concerned with eliciting, analyzing, documenting, validating and managing system requirements. The requirements have to be documentable, actionable, measurable, testable, traceable, related to the business needs and should include details sufficient for system design.&lt;br /&gt;
&lt;br /&gt;
Requirements analysis includes three types of activities:&lt;br /&gt;
&lt;br /&gt;
*Eliciting requirements: Identifying the various types of requirements from various sources i.e. project and business process documentation along with stakeholder interviews.&lt;br /&gt;
&lt;br /&gt;
*Analyzing requirements: Determining whether the specified requirements are clear, complete and consistent.&lt;br /&gt;
&lt;br /&gt;
*Recording requirements: Requirements can be documented in normal language documents, use cases, user stories, or system specifications.&lt;br /&gt;
&lt;br /&gt;
Requirements analysis is a long process during which many changes can occur over that time period. Technology changes, business requirements changes with many other things, so it is important that the stakeholders are in constant touch with the developers to ensure that they understand the new improved system. It is the responsibility of the analyst to gather information from the customer. System prototypes should be developed to demonstrate a working model to the stakeholders. Analysts employ a combination of various methods to establish the exact requirements of the stakeholders, so that the system developed meets the customer’s needs. The information regarding the product requirements can be classified as: Customer, Architectural, Structural, Behavioral, Functional, Non-functional, Performance, Design, Derived, and Allocated Requirements.&lt;br /&gt;
&lt;br /&gt;
=='''System Design'''==&lt;br /&gt;
&lt;br /&gt;
This design process defines the architecture, components, modules, interfaces, and data required by a system to meet the mentioned system requirements. We can say that design is an act of taking the marketing information and creating the products to be manufactured. So, systems design is the process of defining and developing systems specified by the user.&lt;br /&gt;
&lt;br /&gt;
*Softwares that run on generic platforms have enhanced software engineering. &lt;br /&gt;
&lt;br /&gt;
*Object-oriented analysis and design methods are widely used for systems design.&lt;br /&gt;
&lt;br /&gt;
*UML is used for modeling software systems and designing high non-software systems and organizations.&lt;br /&gt;
&lt;br /&gt;
=='''Architecture Design'''==&lt;br /&gt;
&lt;br /&gt;
The design of computer and software architecture can be referred to as high-level design. The architecture selected should realize the list of modules, brief functionality of each module, the interface relationships between the modules, dependencies, database tables, architecture diagrams, technology details etc.&lt;br /&gt;
&lt;br /&gt;
Integration testing design is carried out in this phase.&lt;br /&gt;
&lt;br /&gt;
=='''Module Design'''==&lt;br /&gt;
&lt;br /&gt;
The module design phase is a low-level design. The designed system is broken up into smaller units and each of them is explained to the programmer. The low level design document will contain a detailed functional logic of the module:&lt;br /&gt;
&lt;br /&gt;
*database tables, with all elements, including their type and size&lt;br /&gt;
&lt;br /&gt;
*all interface details with complete API references&lt;br /&gt;
&lt;br /&gt;
*all dependency issues&lt;br /&gt;
&lt;br /&gt;
*error message listings&lt;br /&gt;
&lt;br /&gt;
*complete input and outputs for a module.&lt;br /&gt;
&lt;br /&gt;
Unit test design is developed in this stage.&lt;br /&gt;
&lt;br /&gt;
=='''Coding'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Validation phase'''==&lt;br /&gt;
===Importance of Early Testing===&lt;br /&gt;
&lt;br /&gt;
Studies show that catching a fault early in the development stages before the system is released is more cost effective and it takes less resources to fix the system when compared to fixing it after its release. We must also take into account the reputation of the organisation, the cost associated with missing functionality, so in fact the true cost for fixing the system is much higher.&lt;br /&gt;
&lt;br /&gt;
In the waterfall model errors were found very late in the cycle because testing began at the end of the project. In the V-Model testing begins as early as possible. Prior to testing, the testing team works on various activities in parallel to the development activity which helps to get the test deliverable on time which includes creation of test cases, preparation of test strategies, test planning and test scripting.&lt;br /&gt;
&lt;br /&gt;
===Testing Types Matched to Development Stages===&lt;br /&gt;
&lt;br /&gt;
The first noticeable point of the V-Model is that the Test stage of the Waterfall model is bent upwards to make it a “V”. This stage is now separated out into the various types of testing. So this first step visually points out that there is more than one type of testing to consider for system development and like the development steps they build on one another, and have different objectives. The next important part of the “V” is to match each type of testing against the development stage it matches e.g. we have Component Design matched against Component Testing. This means that the testing stage does not start when the Construct Component stage has ended. Instead when each development stage starts, the testing for that stage also starts.&lt;br /&gt;
&lt;br /&gt;
===Unit testing===&lt;br /&gt;
&lt;br /&gt;
Unit testing, tests the low level design i.e. units. A unit is a basic module of the application on which testing is carried out, it may be an individual function or a procedure. These tests are created by the developers (white box testing) to verify the internal logic code. Input data are passed to the unit to test every case of execution.&lt;br /&gt;
&lt;br /&gt;
===Integration testing===&lt;br /&gt;
&lt;br /&gt;
Integration testing tests high level design i.e. components and their interfaces. In Integration testing the basic units will be tested together to check the interaction between them and finds errors in the interfaces. This is generally a black box testing method. Integration testing is  performed by program team leaders.&lt;br /&gt;
&lt;br /&gt;
===System testing===&lt;br /&gt;
&lt;br /&gt;
Once the entire system has been developed, it then has to be tested against the system specifications to validate if it provides the required features. In short, system testing is about checking the system as a whole. System testing involves a number of special types of tests to see if all the functional and nonfunctional requirements have been met. System testing is performed by system testers.&lt;br /&gt;
Reasons for carrying out a system test even after the unit and integration test&lt;br /&gt;
&lt;br /&gt;
*The previous testings were done against the system specifications. The system test, looks at the system from the perspective of the future user.&lt;br /&gt;
&lt;br /&gt;
*Many of the system functions and characteristics results from the interaction of  the modules, and can be tested only at this level. &lt;br /&gt;
&lt;br /&gt;
*Also, keeping in mind that the customer and the end user can be two different groups of people having their own requirements and interests. &lt;br /&gt;
&lt;br /&gt;
===Acceptance testing===&lt;br /&gt;
&lt;br /&gt;
The major purpose of Acceptance Testing is to validate or confirm that the system meets the  business requirements and gives an assurance before it is delivered to the end user. This phase is for testing the software in the real world by the end user to determine whether to accept the system or not.&lt;br /&gt;
&lt;br /&gt;
===Release testing===&lt;br /&gt;
&lt;br /&gt;
This testing phase answers important questions such as&lt;br /&gt;
&lt;br /&gt;
*Is the software suitable for the end user?&lt;br /&gt;
&lt;br /&gt;
*Has the compatibility with other systems been ensured?&lt;br /&gt;
&lt;br /&gt;
*Is the performance of the software optimized?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Advantages===&lt;br /&gt;
&lt;br /&gt;
*Early acceptance criteria is the key advantage, they are performed against a specification of requirements.&lt;br /&gt;
&lt;br /&gt;
*60 to 70 percent of all faults are in the system before the component construction and test stages start, which is taken care of. &lt;br /&gt;
&lt;br /&gt;
*At an early stage we can feed back to catch a fault before it is built into the system.&lt;br /&gt;
&lt;br /&gt;
*Specifies test requirements and expected results prior to performing the actual tests.&lt;br /&gt;
&lt;br /&gt;
*Defines who is responsible for performing the testing and provides a focus for defining the testing that takes place at each stage. &lt;br /&gt;
&lt;br /&gt;
===Disadvantages===&lt;br /&gt;
&lt;br /&gt;
*Too simple to reflect the development process.&lt;br /&gt;
&lt;br /&gt;
*Leads project managers to a false sense of security.&lt;br /&gt;
&lt;br /&gt;
*Inflexible and no ability to respond to change.&lt;br /&gt;
&lt;br /&gt;
*Produces inefficient testing methodologies&lt;br /&gt;
&lt;br /&gt;
*The placing of contracts for services is not regulated.&lt;br /&gt;
&lt;br /&gt;
*The organization and execution of operation, maintenance, repair and disposal of the system are not covered by the V-Model. &lt;br /&gt;
&lt;br /&gt;
*The V-Model addresses software development within a project rather than a whole organization.&lt;br /&gt;
&lt;br /&gt;
===Conclusion===&lt;br /&gt;
&lt;br /&gt;
Testing in the development process is critical. The earlier a fault is found, the cheaper it is to fix. The V model extends testing to the beginning of the lifecycle. The explicit recognition of testing in the V model makes it very useful in planning and executing information system development. The V-Model has evolved over time and supports flexibility and agility throughout the development process. Static testing techniques, such as inspections and walkthroughs, can be used to find faults in the functional specification, as well as defining test cases that are subsequently executed in system testing.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
http://www.softwaretestingclass.com/v-model/&lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/V-Model_(software_development)&lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/V-Model&lt;br /&gt;
&lt;br /&gt;
http://www.careerride.com/testing-v-model.aspx&lt;br /&gt;
&lt;br /&gt;
http://www.softwaretestingmentor.com/sdlc/vmodel.php&lt;br /&gt;
&lt;br /&gt;
http://www.bucanac.com/documents/The_V-Model.pdf&lt;br /&gt;
&lt;br /&gt;
http://www.compensationanalytics.com/_resources/vtestingmodel.pdf&lt;br /&gt;
&lt;br /&gt;
http://www.google.co.in/search?q=v+model&amp;amp;hl=en&amp;amp;biw=1241&amp;amp;bih=606&amp;amp;prmd=imvnsb&amp;amp;tbm=isch&amp;amp;tbo=u&amp;amp;source=univ&amp;amp;sa=X&amp;amp;ei=XVd8UICgNYem9gSa4oCYDA&amp;amp;sqi=2&amp;amp;ved=0CC8QsAQ&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
&lt;br /&gt;
*Dual Vee Model - http://en.wikipedia.org/wiki/Dual_Vee_Model&lt;br /&gt;
&lt;br /&gt;
*System Development Lifecycle - http://en.wikipedia.org/wiki/Systems_Development_Life_Cycle&lt;br /&gt;
&lt;br /&gt;
*Product Lifecycle Management - http://en.wikipedia.org/wiki/Product_lifecycle_management&lt;br /&gt;
&lt;br /&gt;
*Portal: Software Testing - http://en.wikipedia.org/wiki/Portal:Software_Testing&lt;br /&gt;
&lt;br /&gt;
*IBM RUP - http://en.wikipedia.org/wiki/RUP&lt;br /&gt;
&lt;br /&gt;
*Systems Architecture - http://en.wikipedia.org/wiki/Systems_architecture&lt;br /&gt;
&lt;br /&gt;
*System Analysis - http://en.wikipedia.org/wiki/Systems_analysis&lt;br /&gt;
&lt;br /&gt;
*System Design - http://en.wikipedia.org/wiki/Systems_design&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w4_sa&amp;diff=68166</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w4 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w4_sa&amp;diff=68166"/>
		<updated>2012-10-25T11:07:10Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* Objectives */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''V - Model'''&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
&lt;br /&gt;
The V-model also called as Verification and Validation model is a software development process which simplifies the understanding of the complexity associated with the development of a system,  and is an extension to the waterfall model. Rather than proceeding linearly downwards, after the coding phase, the process steps are bent upwards to form a V shape. This creates an association between the phases in the development and the testing cycle.&lt;br /&gt;
&lt;br /&gt;
In the diagram, the left arm corresponds to the development phases in the traditional waterfall model and the right to the test phases. Each development activity carried out by the development team has its corresponding validation activity done by the testing team.&lt;br /&gt;
&lt;br /&gt;
=='''From Waterfall to V-Model'''==&lt;br /&gt;
&lt;br /&gt;
Every phase or stage in the waterfall model needs to be completed and signed off before the next phase can start, this rigidity affects the flexibility in iterating back and forth between the stages of development with the result being a poor quality system. The V-Model prevents this by explicitly connecting the development and testing stages.&lt;br /&gt;
&lt;br /&gt;
=='''Objectives'''==&lt;br /&gt;
&lt;br /&gt;
The V-Model facilitates the planning and realization of projects. The following are the objectives to be achieved during system development:&lt;br /&gt;
&lt;br /&gt;
*Minimizing Project Risks: Early recognition of planning deviations and risks improves process management, thus reducing risks.&lt;br /&gt;
&lt;br /&gt;
*Improving Quality: Defined interim results can be checked at an early stage. Uniform product contents will improve readability, understandability and verifiability.&lt;br /&gt;
&lt;br /&gt;
*Reduction of Total Cost: The results obtained should be uniform and easily retraced. This reduces the dependency on the supplier and the effort for subsequent activities.&lt;br /&gt;
&lt;br /&gt;
*Effective Communication between all Stakeholders: The miscommunication between user, supplier and developer is reduced.&lt;br /&gt;
&lt;br /&gt;
=='''Verification phase'''==&lt;br /&gt;
&lt;br /&gt;
Verification ensures that, the software is being built correctly. The ISTQB defines Verification as: “Confirmation by examination and through provision of objective evidence that specified requirements have been fulfilled.“&lt;br /&gt;
&lt;br /&gt;
The first part of the definition is the same as for Validation, but the second part is the key. This states that “specified requirements have been fulfilled“. The V-model diagram arrows shows that each produced product is checked against the products or documents that were used to drive the development. This ensures that all aspects have been met. A key problem is ensuring that the user requirements are adequately verified against the customer needs. The Business Case is only likely to contain high level functionality, and not the detail about processes that are essential for determining what is required.&lt;br /&gt;
&lt;br /&gt;
=='''Requirements Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Requirements analysis encompasses those tasks that determine the conditions specified by the stakeholders for the product. Its activities are concerned with eliciting, analyzing, documenting, validating and managing system requirements. The requirements have to be documentable, actionable, measurable, testable, traceable, related to the business needs and should include details sufficient for system design.&lt;br /&gt;
&lt;br /&gt;
Requirements analysis includes three types of activities:&lt;br /&gt;
&lt;br /&gt;
*Eliciting requirements: Identifying the various types of requirements from various sources i.e. project and business process documentation along with stakeholder interviews.&lt;br /&gt;
&lt;br /&gt;
*Analyzing requirements: Determining whether the specified requirements are clear, complete and consistent.&lt;br /&gt;
&lt;br /&gt;
*Recording requirements: Requirements can be documented in normal language documents, use cases, user stories, or system specifications.&lt;br /&gt;
&lt;br /&gt;
Requirements analysis is a long process during which many changes can occur over that time period. Technology changes, business requirements changes with many other things, so it is important that the stakeholders are in constant touch with the developers to ensure that they understand the new improved system. It is the responsibility of the analyst to gather information from the customer. System prototypes should be developed to demonstrate a working model to the stakeholders. Analysts employ a combination of various methods to establish the exact requirements of the stakeholders, so that the system developed meets the customer’s needs. The information regarding the product requirements can be classified as: Customer, Architectural, Structural, Behavioral, Functional, Non-functional, Performance, Design, Derived, and Allocated Requirements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''System Design'''==&lt;br /&gt;
&lt;br /&gt;
This design process defines the architecture, components, modules, interfaces, and data required by a system to meet the mentioned system requirements. We can say that design is an act of taking the marketing information and creating the products to be manufactured. So, systems design is the process of defining and developing systems specified by the user.&lt;br /&gt;
&lt;br /&gt;
*Softwares that run on generic platforms have enhanced software engineering. &lt;br /&gt;
&lt;br /&gt;
*Object-oriented analysis and design methods are widely used for systems design.&lt;br /&gt;
&lt;br /&gt;
*UML is used for modeling software systems and designing high non-software systems and organizations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Architecture Design'''==&lt;br /&gt;
&lt;br /&gt;
The design of computer and software architecture can be referred to as high-level design. The architecture selected should realize the list of modules, brief functionality of each module, the interface relationships between the modules, dependencies, database tables, architecture diagrams, technology details etc.&lt;br /&gt;
&lt;br /&gt;
Integration testing design is carried out in this phase.&lt;br /&gt;
&lt;br /&gt;
=='''Module Design'''==&lt;br /&gt;
&lt;br /&gt;
The module design phase is a low-level design. The designed system is broken up into smaller units and each of them is explained to the programmer. The low level design document will contain a detailed functional logic of the module:&lt;br /&gt;
&lt;br /&gt;
*database tables, with all elements, including their type and size&lt;br /&gt;
&lt;br /&gt;
*all interface details with complete API references&lt;br /&gt;
&lt;br /&gt;
*all dependency issues&lt;br /&gt;
&lt;br /&gt;
*error message listings&lt;br /&gt;
&lt;br /&gt;
*complete input and outputs for a module.&lt;br /&gt;
&lt;br /&gt;
Unit test design is developed in this stage.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Coding'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Validation phase'''==&lt;br /&gt;
===Importance of Early Testing===&lt;br /&gt;
&lt;br /&gt;
Studies show that catching a fault early in the development stages before the system is released is more cost effective and it takes less resources to fix the system when compared to fixing it after its release. We must also take into account the reputation of the organisation, the cost associated with missing functionality, so in fact the true cost for fixing the system is much higher.&lt;br /&gt;
&lt;br /&gt;
In the waterfall model errors were found very late in the cycle because testing began at the end of the project. In the V-Model testing begins as early as possible. Prior to testing, the testing team works on various activities in parallel to the development activity which helps to get the test deliverable on time which includes creation of test cases, preparation of test strategies, test planning and test scripting.&lt;br /&gt;
&lt;br /&gt;
===Testing Types Matched to Development Stages===&lt;br /&gt;
&lt;br /&gt;
The first noticeable point of the V-Model is that the Test stage of the Waterfall model is bent upwards to make it a “V”. This stage is now separated out into the various types of testing. So this first step visually points out that there is more than one type of testing to consider for system development and like the development steps they build on one another, and have different objectives. The next important part of the “V” is to match each type of testing against the development stage it matches e.g. we have Component Design matched against Component Testing. This means that the testing stage does not start when the Construct Component stage has ended. Instead when each development stage starts, the testing for that stage also starts.&lt;br /&gt;
&lt;br /&gt;
===Unit testing===&lt;br /&gt;
&lt;br /&gt;
Unit testing, tests the low level design i.e. units. A unit is a basic module of the application on which testing is carried out, it may be an individual function or a procedure. These tests are created by the developers (white box testing) to verify the internal logic code. Input data are passed to the unit to test every case of execution.&lt;br /&gt;
&lt;br /&gt;
===Integration testing===&lt;br /&gt;
&lt;br /&gt;
Integration testing tests high level design i.e. components and their interfaces. In Integration testing the basic units will be tested together to check the interaction between them and finds errors in the interfaces. This is generally a black box testing method. Integration testing is  performed by program team leaders.&lt;br /&gt;
&lt;br /&gt;
===System testing===&lt;br /&gt;
&lt;br /&gt;
Once the entire system has been developed, it then has to be tested against the system specifications to validate if it provides the required features. In short, system testing is about checking the system as a whole. System testing involves a number of special types of tests to see if all the functional and nonfunctional requirements have been met. System testing is performed by system testers.&lt;br /&gt;
Reasons for carrying out a system test even after the unit and integration test&lt;br /&gt;
&lt;br /&gt;
*The previous testings were done against the system specifications. The system test, looks at the system from the perspective of the future user.&lt;br /&gt;
&lt;br /&gt;
*Many of the system functions and characteristics results from the interaction of  the modules, and can be tested only at this level. &lt;br /&gt;
&lt;br /&gt;
*Also, keeping in mind that the customer and the end user can be two different groups of people having their own requirements and interests. &lt;br /&gt;
&lt;br /&gt;
===Acceptance testing===&lt;br /&gt;
&lt;br /&gt;
The major purpose of Acceptance Testing is to validate or confirm that the system meets the  business requirements and gives an assurance before it is delivered to the end user. This phase is for testing the software in the real world by the end user to determine whether to accept the system or not.&lt;br /&gt;
&lt;br /&gt;
===Release testing===&lt;br /&gt;
&lt;br /&gt;
This testing phase answers important questions such as&lt;br /&gt;
&lt;br /&gt;
*Is the software suitable for the end user?&lt;br /&gt;
&lt;br /&gt;
*Has the compatibility with other systems been ensured?&lt;br /&gt;
&lt;br /&gt;
*Is the performance of the software optimized?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Advantages===&lt;br /&gt;
&lt;br /&gt;
*Early acceptance criteria is the key advantage, they are performed against a specification of requirements.&lt;br /&gt;
&lt;br /&gt;
*60 to 70 percent of all faults are in the system before the component construction and test stages start, which is taken care of. &lt;br /&gt;
&lt;br /&gt;
*At an early stage we can feed back to catch a fault before it is built into the system.&lt;br /&gt;
&lt;br /&gt;
*Specifies test requirements and expected results prior to performing the actual tests.&lt;br /&gt;
&lt;br /&gt;
*Defines who is responsible for performing the testing and provides a focus for defining the testing that takes place at each stage. &lt;br /&gt;
&lt;br /&gt;
===Disadvantages===&lt;br /&gt;
&lt;br /&gt;
*Too simple to reflect the development process.&lt;br /&gt;
&lt;br /&gt;
*Leads project managers to a false sense of security.&lt;br /&gt;
&lt;br /&gt;
*Inflexible and no ability to respond to change.&lt;br /&gt;
&lt;br /&gt;
*Produces inefficient testing methodologies&lt;br /&gt;
&lt;br /&gt;
*The placing of contracts for services is not regulated.&lt;br /&gt;
&lt;br /&gt;
*The organization and execution of operation, maintenance, repair and disposal of the system are not covered by the V-Model. &lt;br /&gt;
&lt;br /&gt;
*The V-Model addresses software development within a project rather than a whole organization.&lt;br /&gt;
&lt;br /&gt;
===Conclusion===&lt;br /&gt;
&lt;br /&gt;
Testing in the development process is critical. The earlier a fault is found, the cheaper it is to fix. The V model extends testing to the beginning of the lifecycle. The explicit recognition of testing in the V model makes it very useful in planning and executing information system development. The V-Model has evolved over time and supports flexibility and agility throughout the development process. Static testing techniques, such as inspections and walkthroughs, can be used to find faults in the functional specification, as well as defining test cases that are subsequently executed in system testing.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
http://www.softwaretestingclass.com/v-model/&lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/V-Model_(software_development)&lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/V-Model&lt;br /&gt;
&lt;br /&gt;
http://www.careerride.com/testing-v-model.aspx&lt;br /&gt;
&lt;br /&gt;
http://www.softwaretestingmentor.com/sdlc/vmodel.php&lt;br /&gt;
&lt;br /&gt;
http://www.bucanac.com/documents/The_V-Model.pdf&lt;br /&gt;
&lt;br /&gt;
http://www.compensationanalytics.com/_resources/vtestingmodel.pdf&lt;br /&gt;
&lt;br /&gt;
http://www.google.co.in/search?q=v+model&amp;amp;hl=en&amp;amp;biw=1241&amp;amp;bih=606&amp;amp;prmd=imvnsb&amp;amp;tbm=isch&amp;amp;tbo=u&amp;amp;source=univ&amp;amp;sa=X&amp;amp;ei=XVd8UICgNYem9gSa4oCYDA&amp;amp;sqi=2&amp;amp;ved=0CC8QsAQ&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
&lt;br /&gt;
*Dual Vee Model - http://en.wikipedia.org/wiki/Dual_Vee_Model&lt;br /&gt;
&lt;br /&gt;
*System Development Lifecycle - http://en.wikipedia.org/wiki/Systems_Development_Life_Cycle&lt;br /&gt;
&lt;br /&gt;
*Product Lifecycle Management - http://en.wikipedia.org/wiki/Product_lifecycle_management&lt;br /&gt;
&lt;br /&gt;
*Portal: Software Testing - http://en.wikipedia.org/wiki/Portal:Software_Testing&lt;br /&gt;
&lt;br /&gt;
*IBM RUP - http://en.wikipedia.org/wiki/RUP&lt;br /&gt;
&lt;br /&gt;
*Systems Architecture - http://en.wikipedia.org/wiki/Systems_architecture&lt;br /&gt;
&lt;br /&gt;
*System Analysis - http://en.wikipedia.org/wiki/Systems_analysis&lt;br /&gt;
&lt;br /&gt;
*System Design - http://en.wikipedia.org/wiki/Systems_design&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w4_sa&amp;diff=68165</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w4 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w4_sa&amp;diff=68165"/>
		<updated>2012-10-25T11:06:00Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* Further Suggested Reading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''V - Model'''&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
&lt;br /&gt;
The V-model also called as Verification and Validation model is a software development process which simplifies the understanding of the complexity associated with the development of a system,  and is an extension to the waterfall model. Rather than proceeding linearly downwards, after the coding phase, the process steps are bent upwards to form a V shape. This creates an association between the phases in the development and the testing cycle.&lt;br /&gt;
&lt;br /&gt;
In the diagram, the left arm corresponds to the development phases in the traditional waterfall model and the right to the test phases. Each development activity carried out by the development team has its corresponding validation activity done by the testing team.&lt;br /&gt;
&lt;br /&gt;
=='''From Waterfall to V-Model'''==&lt;br /&gt;
&lt;br /&gt;
Every phase or stage in the waterfall model needs to be completed and signed off before the next phase can start, this rigidity affects the flexibility in iterating back and forth between the stages of development with the result being a poor quality system. The V-Model prevents this by explicitly connecting the development and testing stages.&lt;br /&gt;
&lt;br /&gt;
=='''Objectives'''==&lt;br /&gt;
&lt;br /&gt;
The V-Model facilitates the planning and realization of projects. The following are the objectives to be achieved during system development:&lt;br /&gt;
&lt;br /&gt;
*Minimizing Project Risks: Early recognition of planning deviations and risks improves process management, thus reducing risks.&lt;br /&gt;
&lt;br /&gt;
*Improving Quality: Defined interim results can be checked at an early stage. Uniform product contents will improve readability, understandability and verifiability.&lt;br /&gt;
&lt;br /&gt;
*Reduction of Total Cost: The results obtained should be uniform and easily retraced. This reduces the dependency on the supplier and the effort for subsequent activities.&lt;br /&gt;
&lt;br /&gt;
*Effective Communication between all Stakeholders: The miscommunication between user, supplier and developer is reduced.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
�&lt;br /&gt;
=='''Verification phase'''==&lt;br /&gt;
&lt;br /&gt;
Verification ensures that, the software is being built correctly. The ISTQB defines Verification as: “Confirmation by examination and through provision of objective evidence that specified requirements have been fulfilled.“&lt;br /&gt;
&lt;br /&gt;
The first part of the definition is the same as for Validation, but the second part is the key. This states that “specified requirements have been fulfilled“. The V-model diagram arrows shows that each produced product is checked against the products or documents that were used to drive the development. This ensures that all aspects have been met. A key problem is ensuring that the user requirements are adequately verified against the customer needs. The Business Case is only likely to contain high level functionality, and not the detail about processes that are essential for determining what is required.&lt;br /&gt;
&lt;br /&gt;
=='''Requirements Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Requirements analysis encompasses those tasks that determine the conditions specified by the stakeholders for the product. Its activities are concerned with eliciting, analyzing, documenting, validating and managing system requirements. The requirements have to be documentable, actionable, measurable, testable, traceable, related to the business needs and should include details sufficient for system design.&lt;br /&gt;
&lt;br /&gt;
Requirements analysis includes three types of activities:&lt;br /&gt;
&lt;br /&gt;
*Eliciting requirements: Identifying the various types of requirements from various sources i.e. project and business process documentation along with stakeholder interviews.&lt;br /&gt;
&lt;br /&gt;
*Analyzing requirements: Determining whether the specified requirements are clear, complete and consistent.&lt;br /&gt;
&lt;br /&gt;
*Recording requirements: Requirements can be documented in normal language documents, use cases, user stories, or system specifications.&lt;br /&gt;
&lt;br /&gt;
Requirements analysis is a long process during which many changes can occur over that time period. Technology changes, business requirements changes with many other things, so it is important that the stakeholders are in constant touch with the developers to ensure that they understand the new improved system. It is the responsibility of the analyst to gather information from the customer. System prototypes should be developed to demonstrate a working model to the stakeholders. Analysts employ a combination of various methods to establish the exact requirements of the stakeholders, so that the system developed meets the customer’s needs. The information regarding the product requirements can be classified as: Customer, Architectural, Structural, Behavioral, Functional, Non-functional, Performance, Design, Derived, and Allocated Requirements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''System Design'''==&lt;br /&gt;
&lt;br /&gt;
This design process defines the architecture, components, modules, interfaces, and data required by a system to meet the mentioned system requirements. We can say that design is an act of taking the marketing information and creating the products to be manufactured. So, systems design is the process of defining and developing systems specified by the user.&lt;br /&gt;
&lt;br /&gt;
*Softwares that run on generic platforms have enhanced software engineering. &lt;br /&gt;
&lt;br /&gt;
*Object-oriented analysis and design methods are widely used for systems design.&lt;br /&gt;
&lt;br /&gt;
*UML is used for modeling software systems and designing high non-software systems and organizations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Architecture Design'''==&lt;br /&gt;
&lt;br /&gt;
The design of computer and software architecture can be referred to as high-level design. The architecture selected should realize the list of modules, brief functionality of each module, the interface relationships between the modules, dependencies, database tables, architecture diagrams, technology details etc.&lt;br /&gt;
&lt;br /&gt;
Integration testing design is carried out in this phase.&lt;br /&gt;
&lt;br /&gt;
=='''Module Design'''==&lt;br /&gt;
&lt;br /&gt;
The module design phase is a low-level design. The designed system is broken up into smaller units and each of them is explained to the programmer. The low level design document will contain a detailed functional logic of the module:&lt;br /&gt;
&lt;br /&gt;
*database tables, with all elements, including their type and size&lt;br /&gt;
&lt;br /&gt;
*all interface details with complete API references&lt;br /&gt;
&lt;br /&gt;
*all dependency issues&lt;br /&gt;
&lt;br /&gt;
*error message listings&lt;br /&gt;
&lt;br /&gt;
*complete input and outputs for a module.&lt;br /&gt;
&lt;br /&gt;
Unit test design is developed in this stage.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Coding'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Validation phase'''==&lt;br /&gt;
===Importance of Early Testing===&lt;br /&gt;
&lt;br /&gt;
Studies show that catching a fault early in the development stages before the system is released is more cost effective and it takes less resources to fix the system when compared to fixing it after its release. We must also take into account the reputation of the organisation, the cost associated with missing functionality, so in fact the true cost for fixing the system is much higher.&lt;br /&gt;
&lt;br /&gt;
In the waterfall model errors were found very late in the cycle because testing began at the end of the project. In the V-Model testing begins as early as possible. Prior to testing, the testing team works on various activities in parallel to the development activity which helps to get the test deliverable on time which includes creation of test cases, preparation of test strategies, test planning and test scripting.&lt;br /&gt;
&lt;br /&gt;
===Testing Types Matched to Development Stages===&lt;br /&gt;
&lt;br /&gt;
The first noticeable point of the V-Model is that the Test stage of the Waterfall model is bent upwards to make it a “V”. This stage is now separated out into the various types of testing. So this first step visually points out that there is more than one type of testing to consider for system development and like the development steps they build on one another, and have different objectives. The next important part of the “V” is to match each type of testing against the development stage it matches e.g. we have Component Design matched against Component Testing. This means that the testing stage does not start when the Construct Component stage has ended. Instead when each development stage starts, the testing for that stage also starts.&lt;br /&gt;
&lt;br /&gt;
===Unit testing===&lt;br /&gt;
&lt;br /&gt;
Unit testing, tests the low level design i.e. units. A unit is a basic module of the application on which testing is carried out, it may be an individual function or a procedure. These tests are created by the developers (white box testing) to verify the internal logic code. Input data are passed to the unit to test every case of execution.&lt;br /&gt;
&lt;br /&gt;
===Integration testing===&lt;br /&gt;
&lt;br /&gt;
Integration testing tests high level design i.e. components and their interfaces. In Integration testing the basic units will be tested together to check the interaction between them and finds errors in the interfaces. This is generally a black box testing method. Integration testing is  performed by program team leaders.&lt;br /&gt;
&lt;br /&gt;
===System testing===&lt;br /&gt;
&lt;br /&gt;
Once the entire system has been developed, it then has to be tested against the system specifications to validate if it provides the required features. In short, system testing is about checking the system as a whole. System testing involves a number of special types of tests to see if all the functional and nonfunctional requirements have been met. System testing is performed by system testers.&lt;br /&gt;
Reasons for carrying out a system test even after the unit and integration test&lt;br /&gt;
&lt;br /&gt;
*The previous testings were done against the system specifications. The system test, looks at the system from the perspective of the future user.&lt;br /&gt;
&lt;br /&gt;
*Many of the system functions and characteristics results from the interaction of  the modules, and can be tested only at this level. &lt;br /&gt;
&lt;br /&gt;
*Also, keeping in mind that the customer and the end user can be two different groups of people having their own requirements and interests. &lt;br /&gt;
&lt;br /&gt;
===Acceptance testing===&lt;br /&gt;
&lt;br /&gt;
The major purpose of Acceptance Testing is to validate or confirm that the system meets the  business requirements and gives an assurance before it is delivered to the end user. This phase is for testing the software in the real world by the end user to determine whether to accept the system or not.&lt;br /&gt;
&lt;br /&gt;
===Release testing===&lt;br /&gt;
&lt;br /&gt;
This testing phase answers important questions such as&lt;br /&gt;
&lt;br /&gt;
*Is the software suitable for the end user?&lt;br /&gt;
&lt;br /&gt;
*Has the compatibility with other systems been ensured?&lt;br /&gt;
&lt;br /&gt;
*Is the performance of the software optimized?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Advantages===&lt;br /&gt;
&lt;br /&gt;
*Early acceptance criteria is the key advantage, they are performed against a specification of requirements.&lt;br /&gt;
&lt;br /&gt;
*60 to 70 percent of all faults are in the system before the component construction and test stages start, which is taken care of. &lt;br /&gt;
&lt;br /&gt;
*At an early stage we can feed back to catch a fault before it is built into the system.&lt;br /&gt;
&lt;br /&gt;
*Specifies test requirements and expected results prior to performing the actual tests.&lt;br /&gt;
&lt;br /&gt;
*Defines who is responsible for performing the testing and provides a focus for defining the testing that takes place at each stage. &lt;br /&gt;
&lt;br /&gt;
===Disadvantages===&lt;br /&gt;
&lt;br /&gt;
*Too simple to reflect the development process.&lt;br /&gt;
&lt;br /&gt;
*Leads project managers to a false sense of security.&lt;br /&gt;
&lt;br /&gt;
*Inflexible and no ability to respond to change.&lt;br /&gt;
&lt;br /&gt;
*Produces inefficient testing methodologies&lt;br /&gt;
&lt;br /&gt;
*The placing of contracts for services is not regulated.&lt;br /&gt;
&lt;br /&gt;
*The organization and execution of operation, maintenance, repair and disposal of the system are not covered by the V-Model. &lt;br /&gt;
&lt;br /&gt;
*The V-Model addresses software development within a project rather than a whole organization.&lt;br /&gt;
&lt;br /&gt;
===Conclusion===&lt;br /&gt;
&lt;br /&gt;
Testing in the development process is critical. The earlier a fault is found, the cheaper it is to fix. The V model extends testing to the beginning of the lifecycle. The explicit recognition of testing in the V model makes it very useful in planning and executing information system development. The V-Model has evolved over time and supports flexibility and agility throughout the development process. Static testing techniques, such as inspections and walkthroughs, can be used to find faults in the functional specification, as well as defining test cases that are subsequently executed in system testing.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
http://www.softwaretestingclass.com/v-model/&lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/V-Model_(software_development)&lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/V-Model&lt;br /&gt;
&lt;br /&gt;
http://www.careerride.com/testing-v-model.aspx&lt;br /&gt;
&lt;br /&gt;
http://www.softwaretestingmentor.com/sdlc/vmodel.php&lt;br /&gt;
&lt;br /&gt;
http://www.bucanac.com/documents/The_V-Model.pdf&lt;br /&gt;
&lt;br /&gt;
http://www.compensationanalytics.com/_resources/vtestingmodel.pdf&lt;br /&gt;
&lt;br /&gt;
http://www.google.co.in/search?q=v+model&amp;amp;hl=en&amp;amp;biw=1241&amp;amp;bih=606&amp;amp;prmd=imvnsb&amp;amp;tbm=isch&amp;amp;tbo=u&amp;amp;source=univ&amp;amp;sa=X&amp;amp;ei=XVd8UICgNYem9gSa4oCYDA&amp;amp;sqi=2&amp;amp;ved=0CC8QsAQ&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
&lt;br /&gt;
*Dual Vee Model - http://en.wikipedia.org/wiki/Dual_Vee_Model&lt;br /&gt;
&lt;br /&gt;
*System Development Lifecycle - http://en.wikipedia.org/wiki/Systems_Development_Life_Cycle&lt;br /&gt;
&lt;br /&gt;
*Product Lifecycle Management - http://en.wikipedia.org/wiki/Product_lifecycle_management&lt;br /&gt;
&lt;br /&gt;
*Portal: Software Testing - http://en.wikipedia.org/wiki/Portal:Software_Testing&lt;br /&gt;
&lt;br /&gt;
*IBM RUP - http://en.wikipedia.org/wiki/RUP&lt;br /&gt;
&lt;br /&gt;
*Systems Architecture - http://en.wikipedia.org/wiki/Systems_architecture&lt;br /&gt;
&lt;br /&gt;
*System Analysis - http://en.wikipedia.org/wiki/Systems_analysis&lt;br /&gt;
&lt;br /&gt;
*System Design - http://en.wikipedia.org/wiki/Systems_design&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w4_sa&amp;diff=68164</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w4 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w4_sa&amp;diff=68164"/>
		<updated>2012-10-25T11:02:18Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''V - Model'''&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
&lt;br /&gt;
The V-model also called as Verification and Validation model is a software development process which simplifies the understanding of the complexity associated with the development of a system,  and is an extension to the waterfall model. Rather than proceeding linearly downwards, after the coding phase, the process steps are bent upwards to form a V shape. This creates an association between the phases in the development and the testing cycle.&lt;br /&gt;
&lt;br /&gt;
In the diagram, the left arm corresponds to the development phases in the traditional waterfall model and the right to the test phases. Each development activity carried out by the development team has its corresponding validation activity done by the testing team.&lt;br /&gt;
&lt;br /&gt;
=='''From Waterfall to V-Model'''==&lt;br /&gt;
&lt;br /&gt;
Every phase or stage in the waterfall model needs to be completed and signed off before the next phase can start, this rigidity affects the flexibility in iterating back and forth between the stages of development with the result being a poor quality system. The V-Model prevents this by explicitly connecting the development and testing stages.&lt;br /&gt;
&lt;br /&gt;
=='''Objectives'''==&lt;br /&gt;
&lt;br /&gt;
The V-Model facilitates the planning and realization of projects. The following are the objectives to be achieved during system development:&lt;br /&gt;
&lt;br /&gt;
*Minimizing Project Risks: Early recognition of planning deviations and risks improves process management, thus reducing risks.&lt;br /&gt;
&lt;br /&gt;
*Improving Quality: Defined interim results can be checked at an early stage. Uniform product contents will improve readability, understandability and verifiability.&lt;br /&gt;
&lt;br /&gt;
*Reduction of Total Cost: The results obtained should be uniform and easily retraced. This reduces the dependency on the supplier and the effort for subsequent activities.&lt;br /&gt;
&lt;br /&gt;
*Effective Communication between all Stakeholders: The miscommunication between user, supplier and developer is reduced.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
�&lt;br /&gt;
=='''Verification phase'''==&lt;br /&gt;
&lt;br /&gt;
Verification ensures that, the software is being built correctly. The ISTQB defines Verification as: “Confirmation by examination and through provision of objective evidence that specified requirements have been fulfilled.“&lt;br /&gt;
&lt;br /&gt;
The first part of the definition is the same as for Validation, but the second part is the key. This states that “specified requirements have been fulfilled“. The V-model diagram arrows shows that each produced product is checked against the products or documents that were used to drive the development. This ensures that all aspects have been met. A key problem is ensuring that the user requirements are adequately verified against the customer needs. The Business Case is only likely to contain high level functionality, and not the detail about processes that are essential for determining what is required.&lt;br /&gt;
&lt;br /&gt;
=='''Requirements Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Requirements analysis encompasses those tasks that determine the conditions specified by the stakeholders for the product. Its activities are concerned with eliciting, analyzing, documenting, validating and managing system requirements. The requirements have to be documentable, actionable, measurable, testable, traceable, related to the business needs and should include details sufficient for system design.&lt;br /&gt;
&lt;br /&gt;
Requirements analysis includes three types of activities:&lt;br /&gt;
&lt;br /&gt;
*Eliciting requirements: Identifying the various types of requirements from various sources i.e. project and business process documentation along with stakeholder interviews.&lt;br /&gt;
&lt;br /&gt;
*Analyzing requirements: Determining whether the specified requirements are clear, complete and consistent.&lt;br /&gt;
&lt;br /&gt;
*Recording requirements: Requirements can be documented in normal language documents, use cases, user stories, or system specifications.&lt;br /&gt;
&lt;br /&gt;
Requirements analysis is a long process during which many changes can occur over that time period. Technology changes, business requirements changes with many other things, so it is important that the stakeholders are in constant touch with the developers to ensure that they understand the new improved system. It is the responsibility of the analyst to gather information from the customer. System prototypes should be developed to demonstrate a working model to the stakeholders. Analysts employ a combination of various methods to establish the exact requirements of the stakeholders, so that the system developed meets the customer’s needs. The information regarding the product requirements can be classified as: Customer, Architectural, Structural, Behavioral, Functional, Non-functional, Performance, Design, Derived, and Allocated Requirements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''System Design'''==&lt;br /&gt;
&lt;br /&gt;
This design process defines the architecture, components, modules, interfaces, and data required by a system to meet the mentioned system requirements. We can say that design is an act of taking the marketing information and creating the products to be manufactured. So, systems design is the process of defining and developing systems specified by the user.&lt;br /&gt;
&lt;br /&gt;
*Softwares that run on generic platforms have enhanced software engineering. &lt;br /&gt;
&lt;br /&gt;
*Object-oriented analysis and design methods are widely used for systems design.&lt;br /&gt;
&lt;br /&gt;
*UML is used for modeling software systems and designing high non-software systems and organizations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Architecture Design'''==&lt;br /&gt;
&lt;br /&gt;
The design of computer and software architecture can be referred to as high-level design. The architecture selected should realize the list of modules, brief functionality of each module, the interface relationships between the modules, dependencies, database tables, architecture diagrams, technology details etc.&lt;br /&gt;
&lt;br /&gt;
Integration testing design is carried out in this phase.&lt;br /&gt;
&lt;br /&gt;
=='''Module Design'''==&lt;br /&gt;
&lt;br /&gt;
The module design phase is a low-level design. The designed system is broken up into smaller units and each of them is explained to the programmer. The low level design document will contain a detailed functional logic of the module:&lt;br /&gt;
&lt;br /&gt;
*database tables, with all elements, including their type and size&lt;br /&gt;
&lt;br /&gt;
*all interface details with complete API references&lt;br /&gt;
&lt;br /&gt;
*all dependency issues&lt;br /&gt;
&lt;br /&gt;
*error message listings&lt;br /&gt;
&lt;br /&gt;
*complete input and outputs for a module.&lt;br /&gt;
&lt;br /&gt;
Unit test design is developed in this stage.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Coding'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Validation phase'''==&lt;br /&gt;
===Importance of Early Testing===&lt;br /&gt;
&lt;br /&gt;
Studies show that catching a fault early in the development stages before the system is released is more cost effective and it takes less resources to fix the system when compared to fixing it after its release. We must also take into account the reputation of the organisation, the cost associated with missing functionality, so in fact the true cost for fixing the system is much higher.&lt;br /&gt;
&lt;br /&gt;
In the waterfall model errors were found very late in the cycle because testing began at the end of the project. In the V-Model testing begins as early as possible. Prior to testing, the testing team works on various activities in parallel to the development activity which helps to get the test deliverable on time which includes creation of test cases, preparation of test strategies, test planning and test scripting.&lt;br /&gt;
&lt;br /&gt;
===Testing Types Matched to Development Stages===&lt;br /&gt;
&lt;br /&gt;
The first noticeable point of the V-Model is that the Test stage of the Waterfall model is bent upwards to make it a “V”. This stage is now separated out into the various types of testing. So this first step visually points out that there is more than one type of testing to consider for system development and like the development steps they build on one another, and have different objectives. The next important part of the “V” is to match each type of testing against the development stage it matches e.g. we have Component Design matched against Component Testing. This means that the testing stage does not start when the Construct Component stage has ended. Instead when each development stage starts, the testing for that stage also starts.&lt;br /&gt;
&lt;br /&gt;
===Unit testing===&lt;br /&gt;
&lt;br /&gt;
Unit testing, tests the low level design i.e. units. A unit is a basic module of the application on which testing is carried out, it may be an individual function or a procedure. These tests are created by the developers (white box testing) to verify the internal logic code. Input data are passed to the unit to test every case of execution.&lt;br /&gt;
&lt;br /&gt;
===Integration testing===&lt;br /&gt;
&lt;br /&gt;
Integration testing tests high level design i.e. components and their interfaces. In Integration testing the basic units will be tested together to check the interaction between them and finds errors in the interfaces. This is generally a black box testing method. Integration testing is  performed by program team leaders.&lt;br /&gt;
&lt;br /&gt;
===System testing===&lt;br /&gt;
&lt;br /&gt;
Once the entire system has been developed, it then has to be tested against the system specifications to validate if it provides the required features. In short, system testing is about checking the system as a whole. System testing involves a number of special types of tests to see if all the functional and nonfunctional requirements have been met. System testing is performed by system testers.&lt;br /&gt;
Reasons for carrying out a system test even after the unit and integration test&lt;br /&gt;
&lt;br /&gt;
*The previous testings were done against the system specifications. The system test, looks at the system from the perspective of the future user.&lt;br /&gt;
&lt;br /&gt;
*Many of the system functions and characteristics results from the interaction of  the modules, and can be tested only at this level. &lt;br /&gt;
&lt;br /&gt;
*Also, keeping in mind that the customer and the end user can be two different groups of people having their own requirements and interests. &lt;br /&gt;
&lt;br /&gt;
===Acceptance testing===&lt;br /&gt;
&lt;br /&gt;
The major purpose of Acceptance Testing is to validate or confirm that the system meets the  business requirements and gives an assurance before it is delivered to the end user. This phase is for testing the software in the real world by the end user to determine whether to accept the system or not.&lt;br /&gt;
&lt;br /&gt;
===Release testing===&lt;br /&gt;
&lt;br /&gt;
This testing phase answers important questions such as&lt;br /&gt;
&lt;br /&gt;
*Is the software suitable for the end user?&lt;br /&gt;
&lt;br /&gt;
*Has the compatibility with other systems been ensured?&lt;br /&gt;
&lt;br /&gt;
*Is the performance of the software optimized?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Advantages===&lt;br /&gt;
&lt;br /&gt;
*Early acceptance criteria is the key advantage, they are performed against a specification of requirements.&lt;br /&gt;
&lt;br /&gt;
*60 to 70 percent of all faults are in the system before the component construction and test stages start, which is taken care of. &lt;br /&gt;
&lt;br /&gt;
*At an early stage we can feed back to catch a fault before it is built into the system.&lt;br /&gt;
&lt;br /&gt;
*Specifies test requirements and expected results prior to performing the actual tests.&lt;br /&gt;
&lt;br /&gt;
*Defines who is responsible for performing the testing and provides a focus for defining the testing that takes place at each stage. &lt;br /&gt;
&lt;br /&gt;
===Disadvantages===&lt;br /&gt;
&lt;br /&gt;
*Too simple to reflect the development process.&lt;br /&gt;
&lt;br /&gt;
*Leads project managers to a false sense of security.&lt;br /&gt;
&lt;br /&gt;
*Inflexible and no ability to respond to change.&lt;br /&gt;
&lt;br /&gt;
*Produces inefficient testing methodologies&lt;br /&gt;
&lt;br /&gt;
*The placing of contracts for services is not regulated.&lt;br /&gt;
&lt;br /&gt;
*The organization and execution of operation, maintenance, repair and disposal of the system are not covered by the V-Model. &lt;br /&gt;
&lt;br /&gt;
*The V-Model addresses software development within a project rather than a whole organization.&lt;br /&gt;
&lt;br /&gt;
===Conclusion===&lt;br /&gt;
&lt;br /&gt;
Testing in the development process is critical. The earlier a fault is found, the cheaper it is to fix. The V model extends testing to the beginning of the lifecycle. The explicit recognition of testing in the V model makes it very useful in planning and executing information system development. The V-Model has evolved over time and supports flexibility and agility throughout the development process. Static testing techniques, such as inspections and walkthroughs, can be used to find faults in the functional specification, as well as defining test cases that are subsequently executed in system testing.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
http://www.softwaretestingclass.com/v-model/&lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/V-Model_(software_development)&lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/V-Model&lt;br /&gt;
&lt;br /&gt;
http://www.careerride.com/testing-v-model.aspx&lt;br /&gt;
&lt;br /&gt;
http://www.softwaretestingmentor.com/sdlc/vmodel.php&lt;br /&gt;
&lt;br /&gt;
http://www.bucanac.com/documents/The_V-Model.pdf&lt;br /&gt;
&lt;br /&gt;
http://www.compensationanalytics.com/_resources/vtestingmodel.pdf&lt;br /&gt;
&lt;br /&gt;
http://www.google.co.in/search?q=v+model&amp;amp;hl=en&amp;amp;biw=1241&amp;amp;bih=606&amp;amp;prmd=imvnsb&amp;amp;tbm=isch&amp;amp;tbo=u&amp;amp;source=univ&amp;amp;sa=X&amp;amp;ei=XVd8UICgNYem9gSa4oCYDA&amp;amp;sqi=2&amp;amp;ved=0CC8QsAQ&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Further Suggested Reading===&lt;br /&gt;
&lt;br /&gt;
    Dual Vee Model             &lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/Dual_Vee_Model&lt;br /&gt;
&lt;br /&gt;
    System Development Lifecycle        &lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/Systems_Development_Life_Cycle&lt;br /&gt;
&lt;br /&gt;
    Product Lifecycle Management        &lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/Product_lifecycle_management&lt;br /&gt;
&lt;br /&gt;
    Portal: Software Testing&lt;br /&gt;
&lt;br /&gt;
       &lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/Portal:Software_Testing&lt;br /&gt;
&lt;br /&gt;
    IBM RUP&lt;br /&gt;
&lt;br /&gt;
    http://en.wikipedia.org/wiki/RUP&lt;br /&gt;
&lt;br /&gt;
    Systems Architecture&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    http://en.wikipedia.org/wiki/Systems_architecture&lt;br /&gt;
&lt;br /&gt;
    System Analysis&lt;br /&gt;
&lt;br /&gt;
    http://en.wikipedia.org/wiki/Systems_analysis&lt;br /&gt;
&lt;br /&gt;
    System Design&lt;br /&gt;
&lt;br /&gt;
    http://en.wikipedia.org/wiki/Systems_design&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w4_sa&amp;diff=68163</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w4 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w4_sa&amp;diff=68163"/>
		<updated>2012-10-25T11:01:57Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''V - Model'''&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
&lt;br /&gt;
The V-model also called as Verification and Validation model is a software development process which simplifies the understanding of the complexity associated with the development of a system,  and is an extension to the waterfall model. Rather than proceeding linearly downwards, after the coding phase, the process steps are bent upwards to form a V shape. This creates an association between the phases in the development and the testing cycle.&lt;br /&gt;
&lt;br /&gt;
In the diagram, the left arm corresponds to the development phases in the traditional waterfall model and the right to the test phases. Each development activity carried out by the development team has its corresponding validation activity done by the testing team.&lt;br /&gt;
&lt;br /&gt;
=='''From Waterfall to V-Model'''==&lt;br /&gt;
&lt;br /&gt;
Every phase or stage in the waterfall model needs to be completed and signed off before the next phase can start, this rigidity affects the flexibility in iterating back and forth between the stages of development with the result being a poor quality system. The V-Model prevents this by explicitly connecting the development and testing stages.&lt;br /&gt;
&lt;br /&gt;
=='''Objectives'''==&lt;br /&gt;
&lt;br /&gt;
The V-Model facilitates the planning and realization of projects. The following are the objectives to be achieved during system development:&lt;br /&gt;
&lt;br /&gt;
*Minimizing Project Risks: Early recognition of planning deviations and risks improves process management, thus reducing risks.&lt;br /&gt;
&lt;br /&gt;
*Improving Quality: Defined interim results can be checked at an early stage. Uniform product contents will improve readability, understandability and verifiability.&lt;br /&gt;
&lt;br /&gt;
*Reduction of Total Cost: The results obtained should be uniform and easily retraced. This reduces the dependency on the supplier and the effort for subsequent activities.&lt;br /&gt;
&lt;br /&gt;
*Effective Communication between all Stakeholders: The miscommunication between user, supplier and developer is reduced.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
�&lt;br /&gt;
=='''Verification phase'''==&lt;br /&gt;
&lt;br /&gt;
Verification ensures that, the software is being built correctly. The ISTQB defines Verification as: “Confirmation by examination and through provision of objective evidence that specified requirements have been fulfilled.“&lt;br /&gt;
&lt;br /&gt;
The first part of the definition is the same as for Validation, but the second part is the key. This states that “specified requirements have been fulfilled“. The V-model diagram arrows shows that each produced product is checked against the products or documents that were used to drive the development. This ensures that all aspects have been met. A key problem is ensuring that the user requirements are adequately verified against the customer needs. The Business Case is only likely to contain high level functionality, and not the detail about processes that are essential for determining what is required.&lt;br /&gt;
&lt;br /&gt;
=='''Requirements Analysis'''==&lt;br /&gt;
&lt;br /&gt;
Requirements analysis encompasses those tasks that determine the conditions specified by the stakeholders for the product. Its activities are concerned with eliciting, analyzing, documenting, validating and managing system requirements. The requirements have to be documentable, actionable, measurable, testable, traceable, related to the business needs and should include details sufficient for system design.&lt;br /&gt;
&lt;br /&gt;
Requirements analysis includes three types of activities:&lt;br /&gt;
&lt;br /&gt;
*Eliciting requirements: Identifying the various types of requirements from various sources i.e. project and business process documentation along with stakeholder interviews.&lt;br /&gt;
&lt;br /&gt;
*Analyzing requirements: Determining whether the specified requirements are clear, complete and consistent.&lt;br /&gt;
&lt;br /&gt;
*Recording requirements: Requirements can be documented in normal language documents, use cases, user stories, or system specifications.&lt;br /&gt;
&lt;br /&gt;
Requirements analysis is a long process during which many changes can occur over that time period. Technology changes, business requirements changes with many other things, so it is important that the stakeholders are in constant touch with the developers to ensure that they understand the new improved system. It is the responsibility of the analyst to gather information from the customer. System prototypes should be developed to demonstrate a working model to the stakeholders. Analysts employ a combination of various methods to establish the exact requirements of the stakeholders, so that the system developed meets the customer’s needs. The information regarding the product requirements can be classified as: Customer, Architectural, Structural, Behavioral, Functional, Non-functional, Performance, Design, Derived, and Allocated Requirements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''System Design'''==&lt;br /&gt;
&lt;br /&gt;
This design process defines the architecture, components, modules, interfaces, and data required by a system to meet the mentioned system requirements. We can say that design is an act of taking the marketing information and creating the products to be manufactured. So, systems design is the process of defining and developing systems specified by the user.&lt;br /&gt;
&lt;br /&gt;
*Softwares that run on generic platforms have enhanced software engineering. &lt;br /&gt;
&lt;br /&gt;
*Object-oriented analysis and design methods are widely used for systems design.&lt;br /&gt;
&lt;br /&gt;
*UML is used for modeling software systems and designing high non-software systems and organizations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Architecture Design'''==&lt;br /&gt;
&lt;br /&gt;
The design of computer and software architecture can be referred to as high-level design. The architecture selected should realize the list of modules, brief functionality of each module, the interface relationships between the modules, dependencies, database tables, architecture diagrams, technology details etc.&lt;br /&gt;
&lt;br /&gt;
Integration testing design is carried out in this phase.&lt;br /&gt;
&lt;br /&gt;
=='''Module Design'''==&lt;br /&gt;
&lt;br /&gt;
The module design phase is a low-level design. The designed system is broken up into smaller units and each of them is explained to the programmer. The low level design document will contain a detailed functional logic of the module:&lt;br /&gt;
&lt;br /&gt;
*database tables, with all elements, including their type and size&lt;br /&gt;
&lt;br /&gt;
*all interface details with complete API references&lt;br /&gt;
&lt;br /&gt;
*all dependency issues&lt;br /&gt;
&lt;br /&gt;
*error message listings&lt;br /&gt;
&lt;br /&gt;
*complete input and outputs for a module.&lt;br /&gt;
&lt;br /&gt;
Unit test design is developed in this stage.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Coding'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Validation phase'''==&lt;br /&gt;
===Importance of Early Testing===&lt;br /&gt;
&lt;br /&gt;
Studies show that catching a fault early in the development stages before the system is released is more cost effective and it takes less resources to fix the system when compared to fixing it after its release. We must also take into account the reputation of the organisation, the cost associated with missing functionality, so in fact the true cost for fixing the system is much higher.&lt;br /&gt;
&lt;br /&gt;
In the waterfall model errors were found very late in the cycle because testing began at the end of the project. In the V-Model testing begins as early as possible. Prior to testing, the testing team works on various activities in parallel to the development activity which helps to get the test deliverable on time which includes creation of test cases, preparation of test strategies, test planning and test scripting.&lt;br /&gt;
&lt;br /&gt;
===Testing Types Matched to Development Stages===&lt;br /&gt;
&lt;br /&gt;
The first noticeable point of the V-Model is that the Test stage of the Waterfall model is bent upwards to make it a “V”. This stage is now separated out into the various types of testing. So this first step visually points out that there is more than one type of testing to consider for system development and like the development steps they build on one another, and have different objectives. The next important part of the “V” is to match each type of testing against the development stage it matches e.g. we have Component Design matched against Component Testing. This means that the testing stage does not start when the Construct Component stage has ended. Instead when each development stage starts, the testing for that stage also starts.&lt;br /&gt;
&lt;br /&gt;
===Unit testing===&lt;br /&gt;
&lt;br /&gt;
Unit testing, tests the low level design i.e. units. A unit is a basic module of the application on which testing is carried out, it may be an individual function or a procedure. These tests are created by the developers (white box testing) to verify the internal logic code. Input data are passed to the unit to test every case of execution.&lt;br /&gt;
&lt;br /&gt;
===Integration testing===&lt;br /&gt;
&lt;br /&gt;
Integration testing tests high level design i.e. components and their interfaces. In Integration testing the basic units will be tested together to check the interaction between them and finds errors in the interfaces. This is generally a black box testing method. Integration testing is  performed by program team leaders.&lt;br /&gt;
&lt;br /&gt;
===System testing===&lt;br /&gt;
&lt;br /&gt;
Once the entire system has been developed, it then has to be tested against the system specifications to validate if it provides the required features. In short, system testing is about checking the system as a whole. System testing involves a number of special types of tests to see if all the functional and nonfunctional requirements have been met. System testing is performed by system testers.&lt;br /&gt;
Reasons for carrying out a system test even after the unit and integration test&lt;br /&gt;
&lt;br /&gt;
*The previous testings were done against the system specifications. The system test, looks at the system from the perspective of the future user.&lt;br /&gt;
&lt;br /&gt;
*Many of the system functions and characteristics results from the interaction of  the modules, and can be tested only at this level. &lt;br /&gt;
&lt;br /&gt;
*Also, keeping in mind that the customer and the end user can be two different groups of people having their own requirements and interests. &lt;br /&gt;
&lt;br /&gt;
===Acceptance testing===&lt;br /&gt;
&lt;br /&gt;
The major purpose of Acceptance Testing is to validate or confirm that the system meets the  business requirements and gives an assurance before it is delivered to the end user. This phase is for testing the software in the real world by the end user to determine whether to accept the system or not.&lt;br /&gt;
&lt;br /&gt;
===Release testing===&lt;br /&gt;
&lt;br /&gt;
This testing phase answers important questions such as&lt;br /&gt;
&lt;br /&gt;
*Is the software suitable for the end user?&lt;br /&gt;
&lt;br /&gt;
*Has the compatibility with other systems been ensured?&lt;br /&gt;
&lt;br /&gt;
*Is the performance of the software optimized?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Advantages===&lt;br /&gt;
&lt;br /&gt;
*Early acceptance criteria is the key advantage, they are performed against a specification of requirements.&lt;br /&gt;
&lt;br /&gt;
*60 to 70 percent of all faults are in the system before the component construction and test stages start, which is taken care of. &lt;br /&gt;
&lt;br /&gt;
*At an early stage we can feed back to catch a fault before it is built into the system.&lt;br /&gt;
&lt;br /&gt;
*Specifies test requirements and expected results prior to performing the actual tests.&lt;br /&gt;
&lt;br /&gt;
*Defines who is responsible for performing the testing and provides a focus for defining the testing that takes place at each stage. &lt;br /&gt;
&lt;br /&gt;
===Disadvantages===&lt;br /&gt;
&lt;br /&gt;
*Too simple to reflect the development process.&lt;br /&gt;
&lt;br /&gt;
*Leads project managers to a false sense of security.&lt;br /&gt;
&lt;br /&gt;
*Inflexible and no ability to respond to change.&lt;br /&gt;
&lt;br /&gt;
*Produces inefficient testing methodologies&lt;br /&gt;
&lt;br /&gt;
*The placing of contracts for services is not regulated.&lt;br /&gt;
&lt;br /&gt;
*The organization and execution of operation, maintenance, repair and disposal of the system are not covered by the V-Model. &lt;br /&gt;
&lt;br /&gt;
*The V-Model addresses software development within a project rather than a whole organization.&lt;br /&gt;
&lt;br /&gt;
===Conclusion===&lt;br /&gt;
&lt;br /&gt;
Testing in the development process is critical. The earlier a fault is found, the cheaper it is to fix. The V model extends testing to the beginning of the lifecycle. The explicit recognition of testing in the V model makes it very useful in planning and executing information system development. The V-Model has evolved over time and supports flexibility and agility throughout the development process. Static testing techniques, such as inspections and walkthroughs, can be used to find faults in the functional specification, as well as defining test cases that are subsequently executed in system testing.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
http://www.softwaretestingclass.com/v-model/&lt;br /&gt;
http://en.wikipedia.org/wiki/V-Model_(software_development)&lt;br /&gt;
http://en.wikipedia.org/wiki/V-Model&lt;br /&gt;
http://www.careerride.com/testing-v-model.aspx&lt;br /&gt;
http://www.softwaretestingmentor.com/sdlc/vmodel.php&lt;br /&gt;
http://www.bucanac.com/documents/The_V-Model.pdf&lt;br /&gt;
http://www.compensationanalytics.com/_resources/vtestingmodel.pdf&lt;br /&gt;
http://www.google.co.in/search?q=v+model&amp;amp;hl=en&amp;amp;biw=1241&amp;amp;bih=606&amp;amp;prmd=imvnsb&amp;amp;tbm=isch&amp;amp;tbo=u&amp;amp;source=univ&amp;amp;sa=X&amp;amp;ei=XVd8UICgNYem9gSa4oCYDA&amp;amp;sqi=2&amp;amp;ved=0CC8QsAQ&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Further Suggested Reading===&lt;br /&gt;
&lt;br /&gt;
    Dual Vee Model             &lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/Dual_Vee_Model&lt;br /&gt;
&lt;br /&gt;
    System Development Lifecycle        &lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/Systems_Development_Life_Cycle&lt;br /&gt;
&lt;br /&gt;
    Product Lifecycle Management        &lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/Product_lifecycle_management&lt;br /&gt;
&lt;br /&gt;
    Portal: Software Testing&lt;br /&gt;
&lt;br /&gt;
       &lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/Portal:Software_Testing&lt;br /&gt;
&lt;br /&gt;
    IBM RUP&lt;br /&gt;
&lt;br /&gt;
    http://en.wikipedia.org/wiki/RUP&lt;br /&gt;
&lt;br /&gt;
    Systems Architecture&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    http://en.wikipedia.org/wiki/Systems_architecture&lt;br /&gt;
&lt;br /&gt;
    System Analysis&lt;br /&gt;
&lt;br /&gt;
    http://en.wikipedia.org/wiki/Systems_analysis&lt;br /&gt;
&lt;br /&gt;
    System Design&lt;br /&gt;
&lt;br /&gt;
    http://en.wikipedia.org/wiki/Systems_design&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65317</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w22 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65317"/>
		<updated>2012-09-20T00:49:13Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* method_missing Implementationhttp://www.thirdbit.net/articles/2007/08/01/10-things-you-should-know-about-method_missing/ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
=='''Introduction&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_method_missing.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
A method that belongs to a class is called by creating an object of the class and passing the method name to the object as a message. The object then looks up the [http://www.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html method lookup path] and tries to match the called method with the defined methods in the class. On success, the method is executed and the result is returned.&lt;br /&gt;
&lt;br /&gt;
If the object does not find a match in its method lookup, in normal circumstances the [http://www.ruby-doc.org/core-1.9.3/NoMethodError.html NoMethodError Exception] is raised .&lt;br /&gt;
&lt;br /&gt;
In cases where the user wants to handle the methods which are not defined but are still called, “method_missing” can be defined and the user can handle the methods as he/she sees fit.&lt;br /&gt;
&lt;br /&gt;
=='''Format for Defining method_missing'''==&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; def method_missing(m,*args,&amp;amp;block)&lt;br /&gt;
&lt;br /&gt;
(i) '''m-&amp;gt;''' accepts the symbol/name of the undefined method (ii) '''*args-&amp;gt;''' accepts the array of arguments passed in the method call  (iii) '''&amp;amp;block-&amp;gt;'''accepts a block passed to the method&lt;br /&gt;
&lt;br /&gt;
=='''Ruby Method Lookup Flow'''==&lt;br /&gt;
When the object of a class receives a method name to be executed, the following steps are carried out for matching and executing the method:&lt;br /&gt;
&lt;br /&gt;
*First, the object looks in its own [http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html instance methods].&lt;br /&gt;
*Second, it looks in the list of instance methods that all objects of that class share.&lt;br /&gt;
*Third, in each of the included [http://www.tutorialspoint.com/ruby/ruby_modules.html modules] of that class, in reverse order of inclusion. &lt;br /&gt;
*Fourth, it looks in that class’s superclass. &lt;br /&gt;
*Fifth, in the superclass’s included modules, all the way up until it reaches the class Object. &lt;br /&gt;
*Sixth, if it still can’t find a method, the very last place it looks is in the [http://linux.die.net/lkmpg/x40.html Kernel module], included in the class Object. &lt;br /&gt;
*Finally, it calls method_missing (if defined in the class), else throws up the NOMethodError exception.&lt;br /&gt;
&lt;br /&gt;
This entire tracing that the object does is the method lookup path.&lt;br /&gt;
&lt;br /&gt;
=='''Examples'''==&lt;br /&gt;
===Calling Defined and Undefined Methods===&lt;br /&gt;
&lt;br /&gt;
 class A		// creating a class 'A'&lt;br /&gt;
 def say		// defining a method 'say'&lt;br /&gt;
 puts &amp;quot; say Hi &amp;quot; // body of method say&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Creating the object of the class&lt;br /&gt;
 &lt;br /&gt;
  a=A.new	       // object of the class&lt;br /&gt;
  =&amp;gt; #&amp;lt;A:0x2a082e0&amp;gt;     //object id&lt;br /&gt;
&lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.say                  // defined method&lt;br /&gt;
 =&amp;gt; say Hi	       // returned result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.sayhi                // undefined method sayhi&lt;br /&gt;
 NoMethodError: undefined method `sayhi' for #&amp;lt;A:0x2a082e0&amp;gt;   // the NoMethodError is raised&lt;br /&gt;
&lt;br /&gt;
===method_missing Implementation&amp;lt;ref&amp;gt;http://www.thirdbit.net/articles/2007/08/01/10-things-you-should-know-about-method_missing/&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def say&lt;br /&gt;
 puts &amp;quot; say hi &amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(m,*args,&amp;amp;block)	// defining method_missing&lt;br /&gt;
 puts &amp;quot; This method does not exist&amp;quot;	// body of method_missing&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Calling a method that is not defined&lt;br /&gt;
 &lt;br /&gt;
 a=A.new&lt;br /&gt;
 a.sayhi                                // calling the undefined method sayhi with no arguments&lt;br /&gt;
 =&amp;gt; This method does not exist		// this result returned when method_missing is executed&lt;br /&gt;
&lt;br /&gt;
When the object 'a' traces its method lookup path for a matching method 'sayhi', upon failure it resorts to method_missing and the body of method_missing is executed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Sometimes when a class has many methods that do generally the same kinds of functionality, and the programmer is not sure in advance which methods the user will call since there are so many of them, and all of them are similar, writing code for all of the methods seems futile. In these situations method_missing can be defined to take care of these cases. The below 'Generic Handler' example implements this.&lt;br /&gt;
&lt;br /&gt;
===Passing Parameters to an Undefined Method Call===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def add(a,b)&lt;br /&gt;
 a+b&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(name,*args,&amp;amp;block)    // the method_missing is defined and the *args parameter accepts all the parameters passed during 								                                 &lt;br /&gt;
                                             the method call   &lt;br /&gt;
 puts “You have typed the method name wrong and these were the parameters passed ; #{args[0]}, #{args[1]}”								&lt;br /&gt;
 end                         			&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The passed parameters are stored in the array 'args' and can be accessed like a normal array                &lt;br /&gt;
                                                   &lt;br /&gt;
 &lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.add(1,2)		        // calling the defined method add and passing the parameters (1,2)&lt;br /&gt;
 =&amp;gt; 3                           // result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.adds(4,2) 			// calling the undefined method adds and passing the parameter (4,2)&lt;br /&gt;
 =&amp;gt; You have typed the method name wrong and these were the parameters passed; 4, 2&lt;br /&gt;
&lt;br /&gt;
The user made a genuine mistake by typing 'adds', but this method is not defined. When the 'adds' method with parameters is called, the object 'a' tries to match the method in the method lookup path. Upon failure it invokes method_missing, the args are passed, stored in the array 'args' and the body of method_missing is executed.&lt;br /&gt;
&lt;br /&gt;
===Converting Numbers from Roman Representation to Integer Representation&amp;lt;ref&amp;gt;http://courses.ncsu.edu/csc517/common/lectures/notes/wk2.pdf&amp;lt;/ref&amp;gt;===&lt;br /&gt;
 class Roman&lt;br /&gt;
 DIGITS = {'I'=&amp;gt;1,'V'=&amp;gt;5,'X'=&amp;gt;10,'L'=&amp;gt;50,'C'=&amp;gt;100,'D'=&amp;gt;500,'M'=&amp;gt;1000,}&lt;br /&gt;
 def roman_to_integer(roman_string)&lt;br /&gt;
 last = nil&lt;br /&gt;
 roman_string.to_s.upcase.split(//).reverse.inject(0) do&lt;br /&gt;
 |memo, digit|&lt;br /&gt;
 if digit_value = DIGITS[digit]&lt;br /&gt;
 if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
 memo -= digit_value&lt;br /&gt;
 else&lt;br /&gt;
 memo += digit_value&lt;br /&gt;
 end&lt;br /&gt;
 last = digit_value&lt;br /&gt;
 end&lt;br /&gt;
 memo&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def method_missing(method)&lt;br /&gt;
 str=method.id2name&lt;br /&gt;
 roman_to_integer(str)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calling the undefined methods&lt;br /&gt;
&lt;br /&gt;
 r= Roman.new&lt;br /&gt;
 r.vii&lt;br /&gt;
 r.xxix&lt;br /&gt;
 r.xxiv&lt;br /&gt;
 r.xxvi&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The Output&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; 7&lt;br /&gt;
 =&amp;gt; 29&lt;br /&gt;
 =&amp;gt; 24&lt;br /&gt;
&lt;br /&gt;
===method_missing to Log Method Calls&amp;lt;ref&amp;gt;http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2007/wiki1b_2_22&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Another application that makes use of method_missing could be a simple logger used for debugging purposes. Many times, it may be required to log the trace of called methods and provide information such as: called method-name, arguments, return type. It can be tedious to repeat this part of code in every method. A simple solution to this problem can be obtained using method_missing as:&lt;br /&gt;
&lt;br /&gt;
  class SimpleCallLogger&lt;br /&gt;
  def initialize(o)&lt;br /&gt;
  @obj = o&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(methodname, *args)&lt;br /&gt;
  puts &amp;quot;called: #{methodname}(#{args})&amp;quot;&lt;br /&gt;
  a = @obj.send(methodname, *args)&lt;br /&gt;
  puts &amp;quot;\t-&amp;gt; returned: #{a}&amp;quot;&lt;br /&gt;
  return a&lt;br /&gt;
  end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
This program makes use of method_missing in a way that it wraps around called method to output the logging information on entry and on exit, it logs the return type. Further, method_missing intercepts the method call and forward it to internal object with ‘send’ method of ruby. Hence, this use of method_missing acts as wrapper.&lt;br /&gt;
&lt;br /&gt;
===Generic Handler===&lt;br /&gt;
 class NoBar&lt;br /&gt;
 def method_missing(methodname, *args)&lt;br /&gt;
 define_method(:bar) if &amp;quot;bar&amp;quot; == methodname.to_s&lt;br /&gt;
 define_method(:nobar) if &amp;quot;nobar&amp;quot; == methodname.to_s&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This is an example of using method_missing as a generic handler to handle when a calling method is not exist. You can use missing_method to dynamically create a method at a runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Advantages of method_missing'''==&lt;br /&gt;
&lt;br /&gt;
*In addition to specifying the error messages for the undefined methods, method_missing provides a more dynamic behavior in the programming environment.&lt;br /&gt;
*If we are unfamiliar with the usage of the objects we created, then using method_missing is a good technique.&lt;br /&gt;
*Handles problems at runtime.&lt;br /&gt;
*Define's a generic method_missing and handle's any undefined method, a big advantage over Java. In Java, when you call an undefined method, the program will not compile.&lt;br /&gt;
*method_missing falls under the general technique of [http://en.wikipedia.org/wiki/Metaprogramming meta-programming]. Employ meta-programming in missing_function to write an another function to handle the call.&lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages of method_missing'''==	&lt;br /&gt;
*Slower than conventional method lookup. Simple tests indicate that method dispatch with method_missing is at least two to three times as expensive in time as conventional dispatch.&lt;br /&gt;
&lt;br /&gt;
*Since the methods being called never actually exist—they are just intercepted at the last step of the method lookup process—they cannot be documented or introspected as conventional methods can.&lt;br /&gt;
&lt;br /&gt;
*method_missing restricts compatibility with future versions of an [http://en.wikipedia.org/wiki/Application_programming_interface API]. Introducing new methods in a future API version can break users' expectations.&lt;br /&gt;
&lt;br /&gt;
=='''Key Points'''==&lt;br /&gt;
&lt;br /&gt;
*In the example below, class A defines only method method_missing() and no other method. When a new object of class A tries to access a method say 'foo', the respond_to? will return the value 'false'. When you actually try to implement it using “a.foo”, the code will get executed, courtesy of method_missing(). Even though the respond_to? says that you cannot access 'foo' method using object of class A, if you have method_missing() defined, you can access the method.&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In method_missing&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)&lt;br /&gt;
 a.foo&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 false&lt;br /&gt;
 In method_missing&lt;br /&gt;
&lt;br /&gt;
*In the following example, if within method_missing() we define an undefined method. &lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 @@i = 0&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In Method Missing #{@@i}&amp;quot;&lt;br /&gt;
 @@i += 1&lt;br /&gt;
 self.fun&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 a.foo &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 The result is a 'stack level too deep' error. &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
When the 'foo' method is called, after no method match the method_missing is run and this block has a method “self.fun” that is undefined.     Here when the program execution encounters 'self.fun' it once again calls method_missing. This goes on in an endless loop till the stack memory is full.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Ruby knows method_missing( ) exists, because it's a private instance method of 'BasicObject' that every object inherits. The BasicObject#method_missing( ) responds by raising the NoMethodError. Overriding this method_missing( ) allows you to call methods that don't really exist. &lt;br /&gt;
&lt;br /&gt;
*If method_missing is only looking for certain method names, don't forget to call the [http://en.wikibooks.org/wiki/Java_Programming/Keywords/super super] keyword if you haven't found what you're looking for, so that the other superclass' method_missing can handle it.&lt;br /&gt;
&lt;br /&gt;
*[http://www.prateekdayal.net/2007/10/16/rubys-responds_to-for-checking-if-a-method-exists/ obj.respond_to?] function returns 'true' if the obj responds to the given method. So if you want to know whether your class will respond to a function you can use respond_to? to know the answer. But if method_missing() is used, the output may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
*http://www.rubyinside.com/ &lt;br /&gt;
*https://www.youtube.com/watch?v=SAEiCkixrdE&amp;amp;feature=relmfu&lt;br /&gt;
*http://blog.jayfields.com/2008/02/ruby-replace-methodmissing-with-dynamic.html &lt;br /&gt;
*http://liquiddevelopment.blogspot.com/2006/04/twisting-and-shaping-dsls-using-ruby.html &lt;br /&gt;
*http://blog.rubybestpractices.com/posts/gregory/031-issue-2-method-lookup.html&lt;br /&gt;
*http://phrogz.net/RubyLibs/RubyMethodLookupFlow.pdf(Diagram)&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65316</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w22 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65316"/>
		<updated>2012-09-20T00:44:47Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* Introductionhttp://rubylearning.com/satishtalim/ruby_method_missing.html */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
=='''Introduction&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_method_missing.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
A method that belongs to a class is called by creating an object of the class and passing the method name to the object as a message. The object then looks up the [http://www.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html method lookup path] and tries to match the called method with the defined methods in the class. On success, the method is executed and the result is returned.&lt;br /&gt;
&lt;br /&gt;
If the object does not find a match in its method lookup, in normal circumstances the [http://www.ruby-doc.org/core-1.9.3/NoMethodError.html NoMethodError Exception] is raised .&lt;br /&gt;
&lt;br /&gt;
In cases where the user wants to handle the methods which are not defined but are still called, “method_missing” can be defined and the user can handle the methods as he/she sees fit.&lt;br /&gt;
&lt;br /&gt;
=='''Format for Defining method_missing'''==&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; def method_missing(m,*args,&amp;amp;block)&lt;br /&gt;
&lt;br /&gt;
(i) '''m-&amp;gt;''' accepts the symbol/name of the undefined method (ii) '''*args-&amp;gt;''' accepts the array of arguments passed in the method call  (iii) '''&amp;amp;block-&amp;gt;'''accepts a block passed to the method&lt;br /&gt;
&lt;br /&gt;
=='''Ruby Method Lookup Flow'''==&lt;br /&gt;
When the object of a class receives a method name to be executed, the following steps are carried out for matching and executing the method:&lt;br /&gt;
&lt;br /&gt;
*First, the object looks in its own [http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html instance methods].&lt;br /&gt;
*Second, it looks in the list of instance methods that all objects of that class share.&lt;br /&gt;
*Third, in each of the included [http://www.tutorialspoint.com/ruby/ruby_modules.html modules] of that class, in reverse order of inclusion. &lt;br /&gt;
*Fourth, it looks in that class’s superclass. &lt;br /&gt;
*Fifth, in the superclass’s included modules, all the way up until it reaches the class Object. &lt;br /&gt;
*Sixth, if it still can’t find a method, the very last place it looks is in the [http://linux.die.net/lkmpg/x40.html Kernel module], included in the class Object. &lt;br /&gt;
*Finally, it calls method_missing (if defined in the class), else throws up the NOMethodError exception.&lt;br /&gt;
&lt;br /&gt;
This entire tracing that the object does is the method lookup path.&lt;br /&gt;
&lt;br /&gt;
=='''Examples'''==&lt;br /&gt;
===Calling Defined and Undefined Methods===&lt;br /&gt;
&lt;br /&gt;
 class A		// creating a class 'A'&lt;br /&gt;
 def say		// defining a method 'say'&lt;br /&gt;
 puts &amp;quot; say Hi &amp;quot; // body of method say&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Creating the object of the class&lt;br /&gt;
 &lt;br /&gt;
  a=A.new	       // object of the class&lt;br /&gt;
  =&amp;gt; #&amp;lt;A:0x2a082e0&amp;gt;     //object id&lt;br /&gt;
&lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.say                  // defined method&lt;br /&gt;
 =&amp;gt; say Hi	       // returned result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.sayhi                // undefined method sayhi&lt;br /&gt;
 NoMethodError: undefined method `sayhi' for #&amp;lt;A:0x2a082e0&amp;gt;   // the NoMethodError is raised&lt;br /&gt;
&lt;br /&gt;
===method_missing Implementation&amp;lt;ref&amp;gt;http://www.thirdbit.net/articles/2007/08/01/10-things-you-should-know-about-method_missing/&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def say&lt;br /&gt;
 puts &amp;quot; say hi &amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(m,*args,&amp;amp;block)	// defining method_missing&lt;br /&gt;
 puts &amp;quot; This method does not exist&amp;quot;	// body of method_missing&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Calling a method that is not defined&lt;br /&gt;
 &lt;br /&gt;
 a=A.new&lt;br /&gt;
 a.sayhi                                // calling the undefined method sayhi with no arguments&lt;br /&gt;
 =&amp;gt; This method does not exist		// this result returned when method_missing is executed&lt;br /&gt;
&lt;br /&gt;
When the object 'a' traces its method lookup path for a matching method as 'sayhi', upon failure it resorts to method_missing and the body of method_missing is executed. 'method_missing' is the last resort.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Sometimes when a class has many methods that do generally the same kinds of things, and the programmer is not sure in advance which methods the user will call since there are so many of them, and they are all so similar, writing code for all of them seems futile. In these situations method_missing can be defined to take care of different cases. The below 'Generic Handler' example implements this.&lt;br /&gt;
&lt;br /&gt;
===Passing Parameters to an Undefined Method Call===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def add(a,b)&lt;br /&gt;
 a+b&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(name,*args,&amp;amp;block)    // the method_missing is defined and the *args parameter accepts all the parameters passed during 								                                 &lt;br /&gt;
                                             the method call   &lt;br /&gt;
 puts “You have typed the method name wrong and these were the parameters passed ; #{args[0]}, #{args[1]}”								&lt;br /&gt;
 end                         			&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The passed parameters are stored in the array 'args' and can be accessed like a normal array                &lt;br /&gt;
                                                   &lt;br /&gt;
 &lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.add(1,2)		        // calling the defined method add and passing the parameters (1,2)&lt;br /&gt;
 =&amp;gt; 3                           // result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.adds(4,2) 			// calling the undefined method adds and passing the parameter (4,2)&lt;br /&gt;
 =&amp;gt; You have typed the method name wrong and these were the parameters passed; 4, 2&lt;br /&gt;
&lt;br /&gt;
The user made a genuine mistake by typing 'adds', but this method is not defined. When the 'adds' method with parameters is called, the object 'a' tries to match the method in the method lookup path. Upon failure it invokes method_missing, the args are passed, stored in the array 'args' and the body of method_missing is executed.&lt;br /&gt;
&lt;br /&gt;
===Converting Numbers from Roman Representation to Integer Representation&amp;lt;ref&amp;gt;http://courses.ncsu.edu/csc517/common/lectures/notes/wk2.pdf&amp;lt;/ref&amp;gt;===&lt;br /&gt;
 class Roman&lt;br /&gt;
 DIGITS = {'I'=&amp;gt;1,'V'=&amp;gt;5,'X'=&amp;gt;10,'L'=&amp;gt;50,'C'=&amp;gt;100,'D'=&amp;gt;500,'M'=&amp;gt;1000,}&lt;br /&gt;
 def roman_to_integer(roman_string)&lt;br /&gt;
 last = nil&lt;br /&gt;
 roman_string.to_s.upcase.split(//).reverse.inject(0) do&lt;br /&gt;
 |memo, digit|&lt;br /&gt;
 if digit_value = DIGITS[digit]&lt;br /&gt;
 if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
 memo -= digit_value&lt;br /&gt;
 else&lt;br /&gt;
 memo += digit_value&lt;br /&gt;
 end&lt;br /&gt;
 last = digit_value&lt;br /&gt;
 end&lt;br /&gt;
 memo&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def method_missing(method)&lt;br /&gt;
 str=method.id2name&lt;br /&gt;
 roman_to_integer(str)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calling the undefined methods&lt;br /&gt;
&lt;br /&gt;
 r= Roman.new&lt;br /&gt;
 r.vii&lt;br /&gt;
 r.xxix&lt;br /&gt;
 r.xxiv&lt;br /&gt;
 r.xxvi&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The Output&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; 7&lt;br /&gt;
 =&amp;gt; 29&lt;br /&gt;
 =&amp;gt; 24&lt;br /&gt;
&lt;br /&gt;
===method_missing to Log Method Calls&amp;lt;ref&amp;gt;http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2007/wiki1b_2_22&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Another application that makes use of method_missing could be a simple logger used for debugging purposes. Many times, it may be required to log the trace of called methods and provide information such as: called method-name, arguments, return type. It can be tedious to repeat this part of code in every method. A simple solution to this problem can be obtained using method_missing as:&lt;br /&gt;
&lt;br /&gt;
  class SimpleCallLogger&lt;br /&gt;
  def initialize(o)&lt;br /&gt;
  @obj = o&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(methodname, *args)&lt;br /&gt;
  puts &amp;quot;called: #{methodname}(#{args})&amp;quot;&lt;br /&gt;
  a = @obj.send(methodname, *args)&lt;br /&gt;
  puts &amp;quot;\t-&amp;gt; returned: #{a}&amp;quot;&lt;br /&gt;
  return a&lt;br /&gt;
  end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
This program makes use of method_missing in a way that it wraps around called method to output the logging information on entry and on exit, it logs the return type. Further, method_missing intercepts the method call and forward it to internal object with ‘send’ method of ruby. Hence, this use of method_missing acts as wrapper.&lt;br /&gt;
&lt;br /&gt;
===Generic Handler===&lt;br /&gt;
 class NoBar&lt;br /&gt;
 def method_missing(methodname, *args)&lt;br /&gt;
 define_method(:bar) if &amp;quot;bar&amp;quot; == methodname.to_s&lt;br /&gt;
 define_method(:nobar) if &amp;quot;nobar&amp;quot; == methodname.to_s&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This is an example of using method_missing as a generic handler to handle when a calling method is not exist. You can use missing_method to dynamically create a method at a runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Advantages of method_missing'''==&lt;br /&gt;
&lt;br /&gt;
*In addition to specifying the error messages for the undefined methods, method_missing provides a more dynamic behavior in the programming environment.&lt;br /&gt;
*If we are unfamiliar with the usage of the objects we created, then using method_missing is a good technique.&lt;br /&gt;
*Handles problems at runtime.&lt;br /&gt;
*Define's a generic method_missing and handle's any undefined method, a big advantage over Java. In Java, when you call an undefined method, the program will not compile.&lt;br /&gt;
*method_missing falls under the general technique of [http://en.wikipedia.org/wiki/Metaprogramming meta-programming]. Employ meta-programming in missing_function to write an another function to handle the call.&lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages of method_missing'''==	&lt;br /&gt;
*Slower than conventional method lookup. Simple tests indicate that method dispatch with method_missing is at least two to three times as expensive in time as conventional dispatch.&lt;br /&gt;
&lt;br /&gt;
*Since the methods being called never actually exist—they are just intercepted at the last step of the method lookup process—they cannot be documented or introspected as conventional methods can.&lt;br /&gt;
&lt;br /&gt;
*method_missing restricts compatibility with future versions of an [http://en.wikipedia.org/wiki/Application_programming_interface API]. Introducing new methods in a future API version can break users' expectations.&lt;br /&gt;
&lt;br /&gt;
=='''Key Points'''==&lt;br /&gt;
&lt;br /&gt;
*In the example below, class A defines only method method_missing() and no other method. When a new object of class A tries to access a method say 'foo', the respond_to? will return the value 'false'. When you actually try to implement it using “a.foo”, the code will get executed, courtesy of method_missing(). Even though the respond_to? says that you cannot access 'foo' method using object of class A, if you have method_missing() defined, you can access the method.&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In method_missing&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)&lt;br /&gt;
 a.foo&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 false&lt;br /&gt;
 In method_missing&lt;br /&gt;
&lt;br /&gt;
*In the following example, if within method_missing() we define an undefined method. &lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 @@i = 0&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In Method Missing #{@@i}&amp;quot;&lt;br /&gt;
 @@i += 1&lt;br /&gt;
 self.fun&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 a.foo &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 The result is a 'stack level too deep' error. &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
When the 'foo' method is called, after no method match the method_missing is run and this block has a method “self.fun” that is undefined.     Here when the program execution encounters 'self.fun' it once again calls method_missing. This goes on in an endless loop till the stack memory is full.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Ruby knows method_missing( ) exists, because it's a private instance method of 'BasicObject' that every object inherits. The BasicObject#method_missing( ) responds by raising the NoMethodError. Overriding this method_missing( ) allows you to call methods that don't really exist. &lt;br /&gt;
&lt;br /&gt;
*If method_missing is only looking for certain method names, don't forget to call the [http://en.wikibooks.org/wiki/Java_Programming/Keywords/super super] keyword if you haven't found what you're looking for, so that the other superclass' method_missing can handle it.&lt;br /&gt;
&lt;br /&gt;
*[http://www.prateekdayal.net/2007/10/16/rubys-responds_to-for-checking-if-a-method-exists/ obj.respond_to?] function returns 'true' if the obj responds to the given method. So if you want to know whether your class will respond to a function you can use respond_to? to know the answer. But if method_missing() is used, the output may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
*http://www.rubyinside.com/ &lt;br /&gt;
*https://www.youtube.com/watch?v=SAEiCkixrdE&amp;amp;feature=relmfu&lt;br /&gt;
*http://blog.jayfields.com/2008/02/ruby-replace-methodmissing-with-dynamic.html &lt;br /&gt;
*http://liquiddevelopment.blogspot.com/2006/04/twisting-and-shaping-dsls-using-ruby.html &lt;br /&gt;
*http://blog.rubybestpractices.com/posts/gregory/031-issue-2-method-lookup.html&lt;br /&gt;
*http://phrogz.net/RubyLibs/RubyMethodLookupFlow.pdf(Diagram)&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65306</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w22 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65306"/>
		<updated>2012-09-19T23:49:24Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* Further Suggested Reading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
=='''Introduction&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_method_missing.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
A method of a class is called by creating an object of the class and passing the method name to the object as a message. The object then looks up into its [http://www.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html method lookup path] and tries to match the called method with the defined methods in the class. On success, the method is executed along with the parameters passed and the result is returned.&lt;br /&gt;
&lt;br /&gt;
If the object does not find a match in its method lookup, in normal circumstances the [http://www.ruby-doc.org/core-1.9.3/NoMethodError.html NoMethodError Exception] is raised .&lt;br /&gt;
&lt;br /&gt;
In cases where the user wants to handle the methods which are not defined but still called, “method_missing” can be defined and the user can handle the methods as he/she sees fit.&lt;br /&gt;
&lt;br /&gt;
=='''Format for Defining method_missing'''==&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; def method_missing(m,*args,&amp;amp;block)&lt;br /&gt;
&lt;br /&gt;
(i) '''m-&amp;gt;''' accepts the symbol/name of the undefined method (ii) '''*args-&amp;gt;''' accepts the array of arguments passed in the method call  (iii) '''&amp;amp;block-&amp;gt;'''accepts a block passed to the method&lt;br /&gt;
&lt;br /&gt;
=='''Ruby Method Lookup Flow'''==&lt;br /&gt;
When the object of a class receives a method name to be executed, the following steps are carried out for matching and executing the method:&lt;br /&gt;
&lt;br /&gt;
*First, the object looks in its own [http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html instance methods].&lt;br /&gt;
*Second, it looks in the list of instance methods that all objects of that class share.&lt;br /&gt;
*Third, in each of the included [http://www.tutorialspoint.com/ruby/ruby_modules.html modules] of that class, in reverse order of inclusion. &lt;br /&gt;
*Fourth, it looks in that class’s superclass. &lt;br /&gt;
*Fifth, in the superclass’s included modules, all the way up until it reaches the class Object. &lt;br /&gt;
*Sixth, if it still can’t find a method, the very last place it looks is in the [http://linux.die.net/lkmpg/x40.html Kernel module], included in the class Object. &lt;br /&gt;
*Finally, it calls method_missing (if defined in the class), else throws up the NOMethodError exception.&lt;br /&gt;
&lt;br /&gt;
This entire tracing that the object does is the method lookup path.&lt;br /&gt;
&lt;br /&gt;
=='''Examples'''==&lt;br /&gt;
===Calling Defined and Undefined Methods===&lt;br /&gt;
&lt;br /&gt;
 class A		// creating a class 'A'&lt;br /&gt;
 def say		// defining a method 'say'&lt;br /&gt;
 puts &amp;quot; say Hi &amp;quot; // body of method say&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Creating the object of the class&lt;br /&gt;
 &lt;br /&gt;
  a=A.new	       // object of the class&lt;br /&gt;
  =&amp;gt; #&amp;lt;A:0x2a082e0&amp;gt;     //object id&lt;br /&gt;
&lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.say                  // defined method&lt;br /&gt;
 =&amp;gt; say Hi	       // returned result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.sayhi                // undefined method sayhi&lt;br /&gt;
 NoMethodError: undefined method `sayhi' for #&amp;lt;A:0x2a082e0&amp;gt;   // the NoMethodError is raised&lt;br /&gt;
&lt;br /&gt;
===method_missing Implementation&amp;lt;ref&amp;gt;http://www.thirdbit.net/articles/2007/08/01/10-things-you-should-know-about-method_missing/&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def say&lt;br /&gt;
 puts &amp;quot; say hi &amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(m,*args,&amp;amp;block)	// defining method_missing&lt;br /&gt;
 puts &amp;quot; This method does not exist&amp;quot;	// body of method_missing&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Calling a method that is not defined&lt;br /&gt;
 &lt;br /&gt;
 a=A.new&lt;br /&gt;
 a.sayhi                                // calling the undefined method sayhi with no arguments&lt;br /&gt;
 =&amp;gt; This method does not exist		// this result returned when method_missing is executed&lt;br /&gt;
&lt;br /&gt;
When the object 'a' traces its method lookup path for a matching method as 'sayhi', upon failure it resorts to method_missing and the body of method_missing is executed. 'method_missing' is the last resort.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Sometimes when a class has many methods that do generally the same kinds of things, and the programmer is not sure in advance which methods the user will call since there are so many of them, and they are all so similar, writing code for all of them seems futile. In these situations method_missing can be defined to take care of different cases. The below 'Generic Handler' example implements this.&lt;br /&gt;
&lt;br /&gt;
===Passing Parameters to an Undefined Method Call===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def add(a,b)&lt;br /&gt;
 a+b&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(name,*args,&amp;amp;block)    // the method_missing is defined and the *args parameter accepts all the parameters passed during 								                                 &lt;br /&gt;
                                             the method call   &lt;br /&gt;
 puts “You have typed the method name wrong and these were the parameters passed ; #{args[0]}, #{args[1]}”								&lt;br /&gt;
 end                         			&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The passed parameters are stored in the array 'args' and can be accessed like a normal array                &lt;br /&gt;
                                                   &lt;br /&gt;
 &lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.add(1,2)		        // calling the defined method add and passing the parameters (1,2)&lt;br /&gt;
 =&amp;gt; 3                           // result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.adds(4,2) 			// calling the undefined method adds and passing the parameter (4,2)&lt;br /&gt;
 =&amp;gt; You have typed the method name wrong and these were the parameters passed; 4, 2&lt;br /&gt;
&lt;br /&gt;
The user made a genuine mistake by typing 'adds', but this method is not defined. When the 'adds' method with parameters is called, the object 'a' tries to match the method in the method lookup path. Upon failure it invokes method_missing, the args are passed, stored in the array 'args' and the body of method_missing is executed.&lt;br /&gt;
&lt;br /&gt;
===Converting Numbers from Roman Representation to Integer Representation&amp;lt;ref&amp;gt;http://courses.ncsu.edu/csc517/common/lectures/notes/wk2.pdf&amp;lt;/ref&amp;gt;===&lt;br /&gt;
 class Roman&lt;br /&gt;
 DIGITS = {'I'=&amp;gt;1,'V'=&amp;gt;5,'X'=&amp;gt;10,'L'=&amp;gt;50,'C'=&amp;gt;100,'D'=&amp;gt;500,'M'=&amp;gt;1000,}&lt;br /&gt;
 def roman_to_integer(roman_string)&lt;br /&gt;
 last = nil&lt;br /&gt;
 roman_string.to_s.upcase.split(//).reverse.inject(0) do&lt;br /&gt;
 |memo, digit|&lt;br /&gt;
 if digit_value = DIGITS[digit]&lt;br /&gt;
 if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
 memo -= digit_value&lt;br /&gt;
 else&lt;br /&gt;
 memo += digit_value&lt;br /&gt;
 end&lt;br /&gt;
 last = digit_value&lt;br /&gt;
 end&lt;br /&gt;
 memo&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def method_missing(method)&lt;br /&gt;
 str=method.id2name&lt;br /&gt;
 roman_to_integer(str)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calling the undefined methods&lt;br /&gt;
&lt;br /&gt;
 r= Roman.new&lt;br /&gt;
 r.vii&lt;br /&gt;
 r.xxix&lt;br /&gt;
 r.xxiv&lt;br /&gt;
 r.xxvi&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The Output&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; 7&lt;br /&gt;
 =&amp;gt; 29&lt;br /&gt;
 =&amp;gt; 24&lt;br /&gt;
&lt;br /&gt;
===method_missing to Log Method Calls&amp;lt;ref&amp;gt;http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2007/wiki1b_2_22&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Another application that makes use of method_missing could be a simple logger used for debugging purposes. Many times, it may be required to log the trace of called methods and provide information such as: called method-name, arguments, return type. It can be tedious to repeat this part of code in every method. A simple solution to this problem can be obtained using method_missing as:&lt;br /&gt;
&lt;br /&gt;
  class SimpleCallLogger&lt;br /&gt;
  def initialize(o)&lt;br /&gt;
  @obj = o&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(methodname, *args)&lt;br /&gt;
  puts &amp;quot;called: #{methodname}(#{args})&amp;quot;&lt;br /&gt;
  a = @obj.send(methodname, *args)&lt;br /&gt;
  puts &amp;quot;\t-&amp;gt; returned: #{a}&amp;quot;&lt;br /&gt;
  return a&lt;br /&gt;
  end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
This program makes use of method_missing in a way that it wraps around called method to output the logging information on entry and on exit, it logs the return type. Further, method_missing intercepts the method call and forward it to internal object with ‘send’ method of ruby. Hence, this use of method_missing acts as wrapper.&lt;br /&gt;
&lt;br /&gt;
===Generic Handler===&lt;br /&gt;
 class NoBar&lt;br /&gt;
 def method_missing(methodname, *args)&lt;br /&gt;
 define_method(:bar) if &amp;quot;bar&amp;quot; == methodname.to_s&lt;br /&gt;
 define_method(:nobar) if &amp;quot;nobar&amp;quot; == methodname.to_s&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This is an example of using method_missing as a generic handler to handle when a calling method is not exist. You can use missing_method to dynamically create a method at a runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Advantages of method_missing'''==&lt;br /&gt;
&lt;br /&gt;
*In addition to specifying the error messages for the undefined methods, method_missing provides a more dynamic behavior in the programming environment.&lt;br /&gt;
*If we are unfamiliar with the usage of the objects we created, then using method_missing is a good technique.&lt;br /&gt;
*Handles problems at runtime.&lt;br /&gt;
*Define's a generic method_missing and handle's any undefined method, a big advantage over Java. In Java, when you call an undefined method, the program will not compile.&lt;br /&gt;
*method_missing falls under the general technique of [http://en.wikipedia.org/wiki/Metaprogramming meta-programming]. Employ meta-programming in missing_function to write an another function to handle the call.&lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages of method_missing'''==	&lt;br /&gt;
*Slower than conventional method lookup. Simple tests indicate that method dispatch with method_missing is at least two to three times as expensive in time as conventional dispatch.&lt;br /&gt;
&lt;br /&gt;
*Since the methods being called never actually exist—they are just intercepted at the last step of the method lookup process—they cannot be documented or introspected as conventional methods can.&lt;br /&gt;
&lt;br /&gt;
*method_missing restricts compatibility with future versions of an [http://en.wikipedia.org/wiki/Application_programming_interface API]. Introducing new methods in a future API version can break users' expectations.&lt;br /&gt;
&lt;br /&gt;
=='''Key Points'''==&lt;br /&gt;
&lt;br /&gt;
*In the example below, class A defines only method method_missing() and no other method. When a new object of class A tries to access a method say 'foo', the respond_to? will return the value 'false'. When you actually try to implement it using “a.foo”, the code will get executed, courtesy of method_missing(). Even though the respond_to? says that you cannot access 'foo' method using object of class A, if you have method_missing() defined, you can access the method.&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In method_missing&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)&lt;br /&gt;
 a.foo&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 false&lt;br /&gt;
 In method_missing&lt;br /&gt;
&lt;br /&gt;
*In the following example, if within method_missing() we define an undefined method. &lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 @@i = 0&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In Method Missing #{@@i}&amp;quot;&lt;br /&gt;
 @@i += 1&lt;br /&gt;
 self.fun&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 a.foo &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 The result is a 'stack level too deep' error. &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
When the 'foo' method is called, after no method match the method_missing is run and this block has a method “self.fun” that is undefined.     Here when the program execution encounters 'self.fun' it once again calls method_missing. This goes on in an endless loop till the stack memory is full.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Ruby knows method_missing( ) exists, because it's a private instance method of 'BasicObject' that every object inherits. The BasicObject#method_missing( ) responds by raising the NoMethodError. Overriding this method_missing( ) allows you to call methods that don't really exist. &lt;br /&gt;
&lt;br /&gt;
*If method_missing is only looking for certain method names, don't forget to call the [http://en.wikibooks.org/wiki/Java_Programming/Keywords/super super] keyword if you haven't found what you're looking for, so that the other superclass' method_missing can handle it.&lt;br /&gt;
&lt;br /&gt;
*[http://www.prateekdayal.net/2007/10/16/rubys-responds_to-for-checking-if-a-method-exists/ obj.respond_to?] function returns 'true' if the obj responds to the given method. So if you want to know whether your class will respond to a function you can use respond_to? to know the answer. But if method_missing() is used, the output may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
*http://www.rubyinside.com/ &lt;br /&gt;
*https://www.youtube.com/watch?v=SAEiCkixrdE&amp;amp;feature=relmfu&lt;br /&gt;
*http://blog.jayfields.com/2008/02/ruby-replace-methodmissing-with-dynamic.html &lt;br /&gt;
*http://liquiddevelopment.blogspot.com/2006/04/twisting-and-shaping-dsls-using-ruby.html &lt;br /&gt;
*http://blog.rubybestpractices.com/posts/gregory/031-issue-2-method-lookup.html&lt;br /&gt;
*http://phrogz.net/RubyLibs/RubyMethodLookupFlow.pdf(Diagram)&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65305</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w22 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65305"/>
		<updated>2012-09-19T23:49:11Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* Further Suggested Reading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
=='''Introduction&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_method_missing.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
A method of a class is called by creating an object of the class and passing the method name to the object as a message. The object then looks up into its [http://www.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html method lookup path] and tries to match the called method with the defined methods in the class. On success, the method is executed along with the parameters passed and the result is returned.&lt;br /&gt;
&lt;br /&gt;
If the object does not find a match in its method lookup, in normal circumstances the [http://www.ruby-doc.org/core-1.9.3/NoMethodError.html NoMethodError Exception] is raised .&lt;br /&gt;
&lt;br /&gt;
In cases where the user wants to handle the methods which are not defined but still called, “method_missing” can be defined and the user can handle the methods as he/she sees fit.&lt;br /&gt;
&lt;br /&gt;
=='''Format for Defining method_missing'''==&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; def method_missing(m,*args,&amp;amp;block)&lt;br /&gt;
&lt;br /&gt;
(i) '''m-&amp;gt;''' accepts the symbol/name of the undefined method (ii) '''*args-&amp;gt;''' accepts the array of arguments passed in the method call  (iii) '''&amp;amp;block-&amp;gt;'''accepts a block passed to the method&lt;br /&gt;
&lt;br /&gt;
=='''Ruby Method Lookup Flow'''==&lt;br /&gt;
When the object of a class receives a method name to be executed, the following steps are carried out for matching and executing the method:&lt;br /&gt;
&lt;br /&gt;
*First, the object looks in its own [http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html instance methods].&lt;br /&gt;
*Second, it looks in the list of instance methods that all objects of that class share.&lt;br /&gt;
*Third, in each of the included [http://www.tutorialspoint.com/ruby/ruby_modules.html modules] of that class, in reverse order of inclusion. &lt;br /&gt;
*Fourth, it looks in that class’s superclass. &lt;br /&gt;
*Fifth, in the superclass’s included modules, all the way up until it reaches the class Object. &lt;br /&gt;
*Sixth, if it still can’t find a method, the very last place it looks is in the [http://linux.die.net/lkmpg/x40.html Kernel module], included in the class Object. &lt;br /&gt;
*Finally, it calls method_missing (if defined in the class), else throws up the NOMethodError exception.&lt;br /&gt;
&lt;br /&gt;
This entire tracing that the object does is the method lookup path.&lt;br /&gt;
&lt;br /&gt;
=='''Examples'''==&lt;br /&gt;
===Calling Defined and Undefined Methods===&lt;br /&gt;
&lt;br /&gt;
 class A		// creating a class 'A'&lt;br /&gt;
 def say		// defining a method 'say'&lt;br /&gt;
 puts &amp;quot; say Hi &amp;quot; // body of method say&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Creating the object of the class&lt;br /&gt;
 &lt;br /&gt;
  a=A.new	       // object of the class&lt;br /&gt;
  =&amp;gt; #&amp;lt;A:0x2a082e0&amp;gt;     //object id&lt;br /&gt;
&lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.say                  // defined method&lt;br /&gt;
 =&amp;gt; say Hi	       // returned result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.sayhi                // undefined method sayhi&lt;br /&gt;
 NoMethodError: undefined method `sayhi' for #&amp;lt;A:0x2a082e0&amp;gt;   // the NoMethodError is raised&lt;br /&gt;
&lt;br /&gt;
===method_missing Implementation&amp;lt;ref&amp;gt;http://www.thirdbit.net/articles/2007/08/01/10-things-you-should-know-about-method_missing/&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def say&lt;br /&gt;
 puts &amp;quot; say hi &amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(m,*args,&amp;amp;block)	// defining method_missing&lt;br /&gt;
 puts &amp;quot; This method does not exist&amp;quot;	// body of method_missing&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Calling a method that is not defined&lt;br /&gt;
 &lt;br /&gt;
 a=A.new&lt;br /&gt;
 a.sayhi                                // calling the undefined method sayhi with no arguments&lt;br /&gt;
 =&amp;gt; This method does not exist		// this result returned when method_missing is executed&lt;br /&gt;
&lt;br /&gt;
When the object 'a' traces its method lookup path for a matching method as 'sayhi', upon failure it resorts to method_missing and the body of method_missing is executed. 'method_missing' is the last resort.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Sometimes when a class has many methods that do generally the same kinds of things, and the programmer is not sure in advance which methods the user will call since there are so many of them, and they are all so similar, writing code for all of them seems futile. In these situations method_missing can be defined to take care of different cases. The below 'Generic Handler' example implements this.&lt;br /&gt;
&lt;br /&gt;
===Passing Parameters to an Undefined Method Call===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def add(a,b)&lt;br /&gt;
 a+b&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(name,*args,&amp;amp;block)    // the method_missing is defined and the *args parameter accepts all the parameters passed during 								                                 &lt;br /&gt;
                                             the method call   &lt;br /&gt;
 puts “You have typed the method name wrong and these were the parameters passed ; #{args[0]}, #{args[1]}”								&lt;br /&gt;
 end                         			&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The passed parameters are stored in the array 'args' and can be accessed like a normal array                &lt;br /&gt;
                                                   &lt;br /&gt;
 &lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.add(1,2)		        // calling the defined method add and passing the parameters (1,2)&lt;br /&gt;
 =&amp;gt; 3                           // result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.adds(4,2) 			// calling the undefined method adds and passing the parameter (4,2)&lt;br /&gt;
 =&amp;gt; You have typed the method name wrong and these were the parameters passed; 4, 2&lt;br /&gt;
&lt;br /&gt;
The user made a genuine mistake by typing 'adds', but this method is not defined. When the 'adds' method with parameters is called, the object 'a' tries to match the method in the method lookup path. Upon failure it invokes method_missing, the args are passed, stored in the array 'args' and the body of method_missing is executed.&lt;br /&gt;
&lt;br /&gt;
===Converting Numbers from Roman Representation to Integer Representation&amp;lt;ref&amp;gt;http://courses.ncsu.edu/csc517/common/lectures/notes/wk2.pdf&amp;lt;/ref&amp;gt;===&lt;br /&gt;
 class Roman&lt;br /&gt;
 DIGITS = {'I'=&amp;gt;1,'V'=&amp;gt;5,'X'=&amp;gt;10,'L'=&amp;gt;50,'C'=&amp;gt;100,'D'=&amp;gt;500,'M'=&amp;gt;1000,}&lt;br /&gt;
 def roman_to_integer(roman_string)&lt;br /&gt;
 last = nil&lt;br /&gt;
 roman_string.to_s.upcase.split(//).reverse.inject(0) do&lt;br /&gt;
 |memo, digit|&lt;br /&gt;
 if digit_value = DIGITS[digit]&lt;br /&gt;
 if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
 memo -= digit_value&lt;br /&gt;
 else&lt;br /&gt;
 memo += digit_value&lt;br /&gt;
 end&lt;br /&gt;
 last = digit_value&lt;br /&gt;
 end&lt;br /&gt;
 memo&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def method_missing(method)&lt;br /&gt;
 str=method.id2name&lt;br /&gt;
 roman_to_integer(str)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calling the undefined methods&lt;br /&gt;
&lt;br /&gt;
 r= Roman.new&lt;br /&gt;
 r.vii&lt;br /&gt;
 r.xxix&lt;br /&gt;
 r.xxiv&lt;br /&gt;
 r.xxvi&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The Output&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; 7&lt;br /&gt;
 =&amp;gt; 29&lt;br /&gt;
 =&amp;gt; 24&lt;br /&gt;
&lt;br /&gt;
===method_missing to Log Method Calls&amp;lt;ref&amp;gt;http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2007/wiki1b_2_22&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Another application that makes use of method_missing could be a simple logger used for debugging purposes. Many times, it may be required to log the trace of called methods and provide information such as: called method-name, arguments, return type. It can be tedious to repeat this part of code in every method. A simple solution to this problem can be obtained using method_missing as:&lt;br /&gt;
&lt;br /&gt;
  class SimpleCallLogger&lt;br /&gt;
  def initialize(o)&lt;br /&gt;
  @obj = o&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(methodname, *args)&lt;br /&gt;
  puts &amp;quot;called: #{methodname}(#{args})&amp;quot;&lt;br /&gt;
  a = @obj.send(methodname, *args)&lt;br /&gt;
  puts &amp;quot;\t-&amp;gt; returned: #{a}&amp;quot;&lt;br /&gt;
  return a&lt;br /&gt;
  end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
This program makes use of method_missing in a way that it wraps around called method to output the logging information on entry and on exit, it logs the return type. Further, method_missing intercepts the method call and forward it to internal object with ‘send’ method of ruby. Hence, this use of method_missing acts as wrapper.&lt;br /&gt;
&lt;br /&gt;
===Generic Handler===&lt;br /&gt;
 class NoBar&lt;br /&gt;
 def method_missing(methodname, *args)&lt;br /&gt;
 define_method(:bar) if &amp;quot;bar&amp;quot; == methodname.to_s&lt;br /&gt;
 define_method(:nobar) if &amp;quot;nobar&amp;quot; == methodname.to_s&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This is an example of using method_missing as a generic handler to handle when a calling method is not exist. You can use missing_method to dynamically create a method at a runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Advantages of method_missing'''==&lt;br /&gt;
&lt;br /&gt;
*In addition to specifying the error messages for the undefined methods, method_missing provides a more dynamic behavior in the programming environment.&lt;br /&gt;
*If we are unfamiliar with the usage of the objects we created, then using method_missing is a good technique.&lt;br /&gt;
*Handles problems at runtime.&lt;br /&gt;
*Define's a generic method_missing and handle's any undefined method, a big advantage over Java. In Java, when you call an undefined method, the program will not compile.&lt;br /&gt;
*method_missing falls under the general technique of [http://en.wikipedia.org/wiki/Metaprogramming meta-programming]. Employ meta-programming in missing_function to write an another function to handle the call.&lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages of method_missing'''==	&lt;br /&gt;
*Slower than conventional method lookup. Simple tests indicate that method dispatch with method_missing is at least two to three times as expensive in time as conventional dispatch.&lt;br /&gt;
&lt;br /&gt;
*Since the methods being called never actually exist—they are just intercepted at the last step of the method lookup process—they cannot be documented or introspected as conventional methods can.&lt;br /&gt;
&lt;br /&gt;
*method_missing restricts compatibility with future versions of an [http://en.wikipedia.org/wiki/Application_programming_interface API]. Introducing new methods in a future API version can break users' expectations.&lt;br /&gt;
&lt;br /&gt;
=='''Key Points'''==&lt;br /&gt;
&lt;br /&gt;
*In the example below, class A defines only method method_missing() and no other method. When a new object of class A tries to access a method say 'foo', the respond_to? will return the value 'false'. When you actually try to implement it using “a.foo”, the code will get executed, courtesy of method_missing(). Even though the respond_to? says that you cannot access 'foo' method using object of class A, if you have method_missing() defined, you can access the method.&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In method_missing&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)&lt;br /&gt;
 a.foo&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 false&lt;br /&gt;
 In method_missing&lt;br /&gt;
&lt;br /&gt;
*In the following example, if within method_missing() we define an undefined method. &lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 @@i = 0&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In Method Missing #{@@i}&amp;quot;&lt;br /&gt;
 @@i += 1&lt;br /&gt;
 self.fun&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 a.foo &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 The result is a 'stack level too deep' error. &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
When the 'foo' method is called, after no method match the method_missing is run and this block has a method “self.fun” that is undefined.     Here when the program execution encounters 'self.fun' it once again calls method_missing. This goes on in an endless loop till the stack memory is full.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Ruby knows method_missing( ) exists, because it's a private instance method of 'BasicObject' that every object inherits. The BasicObject#method_missing( ) responds by raising the NoMethodError. Overriding this method_missing( ) allows you to call methods that don't really exist. &lt;br /&gt;
&lt;br /&gt;
*If method_missing is only looking for certain method names, don't forget to call the [http://en.wikibooks.org/wiki/Java_Programming/Keywords/super super] keyword if you haven't found what you're looking for, so that the other superclass' method_missing can handle it.&lt;br /&gt;
&lt;br /&gt;
*[http://www.prateekdayal.net/2007/10/16/rubys-responds_to-for-checking-if-a-method-exists/ obj.respond_to?] function returns 'true' if the obj responds to the given method. So if you want to know whether your class will respond to a function you can use respond_to? to know the answer. But if method_missing() is used, the output may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
*http://www.rubyinside.com/ &lt;br /&gt;
*https://www.youtube.com/watch?v=SAEiCkixrdE&amp;amp;feature=relmfu&lt;br /&gt;
*http://blog.jayfields.com/2008/02/ruby-replace-methodmissing-with-dynamic.html &lt;br /&gt;
*http://liquiddevelopment.blogspot.com/2006/04/twisting-and-shaping-dsls-using-ruby.html &lt;br /&gt;
*http://blog.rubybestpractices.com/posts/gregory/031-issue-2-method-lookup.html&lt;br /&gt;
*http://phrogz.net/RubyLibs/RubyMethodLookupFlow.pdf (Diagram)&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65304</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w22 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65304"/>
		<updated>2012-09-19T23:47:51Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* Calling defined and undefined Methods */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
=='''Introduction&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_method_missing.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
A method of a class is called by creating an object of the class and passing the method name to the object as a message. The object then looks up into its [http://www.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html method lookup path] and tries to match the called method with the defined methods in the class. On success, the method is executed along with the parameters passed and the result is returned.&lt;br /&gt;
&lt;br /&gt;
If the object does not find a match in its method lookup, in normal circumstances the [http://www.ruby-doc.org/core-1.9.3/NoMethodError.html NoMethodError Exception] is raised .&lt;br /&gt;
&lt;br /&gt;
In cases where the user wants to handle the methods which are not defined but still called, “method_missing” can be defined and the user can handle the methods as he/she sees fit.&lt;br /&gt;
&lt;br /&gt;
=='''Format for Defining method_missing'''==&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; def method_missing(m,*args,&amp;amp;block)&lt;br /&gt;
&lt;br /&gt;
(i) '''m-&amp;gt;''' accepts the symbol/name of the undefined method (ii) '''*args-&amp;gt;''' accepts the array of arguments passed in the method call  (iii) '''&amp;amp;block-&amp;gt;'''accepts a block passed to the method&lt;br /&gt;
&lt;br /&gt;
=='''Ruby Method Lookup Flow'''==&lt;br /&gt;
When the object of a class receives a method name to be executed, the following steps are carried out for matching and executing the method:&lt;br /&gt;
&lt;br /&gt;
*First, the object looks in its own [http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html instance methods].&lt;br /&gt;
*Second, it looks in the list of instance methods that all objects of that class share.&lt;br /&gt;
*Third, in each of the included [http://www.tutorialspoint.com/ruby/ruby_modules.html modules] of that class, in reverse order of inclusion. &lt;br /&gt;
*Fourth, it looks in that class’s superclass. &lt;br /&gt;
*Fifth, in the superclass’s included modules, all the way up until it reaches the class Object. &lt;br /&gt;
*Sixth, if it still can’t find a method, the very last place it looks is in the [http://linux.die.net/lkmpg/x40.html Kernel module], included in the class Object. &lt;br /&gt;
*Finally, it calls method_missing (if defined in the class), else throws up the NOMethodError exception.&lt;br /&gt;
&lt;br /&gt;
This entire tracing that the object does is the method lookup path.&lt;br /&gt;
&lt;br /&gt;
=='''Examples'''==&lt;br /&gt;
===Calling Defined and Undefined Methods===&lt;br /&gt;
&lt;br /&gt;
 class A		// creating a class 'A'&lt;br /&gt;
 def say		// defining a method 'say'&lt;br /&gt;
 puts &amp;quot; say Hi &amp;quot; // body of method say&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Creating the object of the class&lt;br /&gt;
 &lt;br /&gt;
  a=A.new	       // object of the class&lt;br /&gt;
  =&amp;gt; #&amp;lt;A:0x2a082e0&amp;gt;     //object id&lt;br /&gt;
&lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.say                  // defined method&lt;br /&gt;
 =&amp;gt; say Hi	       // returned result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.sayhi                // undefined method sayhi&lt;br /&gt;
 NoMethodError: undefined method `sayhi' for #&amp;lt;A:0x2a082e0&amp;gt;   // the NoMethodError is raised&lt;br /&gt;
&lt;br /&gt;
===method_missing Implementation&amp;lt;ref&amp;gt;http://www.thirdbit.net/articles/2007/08/01/10-things-you-should-know-about-method_missing/&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def say&lt;br /&gt;
 puts &amp;quot; say hi &amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(m,*args,&amp;amp;block)	// defining method_missing&lt;br /&gt;
 puts &amp;quot; This method does not exist&amp;quot;	// body of method_missing&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Calling a method that is not defined&lt;br /&gt;
 &lt;br /&gt;
 a=A.new&lt;br /&gt;
 a.sayhi                                // calling the undefined method sayhi with no arguments&lt;br /&gt;
 =&amp;gt; This method does not exist		// this result returned when method_missing is executed&lt;br /&gt;
&lt;br /&gt;
When the object 'a' traces its method lookup path for a matching method as 'sayhi', upon failure it resorts to method_missing and the body of method_missing is executed. 'method_missing' is the last resort.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Sometimes when a class has many methods that do generally the same kinds of things, and the programmer is not sure in advance which methods the user will call since there are so many of them, and they are all so similar, writing code for all of them seems futile. In these situations method_missing can be defined to take care of different cases. The below 'Generic Handler' example implements this.&lt;br /&gt;
&lt;br /&gt;
===Passing Parameters to an Undefined Method Call===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def add(a,b)&lt;br /&gt;
 a+b&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(name,*args,&amp;amp;block)    // the method_missing is defined and the *args parameter accepts all the parameters passed during 								                                 &lt;br /&gt;
                                             the method call   &lt;br /&gt;
 puts “You have typed the method name wrong and these were the parameters passed ; #{args[0]}, #{args[1]}”								&lt;br /&gt;
 end                         			&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The passed parameters are stored in the array 'args' and can be accessed like a normal array                &lt;br /&gt;
                                                   &lt;br /&gt;
 &lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.add(1,2)		        // calling the defined method add and passing the parameters (1,2)&lt;br /&gt;
 =&amp;gt; 3                           // result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.adds(4,2) 			// calling the undefined method adds and passing the parameter (4,2)&lt;br /&gt;
 =&amp;gt; You have typed the method name wrong and these were the parameters passed; 4, 2&lt;br /&gt;
&lt;br /&gt;
The user made a genuine mistake by typing 'adds', but this method is not defined. When the 'adds' method with parameters is called, the object 'a' tries to match the method in the method lookup path. Upon failure it invokes method_missing, the args are passed, stored in the array 'args' and the body of method_missing is executed.&lt;br /&gt;
&lt;br /&gt;
===Converting Numbers from Roman Representation to Integer Representation&amp;lt;ref&amp;gt;http://courses.ncsu.edu/csc517/common/lectures/notes/wk2.pdf&amp;lt;/ref&amp;gt;===&lt;br /&gt;
 class Roman&lt;br /&gt;
 DIGITS = {'I'=&amp;gt;1,'V'=&amp;gt;5,'X'=&amp;gt;10,'L'=&amp;gt;50,'C'=&amp;gt;100,'D'=&amp;gt;500,'M'=&amp;gt;1000,}&lt;br /&gt;
 def roman_to_integer(roman_string)&lt;br /&gt;
 last = nil&lt;br /&gt;
 roman_string.to_s.upcase.split(//).reverse.inject(0) do&lt;br /&gt;
 |memo, digit|&lt;br /&gt;
 if digit_value = DIGITS[digit]&lt;br /&gt;
 if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
 memo -= digit_value&lt;br /&gt;
 else&lt;br /&gt;
 memo += digit_value&lt;br /&gt;
 end&lt;br /&gt;
 last = digit_value&lt;br /&gt;
 end&lt;br /&gt;
 memo&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def method_missing(method)&lt;br /&gt;
 str=method.id2name&lt;br /&gt;
 roman_to_integer(str)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calling the undefined methods&lt;br /&gt;
&lt;br /&gt;
 r= Roman.new&lt;br /&gt;
 r.vii&lt;br /&gt;
 r.xxix&lt;br /&gt;
 r.xxiv&lt;br /&gt;
 r.xxvi&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The Output&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; 7&lt;br /&gt;
 =&amp;gt; 29&lt;br /&gt;
 =&amp;gt; 24&lt;br /&gt;
&lt;br /&gt;
===method_missing to Log Method Calls&amp;lt;ref&amp;gt;http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2007/wiki1b_2_22&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Another application that makes use of method_missing could be a simple logger used for debugging purposes. Many times, it may be required to log the trace of called methods and provide information such as: called method-name, arguments, return type. It can be tedious to repeat this part of code in every method. A simple solution to this problem can be obtained using method_missing as:&lt;br /&gt;
&lt;br /&gt;
  class SimpleCallLogger&lt;br /&gt;
  def initialize(o)&lt;br /&gt;
  @obj = o&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(methodname, *args)&lt;br /&gt;
  puts &amp;quot;called: #{methodname}(#{args})&amp;quot;&lt;br /&gt;
  a = @obj.send(methodname, *args)&lt;br /&gt;
  puts &amp;quot;\t-&amp;gt; returned: #{a}&amp;quot;&lt;br /&gt;
  return a&lt;br /&gt;
  end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
This program makes use of method_missing in a way that it wraps around called method to output the logging information on entry and on exit, it logs the return type. Further, method_missing intercepts the method call and forward it to internal object with ‘send’ method of ruby. Hence, this use of method_missing acts as wrapper.&lt;br /&gt;
&lt;br /&gt;
===Generic Handler===&lt;br /&gt;
 class NoBar&lt;br /&gt;
 def method_missing(methodname, *args)&lt;br /&gt;
 define_method(:bar) if &amp;quot;bar&amp;quot; == methodname.to_s&lt;br /&gt;
 define_method(:nobar) if &amp;quot;nobar&amp;quot; == methodname.to_s&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This is an example of using method_missing as a generic handler to handle when a calling method is not exist. You can use missing_method to dynamically create a method at a runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Advantages of method_missing'''==&lt;br /&gt;
&lt;br /&gt;
*In addition to specifying the error messages for the undefined methods, method_missing provides a more dynamic behavior in the programming environment.&lt;br /&gt;
*If we are unfamiliar with the usage of the objects we created, then using method_missing is a good technique.&lt;br /&gt;
*Handles problems at runtime.&lt;br /&gt;
*Define's a generic method_missing and handle's any undefined method, a big advantage over Java. In Java, when you call an undefined method, the program will not compile.&lt;br /&gt;
*method_missing falls under the general technique of [http://en.wikipedia.org/wiki/Metaprogramming meta-programming]. Employ meta-programming in missing_function to write an another function to handle the call.&lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages of method_missing'''==	&lt;br /&gt;
*Slower than conventional method lookup. Simple tests indicate that method dispatch with method_missing is at least two to three times as expensive in time as conventional dispatch.&lt;br /&gt;
&lt;br /&gt;
*Since the methods being called never actually exist—they are just intercepted at the last step of the method lookup process—they cannot be documented or introspected as conventional methods can.&lt;br /&gt;
&lt;br /&gt;
*method_missing restricts compatibility with future versions of an [http://en.wikipedia.org/wiki/Application_programming_interface API]. Introducing new methods in a future API version can break users' expectations.&lt;br /&gt;
&lt;br /&gt;
=='''Key Points'''==&lt;br /&gt;
&lt;br /&gt;
*In the example below, class A defines only method method_missing() and no other method. When a new object of class A tries to access a method say 'foo', the respond_to? will return the value 'false'. When you actually try to implement it using “a.foo”, the code will get executed, courtesy of method_missing(). Even though the respond_to? says that you cannot access 'foo' method using object of class A, if you have method_missing() defined, you can access the method.&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In method_missing&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)&lt;br /&gt;
 a.foo&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 false&lt;br /&gt;
 In method_missing&lt;br /&gt;
&lt;br /&gt;
*In the following example, if within method_missing() we define an undefined method. &lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 @@i = 0&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In Method Missing #{@@i}&amp;quot;&lt;br /&gt;
 @@i += 1&lt;br /&gt;
 self.fun&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 a.foo &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 The result is a 'stack level too deep' error. &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
When the 'foo' method is called, after no method match the method_missing is run and this block has a method “self.fun” that is undefined.     Here when the program execution encounters 'self.fun' it once again calls method_missing. This goes on in an endless loop till the stack memory is full.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Ruby knows method_missing( ) exists, because it's a private instance method of 'BasicObject' that every object inherits. The BasicObject#method_missing( ) responds by raising the NoMethodError. Overriding this method_missing( ) allows you to call methods that don't really exist. &lt;br /&gt;
&lt;br /&gt;
*If method_missing is only looking for certain method names, don't forget to call the [http://en.wikibooks.org/wiki/Java_Programming/Keywords/super super] keyword if you haven't found what you're looking for, so that the other superclass' method_missing can handle it.&lt;br /&gt;
&lt;br /&gt;
*[http://www.prateekdayal.net/2007/10/16/rubys-responds_to-for-checking-if-a-method-exists/ obj.respond_to?] function returns 'true' if the obj responds to the given method. So if you want to know whether your class will respond to a function you can use respond_to? to know the answer. But if method_missing() is used, the output may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
*http://www.rubyinside.com/ &lt;br /&gt;
*https://www.youtube.com/watch?v=SAEiCkixrdE&amp;amp;feature=relmfu&lt;br /&gt;
*http://blog.jayfields.com/2008/02/ruby-replace-methodmissing-with-dynamic.html &lt;br /&gt;
*http://liquiddevelopment.blogspot.com/2006/04/twisting-and-shaping-dsls-using-ruby.html &lt;br /&gt;
*http://blog.rubybestpractices.com/posts/gregory/031-issue-2-method-lookup.html&lt;br /&gt;
*http://phrogz.net/RubyLibs/RubyMethodLookupFlow.pdf&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65303</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w22 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65303"/>
		<updated>2012-09-19T23:47:19Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* Format for defining method_missing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
=='''Introduction&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_method_missing.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
A method of a class is called by creating an object of the class and passing the method name to the object as a message. The object then looks up into its [http://www.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html method lookup path] and tries to match the called method with the defined methods in the class. On success, the method is executed along with the parameters passed and the result is returned.&lt;br /&gt;
&lt;br /&gt;
If the object does not find a match in its method lookup, in normal circumstances the [http://www.ruby-doc.org/core-1.9.3/NoMethodError.html NoMethodError Exception] is raised .&lt;br /&gt;
&lt;br /&gt;
In cases where the user wants to handle the methods which are not defined but still called, “method_missing” can be defined and the user can handle the methods as he/she sees fit.&lt;br /&gt;
&lt;br /&gt;
=='''Format for Defining method_missing'''==&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; def method_missing(m,*args,&amp;amp;block)&lt;br /&gt;
&lt;br /&gt;
(i) '''m-&amp;gt;''' accepts the symbol/name of the undefined method (ii) '''*args-&amp;gt;''' accepts the array of arguments passed in the method call  (iii) '''&amp;amp;block-&amp;gt;'''accepts a block passed to the method&lt;br /&gt;
&lt;br /&gt;
=='''Ruby Method Lookup Flow'''==&lt;br /&gt;
When the object of a class receives a method name to be executed, the following steps are carried out for matching and executing the method:&lt;br /&gt;
&lt;br /&gt;
*First, the object looks in its own [http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html instance methods].&lt;br /&gt;
*Second, it looks in the list of instance methods that all objects of that class share.&lt;br /&gt;
*Third, in each of the included [http://www.tutorialspoint.com/ruby/ruby_modules.html modules] of that class, in reverse order of inclusion. &lt;br /&gt;
*Fourth, it looks in that class’s superclass. &lt;br /&gt;
*Fifth, in the superclass’s included modules, all the way up until it reaches the class Object. &lt;br /&gt;
*Sixth, if it still can’t find a method, the very last place it looks is in the [http://linux.die.net/lkmpg/x40.html Kernel module], included in the class Object. &lt;br /&gt;
*Finally, it calls method_missing (if defined in the class), else throws up the NOMethodError exception.&lt;br /&gt;
&lt;br /&gt;
This entire tracing that the object does is the method lookup path.&lt;br /&gt;
&lt;br /&gt;
=='''Examples'''==&lt;br /&gt;
===Calling defined and undefined Methods===&lt;br /&gt;
&lt;br /&gt;
 class A		// creating a class 'A'&lt;br /&gt;
 def say		// defining a method 'say'&lt;br /&gt;
 puts &amp;quot; say Hi &amp;quot; // body of method say&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Creating the object of the class&lt;br /&gt;
 &lt;br /&gt;
  a=A.new	       // object of the class&lt;br /&gt;
  =&amp;gt; #&amp;lt;A:0x2a082e0&amp;gt;     //object id&lt;br /&gt;
&lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.say                  // defined method&lt;br /&gt;
 =&amp;gt; say Hi	       // returned result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.sayhi                // undefined method sayhi&lt;br /&gt;
 NoMethodError: undefined method `sayhi' for #&amp;lt;A:0x2a082e0&amp;gt;   // the NoMethodError is raised&lt;br /&gt;
&lt;br /&gt;
===method_missing Implementation&amp;lt;ref&amp;gt;http://www.thirdbit.net/articles/2007/08/01/10-things-you-should-know-about-method_missing/&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def say&lt;br /&gt;
 puts &amp;quot; say hi &amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(m,*args,&amp;amp;block)	// defining method_missing&lt;br /&gt;
 puts &amp;quot; This method does not exist&amp;quot;	// body of method_missing&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Calling a method that is not defined&lt;br /&gt;
 &lt;br /&gt;
 a=A.new&lt;br /&gt;
 a.sayhi                                // calling the undefined method sayhi with no arguments&lt;br /&gt;
 =&amp;gt; This method does not exist		// this result returned when method_missing is executed&lt;br /&gt;
&lt;br /&gt;
When the object 'a' traces its method lookup path for a matching method as 'sayhi', upon failure it resorts to method_missing and the body of method_missing is executed. 'method_missing' is the last resort.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Sometimes when a class has many methods that do generally the same kinds of things, and the programmer is not sure in advance which methods the user will call since there are so many of them, and they are all so similar, writing code for all of them seems futile. In these situations method_missing can be defined to take care of different cases. The below 'Generic Handler' example implements this.&lt;br /&gt;
&lt;br /&gt;
===Passing Parameters to an Undefined Method Call===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def add(a,b)&lt;br /&gt;
 a+b&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(name,*args,&amp;amp;block)    // the method_missing is defined and the *args parameter accepts all the parameters passed during 								                                 &lt;br /&gt;
                                             the method call   &lt;br /&gt;
 puts “You have typed the method name wrong and these were the parameters passed ; #{args[0]}, #{args[1]}”								&lt;br /&gt;
 end                         			&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The passed parameters are stored in the array 'args' and can be accessed like a normal array                &lt;br /&gt;
                                                   &lt;br /&gt;
 &lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.add(1,2)		        // calling the defined method add and passing the parameters (1,2)&lt;br /&gt;
 =&amp;gt; 3                           // result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.adds(4,2) 			// calling the undefined method adds and passing the parameter (4,2)&lt;br /&gt;
 =&amp;gt; You have typed the method name wrong and these were the parameters passed; 4, 2&lt;br /&gt;
&lt;br /&gt;
The user made a genuine mistake by typing 'adds', but this method is not defined. When the 'adds' method with parameters is called, the object 'a' tries to match the method in the method lookup path. Upon failure it invokes method_missing, the args are passed, stored in the array 'args' and the body of method_missing is executed.&lt;br /&gt;
&lt;br /&gt;
===Converting Numbers from Roman Representation to Integer Representation&amp;lt;ref&amp;gt;http://courses.ncsu.edu/csc517/common/lectures/notes/wk2.pdf&amp;lt;/ref&amp;gt;===&lt;br /&gt;
 class Roman&lt;br /&gt;
 DIGITS = {'I'=&amp;gt;1,'V'=&amp;gt;5,'X'=&amp;gt;10,'L'=&amp;gt;50,'C'=&amp;gt;100,'D'=&amp;gt;500,'M'=&amp;gt;1000,}&lt;br /&gt;
 def roman_to_integer(roman_string)&lt;br /&gt;
 last = nil&lt;br /&gt;
 roman_string.to_s.upcase.split(//).reverse.inject(0) do&lt;br /&gt;
 |memo, digit|&lt;br /&gt;
 if digit_value = DIGITS[digit]&lt;br /&gt;
 if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
 memo -= digit_value&lt;br /&gt;
 else&lt;br /&gt;
 memo += digit_value&lt;br /&gt;
 end&lt;br /&gt;
 last = digit_value&lt;br /&gt;
 end&lt;br /&gt;
 memo&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def method_missing(method)&lt;br /&gt;
 str=method.id2name&lt;br /&gt;
 roman_to_integer(str)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calling the undefined methods&lt;br /&gt;
&lt;br /&gt;
 r= Roman.new&lt;br /&gt;
 r.vii&lt;br /&gt;
 r.xxix&lt;br /&gt;
 r.xxiv&lt;br /&gt;
 r.xxvi&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The Output&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; 7&lt;br /&gt;
 =&amp;gt; 29&lt;br /&gt;
 =&amp;gt; 24&lt;br /&gt;
&lt;br /&gt;
===method_missing to Log Method Calls&amp;lt;ref&amp;gt;http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2007/wiki1b_2_22&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Another application that makes use of method_missing could be a simple logger used for debugging purposes. Many times, it may be required to log the trace of called methods and provide information such as: called method-name, arguments, return type. It can be tedious to repeat this part of code in every method. A simple solution to this problem can be obtained using method_missing as:&lt;br /&gt;
&lt;br /&gt;
  class SimpleCallLogger&lt;br /&gt;
  def initialize(o)&lt;br /&gt;
  @obj = o&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(methodname, *args)&lt;br /&gt;
  puts &amp;quot;called: #{methodname}(#{args})&amp;quot;&lt;br /&gt;
  a = @obj.send(methodname, *args)&lt;br /&gt;
  puts &amp;quot;\t-&amp;gt; returned: #{a}&amp;quot;&lt;br /&gt;
  return a&lt;br /&gt;
  end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
This program makes use of method_missing in a way that it wraps around called method to output the logging information on entry and on exit, it logs the return type. Further, method_missing intercepts the method call and forward it to internal object with ‘send’ method of ruby. Hence, this use of method_missing acts as wrapper.&lt;br /&gt;
&lt;br /&gt;
===Generic Handler===&lt;br /&gt;
 class NoBar&lt;br /&gt;
 def method_missing(methodname, *args)&lt;br /&gt;
 define_method(:bar) if &amp;quot;bar&amp;quot; == methodname.to_s&lt;br /&gt;
 define_method(:nobar) if &amp;quot;nobar&amp;quot; == methodname.to_s&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This is an example of using method_missing as a generic handler to handle when a calling method is not exist. You can use missing_method to dynamically create a method at a runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Advantages of method_missing'''==&lt;br /&gt;
&lt;br /&gt;
*In addition to specifying the error messages for the undefined methods, method_missing provides a more dynamic behavior in the programming environment.&lt;br /&gt;
*If we are unfamiliar with the usage of the objects we created, then using method_missing is a good technique.&lt;br /&gt;
*Handles problems at runtime.&lt;br /&gt;
*Define's a generic method_missing and handle's any undefined method, a big advantage over Java. In Java, when you call an undefined method, the program will not compile.&lt;br /&gt;
*method_missing falls under the general technique of [http://en.wikipedia.org/wiki/Metaprogramming meta-programming]. Employ meta-programming in missing_function to write an another function to handle the call.&lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages of method_missing'''==	&lt;br /&gt;
*Slower than conventional method lookup. Simple tests indicate that method dispatch with method_missing is at least two to three times as expensive in time as conventional dispatch.&lt;br /&gt;
&lt;br /&gt;
*Since the methods being called never actually exist—they are just intercepted at the last step of the method lookup process—they cannot be documented or introspected as conventional methods can.&lt;br /&gt;
&lt;br /&gt;
*method_missing restricts compatibility with future versions of an [http://en.wikipedia.org/wiki/Application_programming_interface API]. Introducing new methods in a future API version can break users' expectations.&lt;br /&gt;
&lt;br /&gt;
=='''Key Points'''==&lt;br /&gt;
&lt;br /&gt;
*In the example below, class A defines only method method_missing() and no other method. When a new object of class A tries to access a method say 'foo', the respond_to? will return the value 'false'. When you actually try to implement it using “a.foo”, the code will get executed, courtesy of method_missing(). Even though the respond_to? says that you cannot access 'foo' method using object of class A, if you have method_missing() defined, you can access the method.&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In method_missing&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)&lt;br /&gt;
 a.foo&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 false&lt;br /&gt;
 In method_missing&lt;br /&gt;
&lt;br /&gt;
*In the following example, if within method_missing() we define an undefined method. &lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 @@i = 0&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In Method Missing #{@@i}&amp;quot;&lt;br /&gt;
 @@i += 1&lt;br /&gt;
 self.fun&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 a.foo &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 The result is a 'stack level too deep' error. &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
When the 'foo' method is called, after no method match the method_missing is run and this block has a method “self.fun” that is undefined.     Here when the program execution encounters 'self.fun' it once again calls method_missing. This goes on in an endless loop till the stack memory is full.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Ruby knows method_missing( ) exists, because it's a private instance method of 'BasicObject' that every object inherits. The BasicObject#method_missing( ) responds by raising the NoMethodError. Overriding this method_missing( ) allows you to call methods that don't really exist. &lt;br /&gt;
&lt;br /&gt;
*If method_missing is only looking for certain method names, don't forget to call the [http://en.wikibooks.org/wiki/Java_Programming/Keywords/super super] keyword if you haven't found what you're looking for, so that the other superclass' method_missing can handle it.&lt;br /&gt;
&lt;br /&gt;
*[http://www.prateekdayal.net/2007/10/16/rubys-responds_to-for-checking-if-a-method-exists/ obj.respond_to?] function returns 'true' if the obj responds to the given method. So if you want to know whether your class will respond to a function you can use respond_to? to know the answer. But if method_missing() is used, the output may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
*http://www.rubyinside.com/ &lt;br /&gt;
*https://www.youtube.com/watch?v=SAEiCkixrdE&amp;amp;feature=relmfu&lt;br /&gt;
*http://blog.jayfields.com/2008/02/ruby-replace-methodmissing-with-dynamic.html &lt;br /&gt;
*http://liquiddevelopment.blogspot.com/2006/04/twisting-and-shaping-dsls-using-ruby.html &lt;br /&gt;
*http://blog.rubybestpractices.com/posts/gregory/031-issue-2-method-lookup.html&lt;br /&gt;
*http://phrogz.net/RubyLibs/RubyMethodLookupFlow.pdf&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65302</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w22 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65302"/>
		<updated>2012-09-19T23:46:47Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
=='''Introduction&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_method_missing.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
A method of a class is called by creating an object of the class and passing the method name to the object as a message. The object then looks up into its [http://www.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html method lookup path] and tries to match the called method with the defined methods in the class. On success, the method is executed along with the parameters passed and the result is returned.&lt;br /&gt;
&lt;br /&gt;
If the object does not find a match in its method lookup, in normal circumstances the [http://www.ruby-doc.org/core-1.9.3/NoMethodError.html NoMethodError Exception] is raised .&lt;br /&gt;
&lt;br /&gt;
In cases where the user wants to handle the methods which are not defined but still called, “method_missing” can be defined and the user can handle the methods as he/she sees fit.&lt;br /&gt;
&lt;br /&gt;
=='''Format for defining method_missing'''==&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; def method_missing(m,*args,&amp;amp;block)&lt;br /&gt;
&lt;br /&gt;
(i) '''m-&amp;gt;''' accepts the symbol/name of the undefined method (ii) '''*args-&amp;gt;''' accepts the array of arguments passed in the method call  (iii) '''&amp;amp;block-&amp;gt;'''accepts a block passed to the method&lt;br /&gt;
&lt;br /&gt;
=='''Ruby Method Lookup Flow'''==&lt;br /&gt;
When the object of a class receives a method name to be executed, the following steps are carried out for matching and executing the method:&lt;br /&gt;
&lt;br /&gt;
*First, the object looks in its own [http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html instance methods].&lt;br /&gt;
*Second, it looks in the list of instance methods that all objects of that class share.&lt;br /&gt;
*Third, in each of the included [http://www.tutorialspoint.com/ruby/ruby_modules.html modules] of that class, in reverse order of inclusion. &lt;br /&gt;
*Fourth, it looks in that class’s superclass. &lt;br /&gt;
*Fifth, in the superclass’s included modules, all the way up until it reaches the class Object. &lt;br /&gt;
*Sixth, if it still can’t find a method, the very last place it looks is in the [http://linux.die.net/lkmpg/x40.html Kernel module], included in the class Object. &lt;br /&gt;
*Finally, it calls method_missing (if defined in the class), else throws up the NOMethodError exception.&lt;br /&gt;
&lt;br /&gt;
This entire tracing that the object does is the method lookup path.&lt;br /&gt;
&lt;br /&gt;
=='''Examples'''==&lt;br /&gt;
===Calling defined and undefined Methods===&lt;br /&gt;
&lt;br /&gt;
 class A		// creating a class 'A'&lt;br /&gt;
 def say		// defining a method 'say'&lt;br /&gt;
 puts &amp;quot; say Hi &amp;quot; // body of method say&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Creating the object of the class&lt;br /&gt;
 &lt;br /&gt;
  a=A.new	       // object of the class&lt;br /&gt;
  =&amp;gt; #&amp;lt;A:0x2a082e0&amp;gt;     //object id&lt;br /&gt;
&lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.say                  // defined method&lt;br /&gt;
 =&amp;gt; say Hi	       // returned result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.sayhi                // undefined method sayhi&lt;br /&gt;
 NoMethodError: undefined method `sayhi' for #&amp;lt;A:0x2a082e0&amp;gt;   // the NoMethodError is raised&lt;br /&gt;
&lt;br /&gt;
===method_missing Implementation&amp;lt;ref&amp;gt;http://www.thirdbit.net/articles/2007/08/01/10-things-you-should-know-about-method_missing/&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def say&lt;br /&gt;
 puts &amp;quot; say hi &amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(m,*args,&amp;amp;block)	// defining method_missing&lt;br /&gt;
 puts &amp;quot; This method does not exist&amp;quot;	// body of method_missing&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Calling a method that is not defined&lt;br /&gt;
 &lt;br /&gt;
 a=A.new&lt;br /&gt;
 a.sayhi                                // calling the undefined method sayhi with no arguments&lt;br /&gt;
 =&amp;gt; This method does not exist		// this result returned when method_missing is executed&lt;br /&gt;
&lt;br /&gt;
When the object 'a' traces its method lookup path for a matching method as 'sayhi', upon failure it resorts to method_missing and the body of method_missing is executed. 'method_missing' is the last resort.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Sometimes when a class has many methods that do generally the same kinds of things, and the programmer is not sure in advance which methods the user will call since there are so many of them, and they are all so similar, writing code for all of them seems futile. In these situations method_missing can be defined to take care of different cases. The below 'Generic Handler' example implements this.&lt;br /&gt;
&lt;br /&gt;
===Passing Parameters to an Undefined Method Call===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def add(a,b)&lt;br /&gt;
 a+b&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(name,*args,&amp;amp;block)    // the method_missing is defined and the *args parameter accepts all the parameters passed during 								                                 &lt;br /&gt;
                                             the method call   &lt;br /&gt;
 puts “You have typed the method name wrong and these were the parameters passed ; #{args[0]}, #{args[1]}”								&lt;br /&gt;
 end                         			&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The passed parameters are stored in the array 'args' and can be accessed like a normal array                &lt;br /&gt;
                                                   &lt;br /&gt;
 &lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.add(1,2)		        // calling the defined method add and passing the parameters (1,2)&lt;br /&gt;
 =&amp;gt; 3                           // result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.adds(4,2) 			// calling the undefined method adds and passing the parameter (4,2)&lt;br /&gt;
 =&amp;gt; You have typed the method name wrong and these were the parameters passed; 4, 2&lt;br /&gt;
&lt;br /&gt;
The user made a genuine mistake by typing 'adds', but this method is not defined. When the 'adds' method with parameters is called, the object 'a' tries to match the method in the method lookup path. Upon failure it invokes method_missing, the args are passed, stored in the array 'args' and the body of method_missing is executed.&lt;br /&gt;
&lt;br /&gt;
===Converting Numbers from Roman Representation to Integer Representation&amp;lt;ref&amp;gt;http://courses.ncsu.edu/csc517/common/lectures/notes/wk2.pdf&amp;lt;/ref&amp;gt;===&lt;br /&gt;
 class Roman&lt;br /&gt;
 DIGITS = {'I'=&amp;gt;1,'V'=&amp;gt;5,'X'=&amp;gt;10,'L'=&amp;gt;50,'C'=&amp;gt;100,'D'=&amp;gt;500,'M'=&amp;gt;1000,}&lt;br /&gt;
 def roman_to_integer(roman_string)&lt;br /&gt;
 last = nil&lt;br /&gt;
 roman_string.to_s.upcase.split(//).reverse.inject(0) do&lt;br /&gt;
 |memo, digit|&lt;br /&gt;
 if digit_value = DIGITS[digit]&lt;br /&gt;
 if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
 memo -= digit_value&lt;br /&gt;
 else&lt;br /&gt;
 memo += digit_value&lt;br /&gt;
 end&lt;br /&gt;
 last = digit_value&lt;br /&gt;
 end&lt;br /&gt;
 memo&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def method_missing(method)&lt;br /&gt;
 str=method.id2name&lt;br /&gt;
 roman_to_integer(str)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calling the undefined methods&lt;br /&gt;
&lt;br /&gt;
 r= Roman.new&lt;br /&gt;
 r.vii&lt;br /&gt;
 r.xxix&lt;br /&gt;
 r.xxiv&lt;br /&gt;
 r.xxvi&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The Output&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; 7&lt;br /&gt;
 =&amp;gt; 29&lt;br /&gt;
 =&amp;gt; 24&lt;br /&gt;
&lt;br /&gt;
===method_missing to Log Method Calls&amp;lt;ref&amp;gt;http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2007/wiki1b_2_22&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Another application that makes use of method_missing could be a simple logger used for debugging purposes. Many times, it may be required to log the trace of called methods and provide information such as: called method-name, arguments, return type. It can be tedious to repeat this part of code in every method. A simple solution to this problem can be obtained using method_missing as:&lt;br /&gt;
&lt;br /&gt;
  class SimpleCallLogger&lt;br /&gt;
  def initialize(o)&lt;br /&gt;
  @obj = o&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(methodname, *args)&lt;br /&gt;
  puts &amp;quot;called: #{methodname}(#{args})&amp;quot;&lt;br /&gt;
  a = @obj.send(methodname, *args)&lt;br /&gt;
  puts &amp;quot;\t-&amp;gt; returned: #{a}&amp;quot;&lt;br /&gt;
  return a&lt;br /&gt;
  end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
This program makes use of method_missing in a way that it wraps around called method to output the logging information on entry and on exit, it logs the return type. Further, method_missing intercepts the method call and forward it to internal object with ‘send’ method of ruby. Hence, this use of method_missing acts as wrapper.&lt;br /&gt;
&lt;br /&gt;
===Generic Handler===&lt;br /&gt;
 class NoBar&lt;br /&gt;
 def method_missing(methodname, *args)&lt;br /&gt;
 define_method(:bar) if &amp;quot;bar&amp;quot; == methodname.to_s&lt;br /&gt;
 define_method(:nobar) if &amp;quot;nobar&amp;quot; == methodname.to_s&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This is an example of using method_missing as a generic handler to handle when a calling method is not exist. You can use missing_method to dynamically create a method at a runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Advantages of method_missing'''==&lt;br /&gt;
&lt;br /&gt;
*In addition to specifying the error messages for the undefined methods, method_missing provides a more dynamic behavior in the programming environment.&lt;br /&gt;
*If we are unfamiliar with the usage of the objects we created, then using method_missing is a good technique.&lt;br /&gt;
*Handles problems at runtime.&lt;br /&gt;
*Define's a generic method_missing and handle's any undefined method, a big advantage over Java. In Java, when you call an undefined method, the program will not compile.&lt;br /&gt;
*method_missing falls under the general technique of [http://en.wikipedia.org/wiki/Metaprogramming meta-programming]. Employ meta-programming in missing_function to write an another function to handle the call.&lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages of method_missing'''==	&lt;br /&gt;
*Slower than conventional method lookup. Simple tests indicate that method dispatch with method_missing is at least two to three times as expensive in time as conventional dispatch.&lt;br /&gt;
&lt;br /&gt;
*Since the methods being called never actually exist—they are just intercepted at the last step of the method lookup process—they cannot be documented or introspected as conventional methods can.&lt;br /&gt;
&lt;br /&gt;
*method_missing restricts compatibility with future versions of an [http://en.wikipedia.org/wiki/Application_programming_interface API]. Introducing new methods in a future API version can break users' expectations.&lt;br /&gt;
&lt;br /&gt;
=='''Key Points'''==&lt;br /&gt;
&lt;br /&gt;
*In the example below, class A defines only method method_missing() and no other method. When a new object of class A tries to access a method say 'foo', the respond_to? will return the value 'false'. When you actually try to implement it using “a.foo”, the code will get executed, courtesy of method_missing(). Even though the respond_to? says that you cannot access 'foo' method using object of class A, if you have method_missing() defined, you can access the method.&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In method_missing&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)&lt;br /&gt;
 a.foo&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 false&lt;br /&gt;
 In method_missing&lt;br /&gt;
&lt;br /&gt;
*In the following example, if within method_missing() we define an undefined method. &lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 @@i = 0&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In Method Missing #{@@i}&amp;quot;&lt;br /&gt;
 @@i += 1&lt;br /&gt;
 self.fun&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 a.foo &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 The result is a 'stack level too deep' error. &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
When the 'foo' method is called, after no method match the method_missing is run and this block has a method “self.fun” that is undefined.     Here when the program execution encounters 'self.fun' it once again calls method_missing. This goes on in an endless loop till the stack memory is full.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Ruby knows method_missing( ) exists, because it's a private instance method of 'BasicObject' that every object inherits. The BasicObject#method_missing( ) responds by raising the NoMethodError. Overriding this method_missing( ) allows you to call methods that don't really exist. &lt;br /&gt;
&lt;br /&gt;
*If method_missing is only looking for certain method names, don't forget to call the [http://en.wikibooks.org/wiki/Java_Programming/Keywords/super super] keyword if you haven't found what you're looking for, so that the other superclass' method_missing can handle it.&lt;br /&gt;
&lt;br /&gt;
*[http://www.prateekdayal.net/2007/10/16/rubys-responds_to-for-checking-if-a-method-exists/ obj.respond_to?] function returns 'true' if the obj responds to the given method. So if you want to know whether your class will respond to a function you can use respond_to? to know the answer. But if method_missing() is used, the output may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
*http://www.rubyinside.com/ &lt;br /&gt;
*https://www.youtube.com/watch?v=SAEiCkixrdE&amp;amp;feature=relmfu&lt;br /&gt;
*http://blog.jayfields.com/2008/02/ruby-replace-methodmissing-with-dynamic.html &lt;br /&gt;
*http://liquiddevelopment.blogspot.com/2006/04/twisting-and-shaping-dsls-using-ruby.html &lt;br /&gt;
*http://blog.rubybestpractices.com/posts/gregory/031-issue-2-method-lookup.html&lt;br /&gt;
*http://phrogz.net/RubyLibs/RubyMethodLookupFlow.pdf&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65301</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w22 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65301"/>
		<updated>2012-09-19T23:46:27Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* Ruby method Lookup Flow */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''method_missing in Ruby:'''  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Introduction&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_method_missing.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
A method of a class is called by creating an object of the class and passing the method name to the object as a message. The object then looks up into its [http://www.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html method lookup path] and tries to match the called method with the defined methods in the class. On success, the method is executed along with the parameters passed and the result is returned.&lt;br /&gt;
&lt;br /&gt;
If the object does not find a match in its method lookup, in normal circumstances the [http://www.ruby-doc.org/core-1.9.3/NoMethodError.html NoMethodError Exception] is raised .&lt;br /&gt;
&lt;br /&gt;
In cases where the user wants to handle the methods which are not defined but still called, “method_missing” can be defined and the user can handle the methods as he/she sees fit.&lt;br /&gt;
&lt;br /&gt;
=='''Format for defining method_missing'''==&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; def method_missing(m,*args,&amp;amp;block)&lt;br /&gt;
&lt;br /&gt;
(i) '''m-&amp;gt;''' accepts the symbol/name of the undefined method (ii) '''*args-&amp;gt;''' accepts the array of arguments passed in the method call  (iii) '''&amp;amp;block-&amp;gt;'''accepts a block passed to the method&lt;br /&gt;
&lt;br /&gt;
=='''Ruby Method Lookup Flow'''==&lt;br /&gt;
When the object of a class receives a method name to be executed, the following steps are carried out for matching and executing the method:&lt;br /&gt;
&lt;br /&gt;
*First, the object looks in its own [http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html instance methods].&lt;br /&gt;
*Second, it looks in the list of instance methods that all objects of that class share.&lt;br /&gt;
*Third, in each of the included [http://www.tutorialspoint.com/ruby/ruby_modules.html modules] of that class, in reverse order of inclusion. &lt;br /&gt;
*Fourth, it looks in that class’s superclass. &lt;br /&gt;
*Fifth, in the superclass’s included modules, all the way up until it reaches the class Object. &lt;br /&gt;
*Sixth, if it still can’t find a method, the very last place it looks is in the [http://linux.die.net/lkmpg/x40.html Kernel module], included in the class Object. &lt;br /&gt;
*Finally, it calls method_missing (if defined in the class), else throws up the NOMethodError exception.&lt;br /&gt;
&lt;br /&gt;
This entire tracing that the object does is the method lookup path.&lt;br /&gt;
&lt;br /&gt;
=='''Examples'''==&lt;br /&gt;
===Calling defined and undefined Methods===&lt;br /&gt;
&lt;br /&gt;
 class A		// creating a class 'A'&lt;br /&gt;
 def say		// defining a method 'say'&lt;br /&gt;
 puts &amp;quot; say Hi &amp;quot; // body of method say&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Creating the object of the class&lt;br /&gt;
 &lt;br /&gt;
  a=A.new	       // object of the class&lt;br /&gt;
  =&amp;gt; #&amp;lt;A:0x2a082e0&amp;gt;     //object id&lt;br /&gt;
&lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.say                  // defined method&lt;br /&gt;
 =&amp;gt; say Hi	       // returned result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.sayhi                // undefined method sayhi&lt;br /&gt;
 NoMethodError: undefined method `sayhi' for #&amp;lt;A:0x2a082e0&amp;gt;   // the NoMethodError is raised&lt;br /&gt;
&lt;br /&gt;
===method_missing Implementation&amp;lt;ref&amp;gt;http://www.thirdbit.net/articles/2007/08/01/10-things-you-should-know-about-method_missing/&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def say&lt;br /&gt;
 puts &amp;quot; say hi &amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(m,*args,&amp;amp;block)	// defining method_missing&lt;br /&gt;
 puts &amp;quot; This method does not exist&amp;quot;	// body of method_missing&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Calling a method that is not defined&lt;br /&gt;
 &lt;br /&gt;
 a=A.new&lt;br /&gt;
 a.sayhi                                // calling the undefined method sayhi with no arguments&lt;br /&gt;
 =&amp;gt; This method does not exist		// this result returned when method_missing is executed&lt;br /&gt;
&lt;br /&gt;
When the object 'a' traces its method lookup path for a matching method as 'sayhi', upon failure it resorts to method_missing and the body of method_missing is executed. 'method_missing' is the last resort.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Sometimes when a class has many methods that do generally the same kinds of things, and the programmer is not sure in advance which methods the user will call since there are so many of them, and they are all so similar, writing code for all of them seems futile. In these situations method_missing can be defined to take care of different cases. The below 'Generic Handler' example implements this.&lt;br /&gt;
&lt;br /&gt;
===Passing Parameters to an Undefined Method Call===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def add(a,b)&lt;br /&gt;
 a+b&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(name,*args,&amp;amp;block)    // the method_missing is defined and the *args parameter accepts all the parameters passed during 								                                 &lt;br /&gt;
                                             the method call   &lt;br /&gt;
 puts “You have typed the method name wrong and these were the parameters passed ; #{args[0]}, #{args[1]}”								&lt;br /&gt;
 end                         			&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The passed parameters are stored in the array 'args' and can be accessed like a normal array                &lt;br /&gt;
                                                   &lt;br /&gt;
 &lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.add(1,2)		        // calling the defined method add and passing the parameters (1,2)&lt;br /&gt;
 =&amp;gt; 3                           // result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.adds(4,2) 			// calling the undefined method adds and passing the parameter (4,2)&lt;br /&gt;
 =&amp;gt; You have typed the method name wrong and these were the parameters passed; 4, 2&lt;br /&gt;
&lt;br /&gt;
The user made a genuine mistake by typing 'adds', but this method is not defined. When the 'adds' method with parameters is called, the object 'a' tries to match the method in the method lookup path. Upon failure it invokes method_missing, the args are passed, stored in the array 'args' and the body of method_missing is executed.&lt;br /&gt;
&lt;br /&gt;
===Converting Numbers from Roman Representation to Integer Representation&amp;lt;ref&amp;gt;http://courses.ncsu.edu/csc517/common/lectures/notes/wk2.pdf&amp;lt;/ref&amp;gt;===&lt;br /&gt;
 class Roman&lt;br /&gt;
 DIGITS = {'I'=&amp;gt;1,'V'=&amp;gt;5,'X'=&amp;gt;10,'L'=&amp;gt;50,'C'=&amp;gt;100,'D'=&amp;gt;500,'M'=&amp;gt;1000,}&lt;br /&gt;
 def roman_to_integer(roman_string)&lt;br /&gt;
 last = nil&lt;br /&gt;
 roman_string.to_s.upcase.split(//).reverse.inject(0) do&lt;br /&gt;
 |memo, digit|&lt;br /&gt;
 if digit_value = DIGITS[digit]&lt;br /&gt;
 if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
 memo -= digit_value&lt;br /&gt;
 else&lt;br /&gt;
 memo += digit_value&lt;br /&gt;
 end&lt;br /&gt;
 last = digit_value&lt;br /&gt;
 end&lt;br /&gt;
 memo&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def method_missing(method)&lt;br /&gt;
 str=method.id2name&lt;br /&gt;
 roman_to_integer(str)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calling the undefined methods&lt;br /&gt;
&lt;br /&gt;
 r= Roman.new&lt;br /&gt;
 r.vii&lt;br /&gt;
 r.xxix&lt;br /&gt;
 r.xxiv&lt;br /&gt;
 r.xxvi&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The Output&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; 7&lt;br /&gt;
 =&amp;gt; 29&lt;br /&gt;
 =&amp;gt; 24&lt;br /&gt;
&lt;br /&gt;
===method_missing to Log Method Calls&amp;lt;ref&amp;gt;http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2007/wiki1b_2_22&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Another application that makes use of method_missing could be a simple logger used for debugging purposes. Many times, it may be required to log the trace of called methods and provide information such as: called method-name, arguments, return type. It can be tedious to repeat this part of code in every method. A simple solution to this problem can be obtained using method_missing as:&lt;br /&gt;
&lt;br /&gt;
  class SimpleCallLogger&lt;br /&gt;
  def initialize(o)&lt;br /&gt;
  @obj = o&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(methodname, *args)&lt;br /&gt;
  puts &amp;quot;called: #{methodname}(#{args})&amp;quot;&lt;br /&gt;
  a = @obj.send(methodname, *args)&lt;br /&gt;
  puts &amp;quot;\t-&amp;gt; returned: #{a}&amp;quot;&lt;br /&gt;
  return a&lt;br /&gt;
  end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
This program makes use of method_missing in a way that it wraps around called method to output the logging information on entry and on exit, it logs the return type. Further, method_missing intercepts the method call and forward it to internal object with ‘send’ method of ruby. Hence, this use of method_missing acts as wrapper.&lt;br /&gt;
&lt;br /&gt;
===Generic Handler===&lt;br /&gt;
 class NoBar&lt;br /&gt;
 def method_missing(methodname, *args)&lt;br /&gt;
 define_method(:bar) if &amp;quot;bar&amp;quot; == methodname.to_s&lt;br /&gt;
 define_method(:nobar) if &amp;quot;nobar&amp;quot; == methodname.to_s&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This is an example of using method_missing as a generic handler to handle when a calling method is not exist. You can use missing_method to dynamically create a method at a runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Advantages of method_missing'''==&lt;br /&gt;
&lt;br /&gt;
*In addition to specifying the error messages for the undefined methods, method_missing provides a more dynamic behavior in the programming environment.&lt;br /&gt;
*If we are unfamiliar with the usage of the objects we created, then using method_missing is a good technique.&lt;br /&gt;
*Handles problems at runtime.&lt;br /&gt;
*Define's a generic method_missing and handle's any undefined method, a big advantage over Java. In Java, when you call an undefined method, the program will not compile.&lt;br /&gt;
*method_missing falls under the general technique of [http://en.wikipedia.org/wiki/Metaprogramming meta-programming]. Employ meta-programming in missing_function to write an another function to handle the call.&lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages of method_missing'''==	&lt;br /&gt;
*Slower than conventional method lookup. Simple tests indicate that method dispatch with method_missing is at least two to three times as expensive in time as conventional dispatch.&lt;br /&gt;
&lt;br /&gt;
*Since the methods being called never actually exist—they are just intercepted at the last step of the method lookup process—they cannot be documented or introspected as conventional methods can.&lt;br /&gt;
&lt;br /&gt;
*method_missing restricts compatibility with future versions of an [http://en.wikipedia.org/wiki/Application_programming_interface API]. Introducing new methods in a future API version can break users' expectations.&lt;br /&gt;
&lt;br /&gt;
=='''Key Points'''==&lt;br /&gt;
&lt;br /&gt;
*In the example below, class A defines only method method_missing() and no other method. When a new object of class A tries to access a method say 'foo', the respond_to? will return the value 'false'. When you actually try to implement it using “a.foo”, the code will get executed, courtesy of method_missing(). Even though the respond_to? says that you cannot access 'foo' method using object of class A, if you have method_missing() defined, you can access the method.&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In method_missing&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)&lt;br /&gt;
 a.foo&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 false&lt;br /&gt;
 In method_missing&lt;br /&gt;
&lt;br /&gt;
*In the following example, if within method_missing() we define an undefined method. &lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 @@i = 0&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In Method Missing #{@@i}&amp;quot;&lt;br /&gt;
 @@i += 1&lt;br /&gt;
 self.fun&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 a.foo &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 The result is a 'stack level too deep' error. &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
When the 'foo' method is called, after no method match the method_missing is run and this block has a method “self.fun” that is undefined.     Here when the program execution encounters 'self.fun' it once again calls method_missing. This goes on in an endless loop till the stack memory is full.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Ruby knows method_missing( ) exists, because it's a private instance method of 'BasicObject' that every object inherits. The BasicObject#method_missing( ) responds by raising the NoMethodError. Overriding this method_missing( ) allows you to call methods that don't really exist. &lt;br /&gt;
&lt;br /&gt;
*If method_missing is only looking for certain method names, don't forget to call the [http://en.wikibooks.org/wiki/Java_Programming/Keywords/super super] keyword if you haven't found what you're looking for, so that the other superclass' method_missing can handle it.&lt;br /&gt;
&lt;br /&gt;
*[http://www.prateekdayal.net/2007/10/16/rubys-responds_to-for-checking-if-a-method-exists/ obj.respond_to?] function returns 'true' if the obj responds to the given method. So if you want to know whether your class will respond to a function you can use respond_to? to know the answer. But if method_missing() is used, the output may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
*http://www.rubyinside.com/ &lt;br /&gt;
*https://www.youtube.com/watch?v=SAEiCkixrdE&amp;amp;feature=relmfu&lt;br /&gt;
*http://blog.jayfields.com/2008/02/ruby-replace-methodmissing-with-dynamic.html &lt;br /&gt;
*http://liquiddevelopment.blogspot.com/2006/04/twisting-and-shaping-dsls-using-ruby.html &lt;br /&gt;
*http://blog.rubybestpractices.com/posts/gregory/031-issue-2-method-lookup.html&lt;br /&gt;
*http://phrogz.net/RubyLibs/RubyMethodLookupFlow.pdf&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65300</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w22 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65300"/>
		<updated>2012-09-19T23:45:51Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* method_missing to log method callshttp://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2007/wiki1b_2_22 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''method_missing in Ruby:'''  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Introduction&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_method_missing.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
A method of a class is called by creating an object of the class and passing the method name to the object as a message. The object then looks up into its [http://www.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html method lookup path] and tries to match the called method with the defined methods in the class. On success, the method is executed along with the parameters passed and the result is returned.&lt;br /&gt;
&lt;br /&gt;
If the object does not find a match in its method lookup, in normal circumstances the [http://www.ruby-doc.org/core-1.9.3/NoMethodError.html NoMethodError Exception] is raised .&lt;br /&gt;
&lt;br /&gt;
In cases where the user wants to handle the methods which are not defined but still called, “method_missing” can be defined and the user can handle the methods as he/she sees fit.&lt;br /&gt;
&lt;br /&gt;
=='''Format for defining method_missing'''==&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; def method_missing(m,*args,&amp;amp;block)&lt;br /&gt;
&lt;br /&gt;
(i) '''m-&amp;gt;''' accepts the symbol/name of the undefined method (ii) '''*args-&amp;gt;''' accepts the array of arguments passed in the method call  (iii) '''&amp;amp;block-&amp;gt;'''accepts a block passed to the method&lt;br /&gt;
&lt;br /&gt;
=='''Ruby method Lookup Flow'''==&lt;br /&gt;
When the object of a class receives a method name to be executed, the following steps are carried out for matching and executing the method:&lt;br /&gt;
&lt;br /&gt;
*First, the object looks in its own [http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html instance methods].&lt;br /&gt;
*Second, it looks in the list of instance methods that all objects of that class share.&lt;br /&gt;
*Third, in each of the included [http://www.tutorialspoint.com/ruby/ruby_modules.html modules] of that class, in reverse order of inclusion. &lt;br /&gt;
*Fourth, it looks in that class’s superclass. &lt;br /&gt;
*Fifth, in the superclass’s included modules, all the way up until it reaches the class Object. &lt;br /&gt;
*Sixth, if it still can’t find a method, the very last place it looks is in the [http://linux.die.net/lkmpg/x40.html Kernel module], included in the class Object. &lt;br /&gt;
*Finally, it calls method_missing (if defined in the class), else throws up the NOMethodError exception.&lt;br /&gt;
&lt;br /&gt;
This entire tracing that the object does is the method lookup path.&lt;br /&gt;
&lt;br /&gt;
=='''Examples'''==&lt;br /&gt;
===Calling defined and undefined Methods===&lt;br /&gt;
&lt;br /&gt;
 class A		// creating a class 'A'&lt;br /&gt;
 def say		// defining a method 'say'&lt;br /&gt;
 puts &amp;quot; say Hi &amp;quot; // body of method say&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Creating the object of the class&lt;br /&gt;
 &lt;br /&gt;
  a=A.new	       // object of the class&lt;br /&gt;
  =&amp;gt; #&amp;lt;A:0x2a082e0&amp;gt;     //object id&lt;br /&gt;
&lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.say                  // defined method&lt;br /&gt;
 =&amp;gt; say Hi	       // returned result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.sayhi                // undefined method sayhi&lt;br /&gt;
 NoMethodError: undefined method `sayhi' for #&amp;lt;A:0x2a082e0&amp;gt;   // the NoMethodError is raised&lt;br /&gt;
&lt;br /&gt;
===method_missing Implementation&amp;lt;ref&amp;gt;http://www.thirdbit.net/articles/2007/08/01/10-things-you-should-know-about-method_missing/&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def say&lt;br /&gt;
 puts &amp;quot; say hi &amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(m,*args,&amp;amp;block)	// defining method_missing&lt;br /&gt;
 puts &amp;quot; This method does not exist&amp;quot;	// body of method_missing&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Calling a method that is not defined&lt;br /&gt;
 &lt;br /&gt;
 a=A.new&lt;br /&gt;
 a.sayhi                                // calling the undefined method sayhi with no arguments&lt;br /&gt;
 =&amp;gt; This method does not exist		// this result returned when method_missing is executed&lt;br /&gt;
&lt;br /&gt;
When the object 'a' traces its method lookup path for a matching method as 'sayhi', upon failure it resorts to method_missing and the body of method_missing is executed. 'method_missing' is the last resort.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Sometimes when a class has many methods that do generally the same kinds of things, and the programmer is not sure in advance which methods the user will call since there are so many of them, and they are all so similar, writing code for all of them seems futile. In these situations method_missing can be defined to take care of different cases. The below 'Generic Handler' example implements this.&lt;br /&gt;
&lt;br /&gt;
===Passing Parameters to an Undefined Method Call===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def add(a,b)&lt;br /&gt;
 a+b&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(name,*args,&amp;amp;block)    // the method_missing is defined and the *args parameter accepts all the parameters passed during 								                                 &lt;br /&gt;
                                             the method call   &lt;br /&gt;
 puts “You have typed the method name wrong and these were the parameters passed ; #{args[0]}, #{args[1]}”								&lt;br /&gt;
 end                         			&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The passed parameters are stored in the array 'args' and can be accessed like a normal array                &lt;br /&gt;
                                                   &lt;br /&gt;
 &lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.add(1,2)		        // calling the defined method add and passing the parameters (1,2)&lt;br /&gt;
 =&amp;gt; 3                           // result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.adds(4,2) 			// calling the undefined method adds and passing the parameter (4,2)&lt;br /&gt;
 =&amp;gt; You have typed the method name wrong and these were the parameters passed; 4, 2&lt;br /&gt;
&lt;br /&gt;
The user made a genuine mistake by typing 'adds', but this method is not defined. When the 'adds' method with parameters is called, the object 'a' tries to match the method in the method lookup path. Upon failure it invokes method_missing, the args are passed, stored in the array 'args' and the body of method_missing is executed.&lt;br /&gt;
&lt;br /&gt;
===Converting Numbers from Roman Representation to Integer Representation&amp;lt;ref&amp;gt;http://courses.ncsu.edu/csc517/common/lectures/notes/wk2.pdf&amp;lt;/ref&amp;gt;===&lt;br /&gt;
 class Roman&lt;br /&gt;
 DIGITS = {'I'=&amp;gt;1,'V'=&amp;gt;5,'X'=&amp;gt;10,'L'=&amp;gt;50,'C'=&amp;gt;100,'D'=&amp;gt;500,'M'=&amp;gt;1000,}&lt;br /&gt;
 def roman_to_integer(roman_string)&lt;br /&gt;
 last = nil&lt;br /&gt;
 roman_string.to_s.upcase.split(//).reverse.inject(0) do&lt;br /&gt;
 |memo, digit|&lt;br /&gt;
 if digit_value = DIGITS[digit]&lt;br /&gt;
 if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
 memo -= digit_value&lt;br /&gt;
 else&lt;br /&gt;
 memo += digit_value&lt;br /&gt;
 end&lt;br /&gt;
 last = digit_value&lt;br /&gt;
 end&lt;br /&gt;
 memo&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def method_missing(method)&lt;br /&gt;
 str=method.id2name&lt;br /&gt;
 roman_to_integer(str)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calling the undefined methods&lt;br /&gt;
&lt;br /&gt;
 r= Roman.new&lt;br /&gt;
 r.vii&lt;br /&gt;
 r.xxix&lt;br /&gt;
 r.xxiv&lt;br /&gt;
 r.xxvi&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The Output&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; 7&lt;br /&gt;
 =&amp;gt; 29&lt;br /&gt;
 =&amp;gt; 24&lt;br /&gt;
&lt;br /&gt;
===method_missing to Log Method Calls&amp;lt;ref&amp;gt;http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2007/wiki1b_2_22&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Another application that makes use of method_missing could be a simple logger used for debugging purposes. Many times, it may be required to log the trace of called methods and provide information such as: called method-name, arguments, return type. It can be tedious to repeat this part of code in every method. A simple solution to this problem can be obtained using method_missing as:&lt;br /&gt;
&lt;br /&gt;
  class SimpleCallLogger&lt;br /&gt;
  def initialize(o)&lt;br /&gt;
  @obj = o&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(methodname, *args)&lt;br /&gt;
  puts &amp;quot;called: #{methodname}(#{args})&amp;quot;&lt;br /&gt;
  a = @obj.send(methodname, *args)&lt;br /&gt;
  puts &amp;quot;\t-&amp;gt; returned: #{a}&amp;quot;&lt;br /&gt;
  return a&lt;br /&gt;
  end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
This program makes use of method_missing in a way that it wraps around called method to output the logging information on entry and on exit, it logs the return type. Further, method_missing intercepts the method call and forward it to internal object with ‘send’ method of ruby. Hence, this use of method_missing acts as wrapper.&lt;br /&gt;
&lt;br /&gt;
===Generic Handler===&lt;br /&gt;
 class NoBar&lt;br /&gt;
 def method_missing(methodname, *args)&lt;br /&gt;
 define_method(:bar) if &amp;quot;bar&amp;quot; == methodname.to_s&lt;br /&gt;
 define_method(:nobar) if &amp;quot;nobar&amp;quot; == methodname.to_s&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This is an example of using method_missing as a generic handler to handle when a calling method is not exist. You can use missing_method to dynamically create a method at a runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Advantages of method_missing'''==&lt;br /&gt;
&lt;br /&gt;
*In addition to specifying the error messages for the undefined methods, method_missing provides a more dynamic behavior in the programming environment.&lt;br /&gt;
*If we are unfamiliar with the usage of the objects we created, then using method_missing is a good technique.&lt;br /&gt;
*Handles problems at runtime.&lt;br /&gt;
*Define's a generic method_missing and handle's any undefined method, a big advantage over Java. In Java, when you call an undefined method, the program will not compile.&lt;br /&gt;
*method_missing falls under the general technique of [http://en.wikipedia.org/wiki/Metaprogramming meta-programming]. Employ meta-programming in missing_function to write an another function to handle the call.&lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages of method_missing'''==	&lt;br /&gt;
*Slower than conventional method lookup. Simple tests indicate that method dispatch with method_missing is at least two to three times as expensive in time as conventional dispatch.&lt;br /&gt;
&lt;br /&gt;
*Since the methods being called never actually exist—they are just intercepted at the last step of the method lookup process—they cannot be documented or introspected as conventional methods can.&lt;br /&gt;
&lt;br /&gt;
*method_missing restricts compatibility with future versions of an [http://en.wikipedia.org/wiki/Application_programming_interface API]. Introducing new methods in a future API version can break users' expectations.&lt;br /&gt;
&lt;br /&gt;
=='''Key Points'''==&lt;br /&gt;
&lt;br /&gt;
*In the example below, class A defines only method method_missing() and no other method. When a new object of class A tries to access a method say 'foo', the respond_to? will return the value 'false'. When you actually try to implement it using “a.foo”, the code will get executed, courtesy of method_missing(). Even though the respond_to? says that you cannot access 'foo' method using object of class A, if you have method_missing() defined, you can access the method.&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In method_missing&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)&lt;br /&gt;
 a.foo&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 false&lt;br /&gt;
 In method_missing&lt;br /&gt;
&lt;br /&gt;
*In the following example, if within method_missing() we define an undefined method. &lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 @@i = 0&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In Method Missing #{@@i}&amp;quot;&lt;br /&gt;
 @@i += 1&lt;br /&gt;
 self.fun&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 a.foo &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 The result is a 'stack level too deep' error. &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
When the 'foo' method is called, after no method match the method_missing is run and this block has a method “self.fun” that is undefined.     Here when the program execution encounters 'self.fun' it once again calls method_missing. This goes on in an endless loop till the stack memory is full.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Ruby knows method_missing( ) exists, because it's a private instance method of 'BasicObject' that every object inherits. The BasicObject#method_missing( ) responds by raising the NoMethodError. Overriding this method_missing( ) allows you to call methods that don't really exist. &lt;br /&gt;
&lt;br /&gt;
*If method_missing is only looking for certain method names, don't forget to call the [http://en.wikibooks.org/wiki/Java_Programming/Keywords/super super] keyword if you haven't found what you're looking for, so that the other superclass' method_missing can handle it.&lt;br /&gt;
&lt;br /&gt;
*[http://www.prateekdayal.net/2007/10/16/rubys-responds_to-for-checking-if-a-method-exists/ obj.respond_to?] function returns 'true' if the obj responds to the given method. So if you want to know whether your class will respond to a function you can use respond_to? to know the answer. But if method_missing() is used, the output may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
*http://www.rubyinside.com/ &lt;br /&gt;
*https://www.youtube.com/watch?v=SAEiCkixrdE&amp;amp;feature=relmfu&lt;br /&gt;
*http://blog.jayfields.com/2008/02/ruby-replace-methodmissing-with-dynamic.html &lt;br /&gt;
*http://liquiddevelopment.blogspot.com/2006/04/twisting-and-shaping-dsls-using-ruby.html &lt;br /&gt;
*http://blog.rubybestpractices.com/posts/gregory/031-issue-2-method-lookup.html&lt;br /&gt;
*http://phrogz.net/RubyLibs/RubyMethodLookupFlow.pdf&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65299</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w22 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65299"/>
		<updated>2012-09-19T23:45:26Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* Converting Numbers from Roman Representation to Integer representationhttp://courses.ncsu.edu/csc517/common/lectures/notes/wk2.pdf */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''method_missing in Ruby:'''  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Introduction&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_method_missing.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
A method of a class is called by creating an object of the class and passing the method name to the object as a message. The object then looks up into its [http://www.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html method lookup path] and tries to match the called method with the defined methods in the class. On success, the method is executed along with the parameters passed and the result is returned.&lt;br /&gt;
&lt;br /&gt;
If the object does not find a match in its method lookup, in normal circumstances the [http://www.ruby-doc.org/core-1.9.3/NoMethodError.html NoMethodError Exception] is raised .&lt;br /&gt;
&lt;br /&gt;
In cases where the user wants to handle the methods which are not defined but still called, “method_missing” can be defined and the user can handle the methods as he/she sees fit.&lt;br /&gt;
&lt;br /&gt;
=='''Format for defining method_missing'''==&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; def method_missing(m,*args,&amp;amp;block)&lt;br /&gt;
&lt;br /&gt;
(i) '''m-&amp;gt;''' accepts the symbol/name of the undefined method (ii) '''*args-&amp;gt;''' accepts the array of arguments passed in the method call  (iii) '''&amp;amp;block-&amp;gt;'''accepts a block passed to the method&lt;br /&gt;
&lt;br /&gt;
=='''Ruby method Lookup Flow'''==&lt;br /&gt;
When the object of a class receives a method name to be executed, the following steps are carried out for matching and executing the method:&lt;br /&gt;
&lt;br /&gt;
*First, the object looks in its own [http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html instance methods].&lt;br /&gt;
*Second, it looks in the list of instance methods that all objects of that class share.&lt;br /&gt;
*Third, in each of the included [http://www.tutorialspoint.com/ruby/ruby_modules.html modules] of that class, in reverse order of inclusion. &lt;br /&gt;
*Fourth, it looks in that class’s superclass. &lt;br /&gt;
*Fifth, in the superclass’s included modules, all the way up until it reaches the class Object. &lt;br /&gt;
*Sixth, if it still can’t find a method, the very last place it looks is in the [http://linux.die.net/lkmpg/x40.html Kernel module], included in the class Object. &lt;br /&gt;
*Finally, it calls method_missing (if defined in the class), else throws up the NOMethodError exception.&lt;br /&gt;
&lt;br /&gt;
This entire tracing that the object does is the method lookup path.&lt;br /&gt;
&lt;br /&gt;
=='''Examples'''==&lt;br /&gt;
===Calling defined and undefined Methods===&lt;br /&gt;
&lt;br /&gt;
 class A		// creating a class 'A'&lt;br /&gt;
 def say		// defining a method 'say'&lt;br /&gt;
 puts &amp;quot; say Hi &amp;quot; // body of method say&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Creating the object of the class&lt;br /&gt;
 &lt;br /&gt;
  a=A.new	       // object of the class&lt;br /&gt;
  =&amp;gt; #&amp;lt;A:0x2a082e0&amp;gt;     //object id&lt;br /&gt;
&lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.say                  // defined method&lt;br /&gt;
 =&amp;gt; say Hi	       // returned result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.sayhi                // undefined method sayhi&lt;br /&gt;
 NoMethodError: undefined method `sayhi' for #&amp;lt;A:0x2a082e0&amp;gt;   // the NoMethodError is raised&lt;br /&gt;
&lt;br /&gt;
===method_missing Implementation&amp;lt;ref&amp;gt;http://www.thirdbit.net/articles/2007/08/01/10-things-you-should-know-about-method_missing/&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def say&lt;br /&gt;
 puts &amp;quot; say hi &amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(m,*args,&amp;amp;block)	// defining method_missing&lt;br /&gt;
 puts &amp;quot; This method does not exist&amp;quot;	// body of method_missing&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Calling a method that is not defined&lt;br /&gt;
 &lt;br /&gt;
 a=A.new&lt;br /&gt;
 a.sayhi                                // calling the undefined method sayhi with no arguments&lt;br /&gt;
 =&amp;gt; This method does not exist		// this result returned when method_missing is executed&lt;br /&gt;
&lt;br /&gt;
When the object 'a' traces its method lookup path for a matching method as 'sayhi', upon failure it resorts to method_missing and the body of method_missing is executed. 'method_missing' is the last resort.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Sometimes when a class has many methods that do generally the same kinds of things, and the programmer is not sure in advance which methods the user will call since there are so many of them, and they are all so similar, writing code for all of them seems futile. In these situations method_missing can be defined to take care of different cases. The below 'Generic Handler' example implements this.&lt;br /&gt;
&lt;br /&gt;
===Passing Parameters to an Undefined Method Call===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def add(a,b)&lt;br /&gt;
 a+b&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(name,*args,&amp;amp;block)    // the method_missing is defined and the *args parameter accepts all the parameters passed during 								                                 &lt;br /&gt;
                                             the method call   &lt;br /&gt;
 puts “You have typed the method name wrong and these were the parameters passed ; #{args[0]}, #{args[1]}”								&lt;br /&gt;
 end                         			&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The passed parameters are stored in the array 'args' and can be accessed like a normal array                &lt;br /&gt;
                                                   &lt;br /&gt;
 &lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.add(1,2)		        // calling the defined method add and passing the parameters (1,2)&lt;br /&gt;
 =&amp;gt; 3                           // result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.adds(4,2) 			// calling the undefined method adds and passing the parameter (4,2)&lt;br /&gt;
 =&amp;gt; You have typed the method name wrong and these were the parameters passed; 4, 2&lt;br /&gt;
&lt;br /&gt;
The user made a genuine mistake by typing 'adds', but this method is not defined. When the 'adds' method with parameters is called, the object 'a' tries to match the method in the method lookup path. Upon failure it invokes method_missing, the args are passed, stored in the array 'args' and the body of method_missing is executed.&lt;br /&gt;
&lt;br /&gt;
===Converting Numbers from Roman Representation to Integer Representation&amp;lt;ref&amp;gt;http://courses.ncsu.edu/csc517/common/lectures/notes/wk2.pdf&amp;lt;/ref&amp;gt;===&lt;br /&gt;
 class Roman&lt;br /&gt;
 DIGITS = {'I'=&amp;gt;1,'V'=&amp;gt;5,'X'=&amp;gt;10,'L'=&amp;gt;50,'C'=&amp;gt;100,'D'=&amp;gt;500,'M'=&amp;gt;1000,}&lt;br /&gt;
 def roman_to_integer(roman_string)&lt;br /&gt;
 last = nil&lt;br /&gt;
 roman_string.to_s.upcase.split(//).reverse.inject(0) do&lt;br /&gt;
 |memo, digit|&lt;br /&gt;
 if digit_value = DIGITS[digit]&lt;br /&gt;
 if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
 memo -= digit_value&lt;br /&gt;
 else&lt;br /&gt;
 memo += digit_value&lt;br /&gt;
 end&lt;br /&gt;
 last = digit_value&lt;br /&gt;
 end&lt;br /&gt;
 memo&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def method_missing(method)&lt;br /&gt;
 str=method.id2name&lt;br /&gt;
 roman_to_integer(str)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calling the undefined methods&lt;br /&gt;
&lt;br /&gt;
 r= Roman.new&lt;br /&gt;
 r.vii&lt;br /&gt;
 r.xxix&lt;br /&gt;
 r.xxiv&lt;br /&gt;
 r.xxvi&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The Output&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; 7&lt;br /&gt;
 =&amp;gt; 29&lt;br /&gt;
 =&amp;gt; 24&lt;br /&gt;
&lt;br /&gt;
===method_missing to log method calls&amp;lt;ref&amp;gt;http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2007/wiki1b_2_22&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Another application that makes use of method_missing could be a simple logger used for debugging purposes. Many times, it may be required to log the trace of called methods and provide information such as: called method-name, arguments, return type. It can be tedious to repeat this part of code in every method. A simple solution to this problem can be obtained using method_missing as:&lt;br /&gt;
&lt;br /&gt;
  class SimpleCallLogger&lt;br /&gt;
  def initialize(o)&lt;br /&gt;
  @obj = o&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(methodname, *args)&lt;br /&gt;
  puts &amp;quot;called: #{methodname}(#{args})&amp;quot;&lt;br /&gt;
  a = @obj.send(methodname, *args)&lt;br /&gt;
  puts &amp;quot;\t-&amp;gt; returned: #{a}&amp;quot;&lt;br /&gt;
  return a&lt;br /&gt;
  end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
This program makes use of method_missing in a way that it wraps around called method to output the logging information on entry and on exit, it logs the return type. Further, method_missing intercepts the method call and forward it to internal object with ‘send’ method of ruby. Hence, this use of method_missing acts as wrapper.&lt;br /&gt;
&lt;br /&gt;
===Generic Handler===&lt;br /&gt;
 class NoBar&lt;br /&gt;
 def method_missing(methodname, *args)&lt;br /&gt;
 define_method(:bar) if &amp;quot;bar&amp;quot; == methodname.to_s&lt;br /&gt;
 define_method(:nobar) if &amp;quot;nobar&amp;quot; == methodname.to_s&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This is an example of using method_missing as a generic handler to handle when a calling method is not exist. You can use missing_method to dynamically create a method at a runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Advantages of method_missing'''==&lt;br /&gt;
&lt;br /&gt;
*In addition to specifying the error messages for the undefined methods, method_missing provides a more dynamic behavior in the programming environment.&lt;br /&gt;
*If we are unfamiliar with the usage of the objects we created, then using method_missing is a good technique.&lt;br /&gt;
*Handles problems at runtime.&lt;br /&gt;
*Define's a generic method_missing and handle's any undefined method, a big advantage over Java. In Java, when you call an undefined method, the program will not compile.&lt;br /&gt;
*method_missing falls under the general technique of [http://en.wikipedia.org/wiki/Metaprogramming meta-programming]. Employ meta-programming in missing_function to write an another function to handle the call.&lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages of method_missing'''==	&lt;br /&gt;
*Slower than conventional method lookup. Simple tests indicate that method dispatch with method_missing is at least two to three times as expensive in time as conventional dispatch.&lt;br /&gt;
&lt;br /&gt;
*Since the methods being called never actually exist—they are just intercepted at the last step of the method lookup process—they cannot be documented or introspected as conventional methods can.&lt;br /&gt;
&lt;br /&gt;
*method_missing restricts compatibility with future versions of an [http://en.wikipedia.org/wiki/Application_programming_interface API]. Introducing new methods in a future API version can break users' expectations.&lt;br /&gt;
&lt;br /&gt;
=='''Key Points'''==&lt;br /&gt;
&lt;br /&gt;
*In the example below, class A defines only method method_missing() and no other method. When a new object of class A tries to access a method say 'foo', the respond_to? will return the value 'false'. When you actually try to implement it using “a.foo”, the code will get executed, courtesy of method_missing(). Even though the respond_to? says that you cannot access 'foo' method using object of class A, if you have method_missing() defined, you can access the method.&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In method_missing&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)&lt;br /&gt;
 a.foo&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 false&lt;br /&gt;
 In method_missing&lt;br /&gt;
&lt;br /&gt;
*In the following example, if within method_missing() we define an undefined method. &lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 @@i = 0&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In Method Missing #{@@i}&amp;quot;&lt;br /&gt;
 @@i += 1&lt;br /&gt;
 self.fun&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 a.foo &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 The result is a 'stack level too deep' error. &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
When the 'foo' method is called, after no method match the method_missing is run and this block has a method “self.fun” that is undefined.     Here when the program execution encounters 'self.fun' it once again calls method_missing. This goes on in an endless loop till the stack memory is full.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Ruby knows method_missing( ) exists, because it's a private instance method of 'BasicObject' that every object inherits. The BasicObject#method_missing( ) responds by raising the NoMethodError. Overriding this method_missing( ) allows you to call methods that don't really exist. &lt;br /&gt;
&lt;br /&gt;
*If method_missing is only looking for certain method names, don't forget to call the [http://en.wikibooks.org/wiki/Java_Programming/Keywords/super super] keyword if you haven't found what you're looking for, so that the other superclass' method_missing can handle it.&lt;br /&gt;
&lt;br /&gt;
*[http://www.prateekdayal.net/2007/10/16/rubys-responds_to-for-checking-if-a-method-exists/ obj.respond_to?] function returns 'true' if the obj responds to the given method. So if you want to know whether your class will respond to a function you can use respond_to? to know the answer. But if method_missing() is used, the output may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
*http://www.rubyinside.com/ &lt;br /&gt;
*https://www.youtube.com/watch?v=SAEiCkixrdE&amp;amp;feature=relmfu&lt;br /&gt;
*http://blog.jayfields.com/2008/02/ruby-replace-methodmissing-with-dynamic.html &lt;br /&gt;
*http://liquiddevelopment.blogspot.com/2006/04/twisting-and-shaping-dsls-using-ruby.html &lt;br /&gt;
*http://blog.rubybestpractices.com/posts/gregory/031-issue-2-method-lookup.html&lt;br /&gt;
*http://phrogz.net/RubyLibs/RubyMethodLookupFlow.pdf&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65298</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w22 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65298"/>
		<updated>2012-09-19T23:44:08Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* Calling defined and undefined methods */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''method_missing in Ruby:'''  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Introduction&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_method_missing.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
A method of a class is called by creating an object of the class and passing the method name to the object as a message. The object then looks up into its [http://www.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html method lookup path] and tries to match the called method with the defined methods in the class. On success, the method is executed along with the parameters passed and the result is returned.&lt;br /&gt;
&lt;br /&gt;
If the object does not find a match in its method lookup, in normal circumstances the [http://www.ruby-doc.org/core-1.9.3/NoMethodError.html NoMethodError Exception] is raised .&lt;br /&gt;
&lt;br /&gt;
In cases where the user wants to handle the methods which are not defined but still called, “method_missing” can be defined and the user can handle the methods as he/she sees fit.&lt;br /&gt;
&lt;br /&gt;
=='''Format for defining method_missing'''==&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; def method_missing(m,*args,&amp;amp;block)&lt;br /&gt;
&lt;br /&gt;
(i) '''m-&amp;gt;''' accepts the symbol/name of the undefined method (ii) '''*args-&amp;gt;''' accepts the array of arguments passed in the method call  (iii) '''&amp;amp;block-&amp;gt;'''accepts a block passed to the method&lt;br /&gt;
&lt;br /&gt;
=='''Ruby method Lookup Flow'''==&lt;br /&gt;
When the object of a class receives a method name to be executed, the following steps are carried out for matching and executing the method:&lt;br /&gt;
&lt;br /&gt;
*First, the object looks in its own [http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html instance methods].&lt;br /&gt;
*Second, it looks in the list of instance methods that all objects of that class share.&lt;br /&gt;
*Third, in each of the included [http://www.tutorialspoint.com/ruby/ruby_modules.html modules] of that class, in reverse order of inclusion. &lt;br /&gt;
*Fourth, it looks in that class’s superclass. &lt;br /&gt;
*Fifth, in the superclass’s included modules, all the way up until it reaches the class Object. &lt;br /&gt;
*Sixth, if it still can’t find a method, the very last place it looks is in the [http://linux.die.net/lkmpg/x40.html Kernel module], included in the class Object. &lt;br /&gt;
*Finally, it calls method_missing (if defined in the class), else throws up the NOMethodError exception.&lt;br /&gt;
&lt;br /&gt;
This entire tracing that the object does is the method lookup path.&lt;br /&gt;
&lt;br /&gt;
=='''Examples'''==&lt;br /&gt;
===Calling defined and undefined Methods===&lt;br /&gt;
&lt;br /&gt;
 class A		// creating a class 'A'&lt;br /&gt;
 def say		// defining a method 'say'&lt;br /&gt;
 puts &amp;quot; say Hi &amp;quot; // body of method say&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Creating the object of the class&lt;br /&gt;
 &lt;br /&gt;
  a=A.new	       // object of the class&lt;br /&gt;
  =&amp;gt; #&amp;lt;A:0x2a082e0&amp;gt;     //object id&lt;br /&gt;
&lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.say                  // defined method&lt;br /&gt;
 =&amp;gt; say Hi	       // returned result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.sayhi                // undefined method sayhi&lt;br /&gt;
 NoMethodError: undefined method `sayhi' for #&amp;lt;A:0x2a082e0&amp;gt;   // the NoMethodError is raised&lt;br /&gt;
&lt;br /&gt;
===method_missing Implementation&amp;lt;ref&amp;gt;http://www.thirdbit.net/articles/2007/08/01/10-things-you-should-know-about-method_missing/&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def say&lt;br /&gt;
 puts &amp;quot; say hi &amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(m,*args,&amp;amp;block)	// defining method_missing&lt;br /&gt;
 puts &amp;quot; This method does not exist&amp;quot;	// body of method_missing&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Calling a method that is not defined&lt;br /&gt;
 &lt;br /&gt;
 a=A.new&lt;br /&gt;
 a.sayhi                                // calling the undefined method sayhi with no arguments&lt;br /&gt;
 =&amp;gt; This method does not exist		// this result returned when method_missing is executed&lt;br /&gt;
&lt;br /&gt;
When the object 'a' traces its method lookup path for a matching method as 'sayhi', upon failure it resorts to method_missing and the body of method_missing is executed. 'method_missing' is the last resort.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Sometimes when a class has many methods that do generally the same kinds of things, and the programmer is not sure in advance which methods the user will call since there are so many of them, and they are all so similar, writing code for all of them seems futile. In these situations method_missing can be defined to take care of different cases. The below 'Generic Handler' example implements this.&lt;br /&gt;
&lt;br /&gt;
===Passing Parameters to an Undefined Method Call===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def add(a,b)&lt;br /&gt;
 a+b&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(name,*args,&amp;amp;block)    // the method_missing is defined and the *args parameter accepts all the parameters passed during 								                                 &lt;br /&gt;
                                             the method call   &lt;br /&gt;
 puts “You have typed the method name wrong and these were the parameters passed ; #{args[0]}, #{args[1]}”								&lt;br /&gt;
 end                         			&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The passed parameters are stored in the array 'args' and can be accessed like a normal array                &lt;br /&gt;
                                                   &lt;br /&gt;
 &lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.add(1,2)		        // calling the defined method add and passing the parameters (1,2)&lt;br /&gt;
 =&amp;gt; 3                           // result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.adds(4,2) 			// calling the undefined method adds and passing the parameter (4,2)&lt;br /&gt;
 =&amp;gt; You have typed the method name wrong and these were the parameters passed; 4, 2&lt;br /&gt;
&lt;br /&gt;
The user made a genuine mistake by typing 'adds', but this method is not defined. When the 'adds' method with parameters is called, the object 'a' tries to match the method in the method lookup path. Upon failure it invokes method_missing, the args are passed, stored in the array 'args' and the body of method_missing is executed.&lt;br /&gt;
&lt;br /&gt;
===Converting Numbers from Roman Representation to Integer representation&amp;lt;ref&amp;gt;http://courses.ncsu.edu/csc517/common/lectures/notes/wk2.pdf&amp;lt;/ref&amp;gt;===&lt;br /&gt;
 class Roman&lt;br /&gt;
 DIGITS = {'I'=&amp;gt;1,'V'=&amp;gt;5,'X'=&amp;gt;10,'L'=&amp;gt;50,'C'=&amp;gt;100,'D'=&amp;gt;500,'M'=&amp;gt;1000,}&lt;br /&gt;
 def roman_to_integer(roman_string)&lt;br /&gt;
 last = nil&lt;br /&gt;
 roman_string.to_s.upcase.split(//).reverse.inject(0) do&lt;br /&gt;
 |memo, digit|&lt;br /&gt;
 if digit_value = DIGITS[digit]&lt;br /&gt;
 if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
 memo -= digit_value&lt;br /&gt;
 else&lt;br /&gt;
 memo += digit_value&lt;br /&gt;
 end&lt;br /&gt;
 last = digit_value&lt;br /&gt;
 end&lt;br /&gt;
 memo&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def method_missing(method)&lt;br /&gt;
 str=method.id2name&lt;br /&gt;
 roman_to_integer(str)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calling the undefined methods&lt;br /&gt;
&lt;br /&gt;
 r= Roman.new&lt;br /&gt;
 r.vii&lt;br /&gt;
 r.xxix&lt;br /&gt;
 r.xxiv&lt;br /&gt;
 r.xxvi&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The Output&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; 7&lt;br /&gt;
 =&amp;gt; 29&lt;br /&gt;
 =&amp;gt; 24&lt;br /&gt;
&lt;br /&gt;
===method_missing to log method calls&amp;lt;ref&amp;gt;http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2007/wiki1b_2_22&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Another application that makes use of method_missing could be a simple logger used for debugging purposes. Many times, it may be required to log the trace of called methods and provide information such as: called method-name, arguments, return type. It can be tedious to repeat this part of code in every method. A simple solution to this problem can be obtained using method_missing as:&lt;br /&gt;
&lt;br /&gt;
  class SimpleCallLogger&lt;br /&gt;
  def initialize(o)&lt;br /&gt;
  @obj = o&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(methodname, *args)&lt;br /&gt;
  puts &amp;quot;called: #{methodname}(#{args})&amp;quot;&lt;br /&gt;
  a = @obj.send(methodname, *args)&lt;br /&gt;
  puts &amp;quot;\t-&amp;gt; returned: #{a}&amp;quot;&lt;br /&gt;
  return a&lt;br /&gt;
  end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
This program makes use of method_missing in a way that it wraps around called method to output the logging information on entry and on exit, it logs the return type. Further, method_missing intercepts the method call and forward it to internal object with ‘send’ method of ruby. Hence, this use of method_missing acts as wrapper.&lt;br /&gt;
&lt;br /&gt;
===Generic Handler===&lt;br /&gt;
 class NoBar&lt;br /&gt;
 def method_missing(methodname, *args)&lt;br /&gt;
 define_method(:bar) if &amp;quot;bar&amp;quot; == methodname.to_s&lt;br /&gt;
 define_method(:nobar) if &amp;quot;nobar&amp;quot; == methodname.to_s&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This is an example of using method_missing as a generic handler to handle when a calling method is not exist. You can use missing_method to dynamically create a method at a runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Advantages of method_missing'''==&lt;br /&gt;
&lt;br /&gt;
*In addition to specifying the error messages for the undefined methods, method_missing provides a more dynamic behavior in the programming environment.&lt;br /&gt;
*If we are unfamiliar with the usage of the objects we created, then using method_missing is a good technique.&lt;br /&gt;
*Handles problems at runtime.&lt;br /&gt;
*Define's a generic method_missing and handle's any undefined method, a big advantage over Java. In Java, when you call an undefined method, the program will not compile.&lt;br /&gt;
*method_missing falls under the general technique of [http://en.wikipedia.org/wiki/Metaprogramming meta-programming]. Employ meta-programming in missing_function to write an another function to handle the call.&lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages of method_missing'''==	&lt;br /&gt;
*Slower than conventional method lookup. Simple tests indicate that method dispatch with method_missing is at least two to three times as expensive in time as conventional dispatch.&lt;br /&gt;
&lt;br /&gt;
*Since the methods being called never actually exist—they are just intercepted at the last step of the method lookup process—they cannot be documented or introspected as conventional methods can.&lt;br /&gt;
&lt;br /&gt;
*method_missing restricts compatibility with future versions of an [http://en.wikipedia.org/wiki/Application_programming_interface API]. Introducing new methods in a future API version can break users' expectations.&lt;br /&gt;
&lt;br /&gt;
=='''Key Points'''==&lt;br /&gt;
&lt;br /&gt;
*In the example below, class A defines only method method_missing() and no other method. When a new object of class A tries to access a method say 'foo', the respond_to? will return the value 'false'. When you actually try to implement it using “a.foo”, the code will get executed, courtesy of method_missing(). Even though the respond_to? says that you cannot access 'foo' method using object of class A, if you have method_missing() defined, you can access the method.&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In method_missing&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)&lt;br /&gt;
 a.foo&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 false&lt;br /&gt;
 In method_missing&lt;br /&gt;
&lt;br /&gt;
*In the following example, if within method_missing() we define an undefined method. &lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 @@i = 0&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In Method Missing #{@@i}&amp;quot;&lt;br /&gt;
 @@i += 1&lt;br /&gt;
 self.fun&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 a.foo &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 The result is a 'stack level too deep' error. &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
When the 'foo' method is called, after no method match the method_missing is run and this block has a method “self.fun” that is undefined.     Here when the program execution encounters 'self.fun' it once again calls method_missing. This goes on in an endless loop till the stack memory is full.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Ruby knows method_missing( ) exists, because it's a private instance method of 'BasicObject' that every object inherits. The BasicObject#method_missing( ) responds by raising the NoMethodError. Overriding this method_missing( ) allows you to call methods that don't really exist. &lt;br /&gt;
&lt;br /&gt;
*If method_missing is only looking for certain method names, don't forget to call the [http://en.wikibooks.org/wiki/Java_Programming/Keywords/super super] keyword if you haven't found what you're looking for, so that the other superclass' method_missing can handle it.&lt;br /&gt;
&lt;br /&gt;
*[http://www.prateekdayal.net/2007/10/16/rubys-responds_to-for-checking-if-a-method-exists/ obj.respond_to?] function returns 'true' if the obj responds to the given method. So if you want to know whether your class will respond to a function you can use respond_to? to know the answer. But if method_missing() is used, the output may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
*http://www.rubyinside.com/ &lt;br /&gt;
*https://www.youtube.com/watch?v=SAEiCkixrdE&amp;amp;feature=relmfu&lt;br /&gt;
*http://blog.jayfields.com/2008/02/ruby-replace-methodmissing-with-dynamic.html &lt;br /&gt;
*http://liquiddevelopment.blogspot.com/2006/04/twisting-and-shaping-dsls-using-ruby.html &lt;br /&gt;
*http://blog.rubybestpractices.com/posts/gregory/031-issue-2-method-lookup.html&lt;br /&gt;
*http://phrogz.net/RubyLibs/RubyMethodLookupFlow.pdf&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65297</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w22 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65297"/>
		<updated>2012-09-19T23:43:49Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* Ruby method lookup flow */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''method_missing in Ruby:'''  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Introduction&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_method_missing.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
A method of a class is called by creating an object of the class and passing the method name to the object as a message. The object then looks up into its [http://www.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html method lookup path] and tries to match the called method with the defined methods in the class. On success, the method is executed along with the parameters passed and the result is returned.&lt;br /&gt;
&lt;br /&gt;
If the object does not find a match in its method lookup, in normal circumstances the [http://www.ruby-doc.org/core-1.9.3/NoMethodError.html NoMethodError Exception] is raised .&lt;br /&gt;
&lt;br /&gt;
In cases where the user wants to handle the methods which are not defined but still called, “method_missing” can be defined and the user can handle the methods as he/she sees fit.&lt;br /&gt;
&lt;br /&gt;
=='''Format for defining method_missing'''==&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; def method_missing(m,*args,&amp;amp;block)&lt;br /&gt;
&lt;br /&gt;
(i) '''m-&amp;gt;''' accepts the symbol/name of the undefined method (ii) '''*args-&amp;gt;''' accepts the array of arguments passed in the method call  (iii) '''&amp;amp;block-&amp;gt;'''accepts a block passed to the method&lt;br /&gt;
&lt;br /&gt;
=='''Ruby method Lookup Flow'''==&lt;br /&gt;
When the object of a class receives a method name to be executed, the following steps are carried out for matching and executing the method:&lt;br /&gt;
&lt;br /&gt;
*First, the object looks in its own [http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html instance methods].&lt;br /&gt;
*Second, it looks in the list of instance methods that all objects of that class share.&lt;br /&gt;
*Third, in each of the included [http://www.tutorialspoint.com/ruby/ruby_modules.html modules] of that class, in reverse order of inclusion. &lt;br /&gt;
*Fourth, it looks in that class’s superclass. &lt;br /&gt;
*Fifth, in the superclass’s included modules, all the way up until it reaches the class Object. &lt;br /&gt;
*Sixth, if it still can’t find a method, the very last place it looks is in the [http://linux.die.net/lkmpg/x40.html Kernel module], included in the class Object. &lt;br /&gt;
*Finally, it calls method_missing (if defined in the class), else throws up the NOMethodError exception.&lt;br /&gt;
&lt;br /&gt;
This entire tracing that the object does is the method lookup path.&lt;br /&gt;
&lt;br /&gt;
=='''Examples'''==&lt;br /&gt;
===Calling defined and undefined methods===&lt;br /&gt;
&lt;br /&gt;
 class A		// creating a class 'A'&lt;br /&gt;
 def say		// defining a method 'say'&lt;br /&gt;
 puts &amp;quot; say Hi &amp;quot; // body of method say&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Creating the object of the class&lt;br /&gt;
 &lt;br /&gt;
  a=A.new	       // object of the class&lt;br /&gt;
  =&amp;gt; #&amp;lt;A:0x2a082e0&amp;gt;     //object id&lt;br /&gt;
&lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.say                  // defined method&lt;br /&gt;
 =&amp;gt; say Hi	       // returned result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.sayhi                // undefined method sayhi&lt;br /&gt;
 NoMethodError: undefined method `sayhi' for #&amp;lt;A:0x2a082e0&amp;gt;   // the NoMethodError is raised&lt;br /&gt;
&lt;br /&gt;
===method_missing Implementation&amp;lt;ref&amp;gt;http://www.thirdbit.net/articles/2007/08/01/10-things-you-should-know-about-method_missing/&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def say&lt;br /&gt;
 puts &amp;quot; say hi &amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(m,*args,&amp;amp;block)	// defining method_missing&lt;br /&gt;
 puts &amp;quot; This method does not exist&amp;quot;	// body of method_missing&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Calling a method that is not defined&lt;br /&gt;
 &lt;br /&gt;
 a=A.new&lt;br /&gt;
 a.sayhi                                // calling the undefined method sayhi with no arguments&lt;br /&gt;
 =&amp;gt; This method does not exist		// this result returned when method_missing is executed&lt;br /&gt;
&lt;br /&gt;
When the object 'a' traces its method lookup path for a matching method as 'sayhi', upon failure it resorts to method_missing and the body of method_missing is executed. 'method_missing' is the last resort.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Sometimes when a class has many methods that do generally the same kinds of things, and the programmer is not sure in advance which methods the user will call since there are so many of them, and they are all so similar, writing code for all of them seems futile. In these situations method_missing can be defined to take care of different cases. The below 'Generic Handler' example implements this.&lt;br /&gt;
&lt;br /&gt;
===Passing Parameters to an Undefined Method Call===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def add(a,b)&lt;br /&gt;
 a+b&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(name,*args,&amp;amp;block)    // the method_missing is defined and the *args parameter accepts all the parameters passed during 								                                 &lt;br /&gt;
                                             the method call   &lt;br /&gt;
 puts “You have typed the method name wrong and these were the parameters passed ; #{args[0]}, #{args[1]}”								&lt;br /&gt;
 end                         			&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The passed parameters are stored in the array 'args' and can be accessed like a normal array                &lt;br /&gt;
                                                   &lt;br /&gt;
 &lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.add(1,2)		        // calling the defined method add and passing the parameters (1,2)&lt;br /&gt;
 =&amp;gt; 3                           // result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.adds(4,2) 			// calling the undefined method adds and passing the parameter (4,2)&lt;br /&gt;
 =&amp;gt; You have typed the method name wrong and these were the parameters passed; 4, 2&lt;br /&gt;
&lt;br /&gt;
The user made a genuine mistake by typing 'adds', but this method is not defined. When the 'adds' method with parameters is called, the object 'a' tries to match the method in the method lookup path. Upon failure it invokes method_missing, the args are passed, stored in the array 'args' and the body of method_missing is executed.&lt;br /&gt;
&lt;br /&gt;
===Converting Numbers from Roman Representation to Integer representation&amp;lt;ref&amp;gt;http://courses.ncsu.edu/csc517/common/lectures/notes/wk2.pdf&amp;lt;/ref&amp;gt;===&lt;br /&gt;
 class Roman&lt;br /&gt;
 DIGITS = {'I'=&amp;gt;1,'V'=&amp;gt;5,'X'=&amp;gt;10,'L'=&amp;gt;50,'C'=&amp;gt;100,'D'=&amp;gt;500,'M'=&amp;gt;1000,}&lt;br /&gt;
 def roman_to_integer(roman_string)&lt;br /&gt;
 last = nil&lt;br /&gt;
 roman_string.to_s.upcase.split(//).reverse.inject(0) do&lt;br /&gt;
 |memo, digit|&lt;br /&gt;
 if digit_value = DIGITS[digit]&lt;br /&gt;
 if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
 memo -= digit_value&lt;br /&gt;
 else&lt;br /&gt;
 memo += digit_value&lt;br /&gt;
 end&lt;br /&gt;
 last = digit_value&lt;br /&gt;
 end&lt;br /&gt;
 memo&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def method_missing(method)&lt;br /&gt;
 str=method.id2name&lt;br /&gt;
 roman_to_integer(str)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calling the undefined methods&lt;br /&gt;
&lt;br /&gt;
 r= Roman.new&lt;br /&gt;
 r.vii&lt;br /&gt;
 r.xxix&lt;br /&gt;
 r.xxiv&lt;br /&gt;
 r.xxvi&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The Output&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; 7&lt;br /&gt;
 =&amp;gt; 29&lt;br /&gt;
 =&amp;gt; 24&lt;br /&gt;
&lt;br /&gt;
===method_missing to log method calls&amp;lt;ref&amp;gt;http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2007/wiki1b_2_22&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Another application that makes use of method_missing could be a simple logger used for debugging purposes. Many times, it may be required to log the trace of called methods and provide information such as: called method-name, arguments, return type. It can be tedious to repeat this part of code in every method. A simple solution to this problem can be obtained using method_missing as:&lt;br /&gt;
&lt;br /&gt;
  class SimpleCallLogger&lt;br /&gt;
  def initialize(o)&lt;br /&gt;
  @obj = o&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(methodname, *args)&lt;br /&gt;
  puts &amp;quot;called: #{methodname}(#{args})&amp;quot;&lt;br /&gt;
  a = @obj.send(methodname, *args)&lt;br /&gt;
  puts &amp;quot;\t-&amp;gt; returned: #{a}&amp;quot;&lt;br /&gt;
  return a&lt;br /&gt;
  end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
This program makes use of method_missing in a way that it wraps around called method to output the logging information on entry and on exit, it logs the return type. Further, method_missing intercepts the method call and forward it to internal object with ‘send’ method of ruby. Hence, this use of method_missing acts as wrapper.&lt;br /&gt;
&lt;br /&gt;
===Generic Handler===&lt;br /&gt;
 class NoBar&lt;br /&gt;
 def method_missing(methodname, *args)&lt;br /&gt;
 define_method(:bar) if &amp;quot;bar&amp;quot; == methodname.to_s&lt;br /&gt;
 define_method(:nobar) if &amp;quot;nobar&amp;quot; == methodname.to_s&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This is an example of using method_missing as a generic handler to handle when a calling method is not exist. You can use missing_method to dynamically create a method at a runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Advantages of method_missing'''==&lt;br /&gt;
&lt;br /&gt;
*In addition to specifying the error messages for the undefined methods, method_missing provides a more dynamic behavior in the programming environment.&lt;br /&gt;
*If we are unfamiliar with the usage of the objects we created, then using method_missing is a good technique.&lt;br /&gt;
*Handles problems at runtime.&lt;br /&gt;
*Define's a generic method_missing and handle's any undefined method, a big advantage over Java. In Java, when you call an undefined method, the program will not compile.&lt;br /&gt;
*method_missing falls under the general technique of [http://en.wikipedia.org/wiki/Metaprogramming meta-programming]. Employ meta-programming in missing_function to write an another function to handle the call.&lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages of method_missing'''==	&lt;br /&gt;
*Slower than conventional method lookup. Simple tests indicate that method dispatch with method_missing is at least two to three times as expensive in time as conventional dispatch.&lt;br /&gt;
&lt;br /&gt;
*Since the methods being called never actually exist—they are just intercepted at the last step of the method lookup process—they cannot be documented or introspected as conventional methods can.&lt;br /&gt;
&lt;br /&gt;
*method_missing restricts compatibility with future versions of an [http://en.wikipedia.org/wiki/Application_programming_interface API]. Introducing new methods in a future API version can break users' expectations.&lt;br /&gt;
&lt;br /&gt;
=='''Key Points'''==&lt;br /&gt;
&lt;br /&gt;
*In the example below, class A defines only method method_missing() and no other method. When a new object of class A tries to access a method say 'foo', the respond_to? will return the value 'false'. When you actually try to implement it using “a.foo”, the code will get executed, courtesy of method_missing(). Even though the respond_to? says that you cannot access 'foo' method using object of class A, if you have method_missing() defined, you can access the method.&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In method_missing&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)&lt;br /&gt;
 a.foo&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 false&lt;br /&gt;
 In method_missing&lt;br /&gt;
&lt;br /&gt;
*In the following example, if within method_missing() we define an undefined method. &lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 @@i = 0&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In Method Missing #{@@i}&amp;quot;&lt;br /&gt;
 @@i += 1&lt;br /&gt;
 self.fun&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 a.foo &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 The result is a 'stack level too deep' error. &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
When the 'foo' method is called, after no method match the method_missing is run and this block has a method “self.fun” that is undefined.     Here when the program execution encounters 'self.fun' it once again calls method_missing. This goes on in an endless loop till the stack memory is full.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Ruby knows method_missing( ) exists, because it's a private instance method of 'BasicObject' that every object inherits. The BasicObject#method_missing( ) responds by raising the NoMethodError. Overriding this method_missing( ) allows you to call methods that don't really exist. &lt;br /&gt;
&lt;br /&gt;
*If method_missing is only looking for certain method names, don't forget to call the [http://en.wikibooks.org/wiki/Java_Programming/Keywords/super super] keyword if you haven't found what you're looking for, so that the other superclass' method_missing can handle it.&lt;br /&gt;
&lt;br /&gt;
*[http://www.prateekdayal.net/2007/10/16/rubys-responds_to-for-checking-if-a-method-exists/ obj.respond_to?] function returns 'true' if the obj responds to the given method. So if you want to know whether your class will respond to a function you can use respond_to? to know the answer. But if method_missing() is used, the output may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
*http://www.rubyinside.com/ &lt;br /&gt;
*https://www.youtube.com/watch?v=SAEiCkixrdE&amp;amp;feature=relmfu&lt;br /&gt;
*http://blog.jayfields.com/2008/02/ruby-replace-methodmissing-with-dynamic.html &lt;br /&gt;
*http://liquiddevelopment.blogspot.com/2006/04/twisting-and-shaping-dsls-using-ruby.html &lt;br /&gt;
*http://blog.rubybestpractices.com/posts/gregory/031-issue-2-method-lookup.html&lt;br /&gt;
*http://phrogz.net/RubyLibs/RubyMethodLookupFlow.pdf&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65296</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w22 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65296"/>
		<updated>2012-09-19T23:43:22Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* converting numbers from roman representation to integer representationhttp://courses.ncsu.edu/csc517/common/lectures/notes/wk2.pdf */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''method_missing in Ruby:'''  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Introduction&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_method_missing.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
A method of a class is called by creating an object of the class and passing the method name to the object as a message. The object then looks up into its [http://www.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html method lookup path] and tries to match the called method with the defined methods in the class. On success, the method is executed along with the parameters passed and the result is returned.&lt;br /&gt;
&lt;br /&gt;
If the object does not find a match in its method lookup, in normal circumstances the [http://www.ruby-doc.org/core-1.9.3/NoMethodError.html NoMethodError Exception] is raised .&lt;br /&gt;
&lt;br /&gt;
In cases where the user wants to handle the methods which are not defined but still called, “method_missing” can be defined and the user can handle the methods as he/she sees fit.&lt;br /&gt;
&lt;br /&gt;
=='''Format for defining method_missing'''==&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; def method_missing(m,*args,&amp;amp;block)&lt;br /&gt;
&lt;br /&gt;
(i) '''m-&amp;gt;''' accepts the symbol/name of the undefined method (ii) '''*args-&amp;gt;''' accepts the array of arguments passed in the method call  (iii) '''&amp;amp;block-&amp;gt;'''accepts a block passed to the method&lt;br /&gt;
&lt;br /&gt;
=='''Ruby method lookup flow'''==&lt;br /&gt;
When the object of a class receives a method name to be executed, the following steps are carried out for matching and executing the method:&lt;br /&gt;
&lt;br /&gt;
*First, the object looks in its own [http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html instance methods].&lt;br /&gt;
*Second, it looks in the list of instance methods that all objects of that class share.&lt;br /&gt;
*Third, in each of the included [http://www.tutorialspoint.com/ruby/ruby_modules.html modules] of that class, in reverse order of inclusion. &lt;br /&gt;
*Fourth, it looks in that class’s superclass. &lt;br /&gt;
*Fifth, in the superclass’s included modules, all the way up until it reaches the class Object. &lt;br /&gt;
*Sixth, if it still can’t find a method, the very last place it looks is in the [http://linux.die.net/lkmpg/x40.html Kernel module], included in the class Object. &lt;br /&gt;
*Finally, it calls method_missing (if defined in the class), else throws up the NOMethodError exception.&lt;br /&gt;
&lt;br /&gt;
This entire tracing that the object does is the method lookup path.&lt;br /&gt;
&lt;br /&gt;
=='''Examples'''==&lt;br /&gt;
===Calling defined and undefined methods===&lt;br /&gt;
&lt;br /&gt;
 class A		// creating a class 'A'&lt;br /&gt;
 def say		// defining a method 'say'&lt;br /&gt;
 puts &amp;quot; say Hi &amp;quot; // body of method say&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Creating the object of the class&lt;br /&gt;
 &lt;br /&gt;
  a=A.new	       // object of the class&lt;br /&gt;
  =&amp;gt; #&amp;lt;A:0x2a082e0&amp;gt;     //object id&lt;br /&gt;
&lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.say                  // defined method&lt;br /&gt;
 =&amp;gt; say Hi	       // returned result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.sayhi                // undefined method sayhi&lt;br /&gt;
 NoMethodError: undefined method `sayhi' for #&amp;lt;A:0x2a082e0&amp;gt;   // the NoMethodError is raised&lt;br /&gt;
&lt;br /&gt;
===method_missing Implementation&amp;lt;ref&amp;gt;http://www.thirdbit.net/articles/2007/08/01/10-things-you-should-know-about-method_missing/&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def say&lt;br /&gt;
 puts &amp;quot; say hi &amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(m,*args,&amp;amp;block)	// defining method_missing&lt;br /&gt;
 puts &amp;quot; This method does not exist&amp;quot;	// body of method_missing&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Calling a method that is not defined&lt;br /&gt;
 &lt;br /&gt;
 a=A.new&lt;br /&gt;
 a.sayhi                                // calling the undefined method sayhi with no arguments&lt;br /&gt;
 =&amp;gt; This method does not exist		// this result returned when method_missing is executed&lt;br /&gt;
&lt;br /&gt;
When the object 'a' traces its method lookup path for a matching method as 'sayhi', upon failure it resorts to method_missing and the body of method_missing is executed. 'method_missing' is the last resort.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Sometimes when a class has many methods that do generally the same kinds of things, and the programmer is not sure in advance which methods the user will call since there are so many of them, and they are all so similar, writing code for all of them seems futile. In these situations method_missing can be defined to take care of different cases. The below 'Generic Handler' example implements this.&lt;br /&gt;
&lt;br /&gt;
===Passing Parameters to an Undefined Method Call===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def add(a,b)&lt;br /&gt;
 a+b&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(name,*args,&amp;amp;block)    // the method_missing is defined and the *args parameter accepts all the parameters passed during 								                                 &lt;br /&gt;
                                             the method call   &lt;br /&gt;
 puts “You have typed the method name wrong and these were the parameters passed ; #{args[0]}, #{args[1]}”								&lt;br /&gt;
 end                         			&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The passed parameters are stored in the array 'args' and can be accessed like a normal array                &lt;br /&gt;
                                                   &lt;br /&gt;
 &lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.add(1,2)		        // calling the defined method add and passing the parameters (1,2)&lt;br /&gt;
 =&amp;gt; 3                           // result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.adds(4,2) 			// calling the undefined method adds and passing the parameter (4,2)&lt;br /&gt;
 =&amp;gt; You have typed the method name wrong and these were the parameters passed; 4, 2&lt;br /&gt;
&lt;br /&gt;
The user made a genuine mistake by typing 'adds', but this method is not defined. When the 'adds' method with parameters is called, the object 'a' tries to match the method in the method lookup path. Upon failure it invokes method_missing, the args are passed, stored in the array 'args' and the body of method_missing is executed.&lt;br /&gt;
&lt;br /&gt;
===Converting Numbers from Roman Representation to Integer representation&amp;lt;ref&amp;gt;http://courses.ncsu.edu/csc517/common/lectures/notes/wk2.pdf&amp;lt;/ref&amp;gt;===&lt;br /&gt;
 class Roman&lt;br /&gt;
 DIGITS = {'I'=&amp;gt;1,'V'=&amp;gt;5,'X'=&amp;gt;10,'L'=&amp;gt;50,'C'=&amp;gt;100,'D'=&amp;gt;500,'M'=&amp;gt;1000,}&lt;br /&gt;
 def roman_to_integer(roman_string)&lt;br /&gt;
 last = nil&lt;br /&gt;
 roman_string.to_s.upcase.split(//).reverse.inject(0) do&lt;br /&gt;
 |memo, digit|&lt;br /&gt;
 if digit_value = DIGITS[digit]&lt;br /&gt;
 if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
 memo -= digit_value&lt;br /&gt;
 else&lt;br /&gt;
 memo += digit_value&lt;br /&gt;
 end&lt;br /&gt;
 last = digit_value&lt;br /&gt;
 end&lt;br /&gt;
 memo&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def method_missing(method)&lt;br /&gt;
 str=method.id2name&lt;br /&gt;
 roman_to_integer(str)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calling the undefined methods&lt;br /&gt;
&lt;br /&gt;
 r= Roman.new&lt;br /&gt;
 r.vii&lt;br /&gt;
 r.xxix&lt;br /&gt;
 r.xxiv&lt;br /&gt;
 r.xxvi&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The Output&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; 7&lt;br /&gt;
 =&amp;gt; 29&lt;br /&gt;
 =&amp;gt; 24&lt;br /&gt;
&lt;br /&gt;
===method_missing to log method calls&amp;lt;ref&amp;gt;http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2007/wiki1b_2_22&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Another application that makes use of method_missing could be a simple logger used for debugging purposes. Many times, it may be required to log the trace of called methods and provide information such as: called method-name, arguments, return type. It can be tedious to repeat this part of code in every method. A simple solution to this problem can be obtained using method_missing as:&lt;br /&gt;
&lt;br /&gt;
  class SimpleCallLogger&lt;br /&gt;
  def initialize(o)&lt;br /&gt;
  @obj = o&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(methodname, *args)&lt;br /&gt;
  puts &amp;quot;called: #{methodname}(#{args})&amp;quot;&lt;br /&gt;
  a = @obj.send(methodname, *args)&lt;br /&gt;
  puts &amp;quot;\t-&amp;gt; returned: #{a}&amp;quot;&lt;br /&gt;
  return a&lt;br /&gt;
  end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
This program makes use of method_missing in a way that it wraps around called method to output the logging information on entry and on exit, it logs the return type. Further, method_missing intercepts the method call and forward it to internal object with ‘send’ method of ruby. Hence, this use of method_missing acts as wrapper.&lt;br /&gt;
&lt;br /&gt;
===Generic Handler===&lt;br /&gt;
 class NoBar&lt;br /&gt;
 def method_missing(methodname, *args)&lt;br /&gt;
 define_method(:bar) if &amp;quot;bar&amp;quot; == methodname.to_s&lt;br /&gt;
 define_method(:nobar) if &amp;quot;nobar&amp;quot; == methodname.to_s&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This is an example of using method_missing as a generic handler to handle when a calling method is not exist. You can use missing_method to dynamically create a method at a runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Advantages of method_missing'''==&lt;br /&gt;
&lt;br /&gt;
*In addition to specifying the error messages for the undefined methods, method_missing provides a more dynamic behavior in the programming environment.&lt;br /&gt;
*If we are unfamiliar with the usage of the objects we created, then using method_missing is a good technique.&lt;br /&gt;
*Handles problems at runtime.&lt;br /&gt;
*Define's a generic method_missing and handle's any undefined method, a big advantage over Java. In Java, when you call an undefined method, the program will not compile.&lt;br /&gt;
*method_missing falls under the general technique of [http://en.wikipedia.org/wiki/Metaprogramming meta-programming]. Employ meta-programming in missing_function to write an another function to handle the call.&lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages of method_missing'''==	&lt;br /&gt;
*Slower than conventional method lookup. Simple tests indicate that method dispatch with method_missing is at least two to three times as expensive in time as conventional dispatch.&lt;br /&gt;
&lt;br /&gt;
*Since the methods being called never actually exist—they are just intercepted at the last step of the method lookup process—they cannot be documented or introspected as conventional methods can.&lt;br /&gt;
&lt;br /&gt;
*method_missing restricts compatibility with future versions of an [http://en.wikipedia.org/wiki/Application_programming_interface API]. Introducing new methods in a future API version can break users' expectations.&lt;br /&gt;
&lt;br /&gt;
=='''Key Points'''==&lt;br /&gt;
&lt;br /&gt;
*In the example below, class A defines only method method_missing() and no other method. When a new object of class A tries to access a method say 'foo', the respond_to? will return the value 'false'. When you actually try to implement it using “a.foo”, the code will get executed, courtesy of method_missing(). Even though the respond_to? says that you cannot access 'foo' method using object of class A, if you have method_missing() defined, you can access the method.&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In method_missing&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)&lt;br /&gt;
 a.foo&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 false&lt;br /&gt;
 In method_missing&lt;br /&gt;
&lt;br /&gt;
*In the following example, if within method_missing() we define an undefined method. &lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 @@i = 0&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In Method Missing #{@@i}&amp;quot;&lt;br /&gt;
 @@i += 1&lt;br /&gt;
 self.fun&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 a.foo &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 The result is a 'stack level too deep' error. &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
When the 'foo' method is called, after no method match the method_missing is run and this block has a method “self.fun” that is undefined.     Here when the program execution encounters 'self.fun' it once again calls method_missing. This goes on in an endless loop till the stack memory is full.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Ruby knows method_missing( ) exists, because it's a private instance method of 'BasicObject' that every object inherits. The BasicObject#method_missing( ) responds by raising the NoMethodError. Overriding this method_missing( ) allows you to call methods that don't really exist. &lt;br /&gt;
&lt;br /&gt;
*If method_missing is only looking for certain method names, don't forget to call the [http://en.wikibooks.org/wiki/Java_Programming/Keywords/super super] keyword if you haven't found what you're looking for, so that the other superclass' method_missing can handle it.&lt;br /&gt;
&lt;br /&gt;
*[http://www.prateekdayal.net/2007/10/16/rubys-responds_to-for-checking-if-a-method-exists/ obj.respond_to?] function returns 'true' if the obj responds to the given method. So if you want to know whether your class will respond to a function you can use respond_to? to know the answer. But if method_missing() is used, the output may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
*http://www.rubyinside.com/ &lt;br /&gt;
*https://www.youtube.com/watch?v=SAEiCkixrdE&amp;amp;feature=relmfu&lt;br /&gt;
*http://blog.jayfields.com/2008/02/ruby-replace-methodmissing-with-dynamic.html &lt;br /&gt;
*http://liquiddevelopment.blogspot.com/2006/04/twisting-and-shaping-dsls-using-ruby.html &lt;br /&gt;
*http://blog.rubybestpractices.com/posts/gregory/031-issue-2-method-lookup.html&lt;br /&gt;
*http://phrogz.net/RubyLibs/RubyMethodLookupFlow.pdf&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65295</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w22 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65295"/>
		<updated>2012-09-19T23:42:58Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* passing parameters to an undefined method call */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''method_missing in Ruby:'''  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Introduction&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_method_missing.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
A method of a class is called by creating an object of the class and passing the method name to the object as a message. The object then looks up into its [http://www.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html method lookup path] and tries to match the called method with the defined methods in the class. On success, the method is executed along with the parameters passed and the result is returned.&lt;br /&gt;
&lt;br /&gt;
If the object does not find a match in its method lookup, in normal circumstances the [http://www.ruby-doc.org/core-1.9.3/NoMethodError.html NoMethodError Exception] is raised .&lt;br /&gt;
&lt;br /&gt;
In cases where the user wants to handle the methods which are not defined but still called, “method_missing” can be defined and the user can handle the methods as he/she sees fit.&lt;br /&gt;
&lt;br /&gt;
=='''Format for defining method_missing'''==&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; def method_missing(m,*args,&amp;amp;block)&lt;br /&gt;
&lt;br /&gt;
(i) '''m-&amp;gt;''' accepts the symbol/name of the undefined method (ii) '''*args-&amp;gt;''' accepts the array of arguments passed in the method call  (iii) '''&amp;amp;block-&amp;gt;'''accepts a block passed to the method&lt;br /&gt;
&lt;br /&gt;
=='''Ruby method lookup flow'''==&lt;br /&gt;
When the object of a class receives a method name to be executed, the following steps are carried out for matching and executing the method:&lt;br /&gt;
&lt;br /&gt;
*First, the object looks in its own [http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html instance methods].&lt;br /&gt;
*Second, it looks in the list of instance methods that all objects of that class share.&lt;br /&gt;
*Third, in each of the included [http://www.tutorialspoint.com/ruby/ruby_modules.html modules] of that class, in reverse order of inclusion. &lt;br /&gt;
*Fourth, it looks in that class’s superclass. &lt;br /&gt;
*Fifth, in the superclass’s included modules, all the way up until it reaches the class Object. &lt;br /&gt;
*Sixth, if it still can’t find a method, the very last place it looks is in the [http://linux.die.net/lkmpg/x40.html Kernel module], included in the class Object. &lt;br /&gt;
*Finally, it calls method_missing (if defined in the class), else throws up the NOMethodError exception.&lt;br /&gt;
&lt;br /&gt;
This entire tracing that the object does is the method lookup path.&lt;br /&gt;
&lt;br /&gt;
=='''Examples'''==&lt;br /&gt;
===Calling defined and undefined methods===&lt;br /&gt;
&lt;br /&gt;
 class A		// creating a class 'A'&lt;br /&gt;
 def say		// defining a method 'say'&lt;br /&gt;
 puts &amp;quot; say Hi &amp;quot; // body of method say&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Creating the object of the class&lt;br /&gt;
 &lt;br /&gt;
  a=A.new	       // object of the class&lt;br /&gt;
  =&amp;gt; #&amp;lt;A:0x2a082e0&amp;gt;     //object id&lt;br /&gt;
&lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.say                  // defined method&lt;br /&gt;
 =&amp;gt; say Hi	       // returned result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.sayhi                // undefined method sayhi&lt;br /&gt;
 NoMethodError: undefined method `sayhi' for #&amp;lt;A:0x2a082e0&amp;gt;   // the NoMethodError is raised&lt;br /&gt;
&lt;br /&gt;
===method_missing Implementation&amp;lt;ref&amp;gt;http://www.thirdbit.net/articles/2007/08/01/10-things-you-should-know-about-method_missing/&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def say&lt;br /&gt;
 puts &amp;quot; say hi &amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(m,*args,&amp;amp;block)	// defining method_missing&lt;br /&gt;
 puts &amp;quot; This method does not exist&amp;quot;	// body of method_missing&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Calling a method that is not defined&lt;br /&gt;
 &lt;br /&gt;
 a=A.new&lt;br /&gt;
 a.sayhi                                // calling the undefined method sayhi with no arguments&lt;br /&gt;
 =&amp;gt; This method does not exist		// this result returned when method_missing is executed&lt;br /&gt;
&lt;br /&gt;
When the object 'a' traces its method lookup path for a matching method as 'sayhi', upon failure it resorts to method_missing and the body of method_missing is executed. 'method_missing' is the last resort.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Sometimes when a class has many methods that do generally the same kinds of things, and the programmer is not sure in advance which methods the user will call since there are so many of them, and they are all so similar, writing code for all of them seems futile. In these situations method_missing can be defined to take care of different cases. The below 'Generic Handler' example implements this.&lt;br /&gt;
&lt;br /&gt;
===Passing Parameters to an Undefined Method Call===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def add(a,b)&lt;br /&gt;
 a+b&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(name,*args,&amp;amp;block)    // the method_missing is defined and the *args parameter accepts all the parameters passed during 								                                 &lt;br /&gt;
                                             the method call   &lt;br /&gt;
 puts “You have typed the method name wrong and these were the parameters passed ; #{args[0]}, #{args[1]}”								&lt;br /&gt;
 end                         			&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The passed parameters are stored in the array 'args' and can be accessed like a normal array                &lt;br /&gt;
                                                   &lt;br /&gt;
 &lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.add(1,2)		        // calling the defined method add and passing the parameters (1,2)&lt;br /&gt;
 =&amp;gt; 3                           // result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.adds(4,2) 			// calling the undefined method adds and passing the parameter (4,2)&lt;br /&gt;
 =&amp;gt; You have typed the method name wrong and these were the parameters passed; 4, 2&lt;br /&gt;
&lt;br /&gt;
The user made a genuine mistake by typing 'adds', but this method is not defined. When the 'adds' method with parameters is called, the object 'a' tries to match the method in the method lookup path. Upon failure it invokes method_missing, the args are passed, stored in the array 'args' and the body of method_missing is executed.&lt;br /&gt;
&lt;br /&gt;
===converting numbers from roman representation to integer representation&amp;lt;ref&amp;gt;http://courses.ncsu.edu/csc517/common/lectures/notes/wk2.pdf&amp;lt;/ref&amp;gt;===&lt;br /&gt;
 class Roman&lt;br /&gt;
 DIGITS = {'I'=&amp;gt;1,'V'=&amp;gt;5,'X'=&amp;gt;10,'L'=&amp;gt;50,'C'=&amp;gt;100,'D'=&amp;gt;500,'M'=&amp;gt;1000,}&lt;br /&gt;
 def roman_to_integer(roman_string)&lt;br /&gt;
 last = nil&lt;br /&gt;
 roman_string.to_s.upcase.split(//).reverse.inject(0) do&lt;br /&gt;
 |memo, digit|&lt;br /&gt;
 if digit_value = DIGITS[digit]&lt;br /&gt;
 if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
 memo -= digit_value&lt;br /&gt;
 else&lt;br /&gt;
 memo += digit_value&lt;br /&gt;
 end&lt;br /&gt;
 last = digit_value&lt;br /&gt;
 end&lt;br /&gt;
 memo&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def method_missing(method)&lt;br /&gt;
 str=method.id2name&lt;br /&gt;
 roman_to_integer(str)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calling the undefined methods&lt;br /&gt;
&lt;br /&gt;
 r= Roman.new&lt;br /&gt;
 r.vii&lt;br /&gt;
 r.xxix&lt;br /&gt;
 r.xxiv&lt;br /&gt;
 r.xxvi&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The Output&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; 7&lt;br /&gt;
 =&amp;gt; 29&lt;br /&gt;
 =&amp;gt; 24&lt;br /&gt;
&lt;br /&gt;
===method_missing to log method calls&amp;lt;ref&amp;gt;http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2007/wiki1b_2_22&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Another application that makes use of method_missing could be a simple logger used for debugging purposes. Many times, it may be required to log the trace of called methods and provide information such as: called method-name, arguments, return type. It can be tedious to repeat this part of code in every method. A simple solution to this problem can be obtained using method_missing as:&lt;br /&gt;
&lt;br /&gt;
  class SimpleCallLogger&lt;br /&gt;
  def initialize(o)&lt;br /&gt;
  @obj = o&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(methodname, *args)&lt;br /&gt;
  puts &amp;quot;called: #{methodname}(#{args})&amp;quot;&lt;br /&gt;
  a = @obj.send(methodname, *args)&lt;br /&gt;
  puts &amp;quot;\t-&amp;gt; returned: #{a}&amp;quot;&lt;br /&gt;
  return a&lt;br /&gt;
  end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
This program makes use of method_missing in a way that it wraps around called method to output the logging information on entry and on exit, it logs the return type. Further, method_missing intercepts the method call and forward it to internal object with ‘send’ method of ruby. Hence, this use of method_missing acts as wrapper.&lt;br /&gt;
&lt;br /&gt;
===Generic Handler===&lt;br /&gt;
 class NoBar&lt;br /&gt;
 def method_missing(methodname, *args)&lt;br /&gt;
 define_method(:bar) if &amp;quot;bar&amp;quot; == methodname.to_s&lt;br /&gt;
 define_method(:nobar) if &amp;quot;nobar&amp;quot; == methodname.to_s&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This is an example of using method_missing as a generic handler to handle when a calling method is not exist. You can use missing_method to dynamically create a method at a runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Advantages of method_missing'''==&lt;br /&gt;
&lt;br /&gt;
*In addition to specifying the error messages for the undefined methods, method_missing provides a more dynamic behavior in the programming environment.&lt;br /&gt;
*If we are unfamiliar with the usage of the objects we created, then using method_missing is a good technique.&lt;br /&gt;
*Handles problems at runtime.&lt;br /&gt;
*Define's a generic method_missing and handle's any undefined method, a big advantage over Java. In Java, when you call an undefined method, the program will not compile.&lt;br /&gt;
*method_missing falls under the general technique of [http://en.wikipedia.org/wiki/Metaprogramming meta-programming]. Employ meta-programming in missing_function to write an another function to handle the call.&lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages of method_missing'''==	&lt;br /&gt;
*Slower than conventional method lookup. Simple tests indicate that method dispatch with method_missing is at least two to three times as expensive in time as conventional dispatch.&lt;br /&gt;
&lt;br /&gt;
*Since the methods being called never actually exist—they are just intercepted at the last step of the method lookup process—they cannot be documented or introspected as conventional methods can.&lt;br /&gt;
&lt;br /&gt;
*method_missing restricts compatibility with future versions of an [http://en.wikipedia.org/wiki/Application_programming_interface API]. Introducing new methods in a future API version can break users' expectations.&lt;br /&gt;
&lt;br /&gt;
=='''Key Points'''==&lt;br /&gt;
&lt;br /&gt;
*In the example below, class A defines only method method_missing() and no other method. When a new object of class A tries to access a method say 'foo', the respond_to? will return the value 'false'. When you actually try to implement it using “a.foo”, the code will get executed, courtesy of method_missing(). Even though the respond_to? says that you cannot access 'foo' method using object of class A, if you have method_missing() defined, you can access the method.&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In method_missing&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)&lt;br /&gt;
 a.foo&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 false&lt;br /&gt;
 In method_missing&lt;br /&gt;
&lt;br /&gt;
*In the following example, if within method_missing() we define an undefined method. &lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 @@i = 0&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In Method Missing #{@@i}&amp;quot;&lt;br /&gt;
 @@i += 1&lt;br /&gt;
 self.fun&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 a.foo &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 The result is a 'stack level too deep' error. &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
When the 'foo' method is called, after no method match the method_missing is run and this block has a method “self.fun” that is undefined.     Here when the program execution encounters 'self.fun' it once again calls method_missing. This goes on in an endless loop till the stack memory is full.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Ruby knows method_missing( ) exists, because it's a private instance method of 'BasicObject' that every object inherits. The BasicObject#method_missing( ) responds by raising the NoMethodError. Overriding this method_missing( ) allows you to call methods that don't really exist. &lt;br /&gt;
&lt;br /&gt;
*If method_missing is only looking for certain method names, don't forget to call the [http://en.wikibooks.org/wiki/Java_Programming/Keywords/super super] keyword if you haven't found what you're looking for, so that the other superclass' method_missing can handle it.&lt;br /&gt;
&lt;br /&gt;
*[http://www.prateekdayal.net/2007/10/16/rubys-responds_to-for-checking-if-a-method-exists/ obj.respond_to?] function returns 'true' if the obj responds to the given method. So if you want to know whether your class will respond to a function you can use respond_to? to know the answer. But if method_missing() is used, the output may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
*http://www.rubyinside.com/ &lt;br /&gt;
*https://www.youtube.com/watch?v=SAEiCkixrdE&amp;amp;feature=relmfu&lt;br /&gt;
*http://blog.jayfields.com/2008/02/ruby-replace-methodmissing-with-dynamic.html &lt;br /&gt;
*http://liquiddevelopment.blogspot.com/2006/04/twisting-and-shaping-dsls-using-ruby.html &lt;br /&gt;
*http://blog.rubybestpractices.com/posts/gregory/031-issue-2-method-lookup.html&lt;br /&gt;
*http://phrogz.net/RubyLibs/RubyMethodLookupFlow.pdf&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65294</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w22 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65294"/>
		<updated>2012-09-19T23:42:21Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* method_missing implementationhttp://www.thirdbit.net/articles/2007/08/01/10-things-you-should-know-about-method_missing/ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''method_missing in Ruby:'''  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Introduction&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_method_missing.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
A method of a class is called by creating an object of the class and passing the method name to the object as a message. The object then looks up into its [http://www.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html method lookup path] and tries to match the called method with the defined methods in the class. On success, the method is executed along with the parameters passed and the result is returned.&lt;br /&gt;
&lt;br /&gt;
If the object does not find a match in its method lookup, in normal circumstances the [http://www.ruby-doc.org/core-1.9.3/NoMethodError.html NoMethodError Exception] is raised .&lt;br /&gt;
&lt;br /&gt;
In cases where the user wants to handle the methods which are not defined but still called, “method_missing” can be defined and the user can handle the methods as he/she sees fit.&lt;br /&gt;
&lt;br /&gt;
=='''Format for defining method_missing'''==&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; def method_missing(m,*args,&amp;amp;block)&lt;br /&gt;
&lt;br /&gt;
(i) '''m-&amp;gt;''' accepts the symbol/name of the undefined method (ii) '''*args-&amp;gt;''' accepts the array of arguments passed in the method call  (iii) '''&amp;amp;block-&amp;gt;'''accepts a block passed to the method&lt;br /&gt;
&lt;br /&gt;
=='''Ruby method lookup flow'''==&lt;br /&gt;
When the object of a class receives a method name to be executed, the following steps are carried out for matching and executing the method:&lt;br /&gt;
&lt;br /&gt;
*First, the object looks in its own [http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html instance methods].&lt;br /&gt;
*Second, it looks in the list of instance methods that all objects of that class share.&lt;br /&gt;
*Third, in each of the included [http://www.tutorialspoint.com/ruby/ruby_modules.html modules] of that class, in reverse order of inclusion. &lt;br /&gt;
*Fourth, it looks in that class’s superclass. &lt;br /&gt;
*Fifth, in the superclass’s included modules, all the way up until it reaches the class Object. &lt;br /&gt;
*Sixth, if it still can’t find a method, the very last place it looks is in the [http://linux.die.net/lkmpg/x40.html Kernel module], included in the class Object. &lt;br /&gt;
*Finally, it calls method_missing (if defined in the class), else throws up the NOMethodError exception.&lt;br /&gt;
&lt;br /&gt;
This entire tracing that the object does is the method lookup path.&lt;br /&gt;
&lt;br /&gt;
=='''Examples'''==&lt;br /&gt;
===Calling defined and undefined methods===&lt;br /&gt;
&lt;br /&gt;
 class A		// creating a class 'A'&lt;br /&gt;
 def say		// defining a method 'say'&lt;br /&gt;
 puts &amp;quot; say Hi &amp;quot; // body of method say&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Creating the object of the class&lt;br /&gt;
 &lt;br /&gt;
  a=A.new	       // object of the class&lt;br /&gt;
  =&amp;gt; #&amp;lt;A:0x2a082e0&amp;gt;     //object id&lt;br /&gt;
&lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.say                  // defined method&lt;br /&gt;
 =&amp;gt; say Hi	       // returned result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.sayhi                // undefined method sayhi&lt;br /&gt;
 NoMethodError: undefined method `sayhi' for #&amp;lt;A:0x2a082e0&amp;gt;   // the NoMethodError is raised&lt;br /&gt;
&lt;br /&gt;
===method_missing Implementation&amp;lt;ref&amp;gt;http://www.thirdbit.net/articles/2007/08/01/10-things-you-should-know-about-method_missing/&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def say&lt;br /&gt;
 puts &amp;quot; say hi &amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(m,*args,&amp;amp;block)	// defining method_missing&lt;br /&gt;
 puts &amp;quot; This method does not exist&amp;quot;	// body of method_missing&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Calling a method that is not defined&lt;br /&gt;
 &lt;br /&gt;
 a=A.new&lt;br /&gt;
 a.sayhi                                // calling the undefined method sayhi with no arguments&lt;br /&gt;
 =&amp;gt; This method does not exist		// this result returned when method_missing is executed&lt;br /&gt;
&lt;br /&gt;
When the object 'a' traces its method lookup path for a matching method as 'sayhi', upon failure it resorts to method_missing and the body of method_missing is executed. 'method_missing' is the last resort.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Sometimes when a class has many methods that do generally the same kinds of things, and the programmer is not sure in advance which methods the user will call since there are so many of them, and they are all so similar, writing code for all of them seems futile. In these situations method_missing can be defined to take care of different cases. The below 'Generic Handler' example implements this.&lt;br /&gt;
&lt;br /&gt;
===passing parameters to an undefined method call===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def add(a,b)&lt;br /&gt;
 a+b&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(name,*args,&amp;amp;block)    // the method_missing is defined and the *args parameter accepts all the parameters passed during 								                                 &lt;br /&gt;
                                             the method call   &lt;br /&gt;
 puts “You have typed the method name wrong and these were the parameters passed ; #{args[0]}, #{args[1]}”								&lt;br /&gt;
 end                         			&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The passed parameters are stored in the array 'args' and can be accessed like a normal array                &lt;br /&gt;
                                                   &lt;br /&gt;
 &lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.add(1,2)		        // calling the defined method add and passing the parameters (1,2)&lt;br /&gt;
 =&amp;gt; 3                           // result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.adds(4,2) 			// calling the undefined method adds and passing the parameter (4,2)&lt;br /&gt;
 =&amp;gt; You have typed the method name wrong and these were the parameters passed; 4, 2&lt;br /&gt;
&lt;br /&gt;
The user made a genuine mistake by typing 'adds', but this method is not defined. When the 'adds' method with parameters is called, the object 'a' tries to match the method in the method lookup path. Upon failure it invokes method_missing, the args are passed, stored in the array 'args' and the body of method_missing is executed.&lt;br /&gt;
&lt;br /&gt;
===converting numbers from roman representation to integer representation&amp;lt;ref&amp;gt;http://courses.ncsu.edu/csc517/common/lectures/notes/wk2.pdf&amp;lt;/ref&amp;gt;===&lt;br /&gt;
 class Roman&lt;br /&gt;
 DIGITS = {'I'=&amp;gt;1,'V'=&amp;gt;5,'X'=&amp;gt;10,'L'=&amp;gt;50,'C'=&amp;gt;100,'D'=&amp;gt;500,'M'=&amp;gt;1000,}&lt;br /&gt;
 def roman_to_integer(roman_string)&lt;br /&gt;
 last = nil&lt;br /&gt;
 roman_string.to_s.upcase.split(//).reverse.inject(0) do&lt;br /&gt;
 |memo, digit|&lt;br /&gt;
 if digit_value = DIGITS[digit]&lt;br /&gt;
 if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
 memo -= digit_value&lt;br /&gt;
 else&lt;br /&gt;
 memo += digit_value&lt;br /&gt;
 end&lt;br /&gt;
 last = digit_value&lt;br /&gt;
 end&lt;br /&gt;
 memo&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def method_missing(method)&lt;br /&gt;
 str=method.id2name&lt;br /&gt;
 roman_to_integer(str)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calling the undefined methods&lt;br /&gt;
&lt;br /&gt;
 r= Roman.new&lt;br /&gt;
 r.vii&lt;br /&gt;
 r.xxix&lt;br /&gt;
 r.xxiv&lt;br /&gt;
 r.xxvi&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The Output&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; 7&lt;br /&gt;
 =&amp;gt; 29&lt;br /&gt;
 =&amp;gt; 24&lt;br /&gt;
&lt;br /&gt;
===method_missing to log method calls&amp;lt;ref&amp;gt;http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2007/wiki1b_2_22&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Another application that makes use of method_missing could be a simple logger used for debugging purposes. Many times, it may be required to log the trace of called methods and provide information such as: called method-name, arguments, return type. It can be tedious to repeat this part of code in every method. A simple solution to this problem can be obtained using method_missing as:&lt;br /&gt;
&lt;br /&gt;
  class SimpleCallLogger&lt;br /&gt;
  def initialize(o)&lt;br /&gt;
  @obj = o&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(methodname, *args)&lt;br /&gt;
  puts &amp;quot;called: #{methodname}(#{args})&amp;quot;&lt;br /&gt;
  a = @obj.send(methodname, *args)&lt;br /&gt;
  puts &amp;quot;\t-&amp;gt; returned: #{a}&amp;quot;&lt;br /&gt;
  return a&lt;br /&gt;
  end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
This program makes use of method_missing in a way that it wraps around called method to output the logging information on entry and on exit, it logs the return type. Further, method_missing intercepts the method call and forward it to internal object with ‘send’ method of ruby. Hence, this use of method_missing acts as wrapper.&lt;br /&gt;
&lt;br /&gt;
===Generic Handler===&lt;br /&gt;
 class NoBar&lt;br /&gt;
 def method_missing(methodname, *args)&lt;br /&gt;
 define_method(:bar) if &amp;quot;bar&amp;quot; == methodname.to_s&lt;br /&gt;
 define_method(:nobar) if &amp;quot;nobar&amp;quot; == methodname.to_s&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This is an example of using method_missing as a generic handler to handle when a calling method is not exist. You can use missing_method to dynamically create a method at a runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Advantages of method_missing'''==&lt;br /&gt;
&lt;br /&gt;
*In addition to specifying the error messages for the undefined methods, method_missing provides a more dynamic behavior in the programming environment.&lt;br /&gt;
*If we are unfamiliar with the usage of the objects we created, then using method_missing is a good technique.&lt;br /&gt;
*Handles problems at runtime.&lt;br /&gt;
*Define's a generic method_missing and handle's any undefined method, a big advantage over Java. In Java, when you call an undefined method, the program will not compile.&lt;br /&gt;
*method_missing falls under the general technique of [http://en.wikipedia.org/wiki/Metaprogramming meta-programming]. Employ meta-programming in missing_function to write an another function to handle the call.&lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages of method_missing'''==	&lt;br /&gt;
*Slower than conventional method lookup. Simple tests indicate that method dispatch with method_missing is at least two to three times as expensive in time as conventional dispatch.&lt;br /&gt;
&lt;br /&gt;
*Since the methods being called never actually exist—they are just intercepted at the last step of the method lookup process—they cannot be documented or introspected as conventional methods can.&lt;br /&gt;
&lt;br /&gt;
*method_missing restricts compatibility with future versions of an [http://en.wikipedia.org/wiki/Application_programming_interface API]. Introducing new methods in a future API version can break users' expectations.&lt;br /&gt;
&lt;br /&gt;
=='''Key Points'''==&lt;br /&gt;
&lt;br /&gt;
*In the example below, class A defines only method method_missing() and no other method. When a new object of class A tries to access a method say 'foo', the respond_to? will return the value 'false'. When you actually try to implement it using “a.foo”, the code will get executed, courtesy of method_missing(). Even though the respond_to? says that you cannot access 'foo' method using object of class A, if you have method_missing() defined, you can access the method.&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In method_missing&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)&lt;br /&gt;
 a.foo&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 false&lt;br /&gt;
 In method_missing&lt;br /&gt;
&lt;br /&gt;
*In the following example, if within method_missing() we define an undefined method. &lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 @@i = 0&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In Method Missing #{@@i}&amp;quot;&lt;br /&gt;
 @@i += 1&lt;br /&gt;
 self.fun&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 a.foo &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 The result is a 'stack level too deep' error. &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
When the 'foo' method is called, after no method match the method_missing is run and this block has a method “self.fun” that is undefined.     Here when the program execution encounters 'self.fun' it once again calls method_missing. This goes on in an endless loop till the stack memory is full.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Ruby knows method_missing( ) exists, because it's a private instance method of 'BasicObject' that every object inherits. The BasicObject#method_missing( ) responds by raising the NoMethodError. Overriding this method_missing( ) allows you to call methods that don't really exist. &lt;br /&gt;
&lt;br /&gt;
*If method_missing is only looking for certain method names, don't forget to call the [http://en.wikibooks.org/wiki/Java_Programming/Keywords/super super] keyword if you haven't found what you're looking for, so that the other superclass' method_missing can handle it.&lt;br /&gt;
&lt;br /&gt;
*[http://www.prateekdayal.net/2007/10/16/rubys-responds_to-for-checking-if-a-method-exists/ obj.respond_to?] function returns 'true' if the obj responds to the given method. So if you want to know whether your class will respond to a function you can use respond_to? to know the answer. But if method_missing() is used, the output may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
*http://www.rubyinside.com/ &lt;br /&gt;
*https://www.youtube.com/watch?v=SAEiCkixrdE&amp;amp;feature=relmfu&lt;br /&gt;
*http://blog.jayfields.com/2008/02/ruby-replace-methodmissing-with-dynamic.html &lt;br /&gt;
*http://liquiddevelopment.blogspot.com/2006/04/twisting-and-shaping-dsls-using-ruby.html &lt;br /&gt;
*http://blog.rubybestpractices.com/posts/gregory/031-issue-2-method-lookup.html&lt;br /&gt;
*http://phrogz.net/RubyLibs/RubyMethodLookupFlow.pdf&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65292</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w22 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65292"/>
		<updated>2012-09-19T23:41:12Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* Key Points */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''method_missing in Ruby:'''  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Introduction&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_method_missing.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
A method of a class is called by creating an object of the class and passing the method name to the object as a message. The object then looks up into its [http://www.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html method lookup path] and tries to match the called method with the defined methods in the class. On success, the method is executed along with the parameters passed and the result is returned.&lt;br /&gt;
&lt;br /&gt;
If the object does not find a match in its method lookup, in normal circumstances the [http://www.ruby-doc.org/core-1.9.3/NoMethodError.html NoMethodError Exception] is raised .&lt;br /&gt;
&lt;br /&gt;
In cases where the user wants to handle the methods which are not defined but still called, “method_missing” can be defined and the user can handle the methods as he/she sees fit.&lt;br /&gt;
&lt;br /&gt;
=='''Format for defining method_missing'''==&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; def method_missing(m,*args,&amp;amp;block)&lt;br /&gt;
&lt;br /&gt;
(i) '''m-&amp;gt;''' accepts the symbol/name of the undefined method (ii) '''*args-&amp;gt;''' accepts the array of arguments passed in the method call  (iii) '''&amp;amp;block-&amp;gt;'''accepts a block passed to the method&lt;br /&gt;
&lt;br /&gt;
=='''Ruby method lookup flow'''==&lt;br /&gt;
When the object of a class receives a method name to be executed, the following steps are carried out for matching and executing the method:&lt;br /&gt;
&lt;br /&gt;
*First, the object looks in its own [http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html instance methods].&lt;br /&gt;
*Second, it looks in the list of instance methods that all objects of that class share.&lt;br /&gt;
*Third, in each of the included [http://www.tutorialspoint.com/ruby/ruby_modules.html modules] of that class, in reverse order of inclusion. &lt;br /&gt;
*Fourth, it looks in that class’s superclass. &lt;br /&gt;
*Fifth, in the superclass’s included modules, all the way up until it reaches the class Object. &lt;br /&gt;
*Sixth, if it still can’t find a method, the very last place it looks is in the [http://linux.die.net/lkmpg/x40.html Kernel module], included in the class Object. &lt;br /&gt;
*Finally, it calls method_missing (if defined in the class), else throws up the NOMethodError exception.&lt;br /&gt;
&lt;br /&gt;
This entire tracing that the object does is the method lookup path.&lt;br /&gt;
&lt;br /&gt;
=='''Examples'''==&lt;br /&gt;
===Calling defined and undefined methods===&lt;br /&gt;
&lt;br /&gt;
 class A		// creating a class 'A'&lt;br /&gt;
 def say		// defining a method 'say'&lt;br /&gt;
 puts &amp;quot; say Hi &amp;quot; // body of method say&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Creating the object of the class&lt;br /&gt;
 &lt;br /&gt;
  a=A.new	       // object of the class&lt;br /&gt;
  =&amp;gt; #&amp;lt;A:0x2a082e0&amp;gt;     //object id&lt;br /&gt;
&lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.say                  // defined method&lt;br /&gt;
 =&amp;gt; say Hi	       // returned result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.sayhi                // undefined method sayhi&lt;br /&gt;
 NoMethodError: undefined method `sayhi' for #&amp;lt;A:0x2a082e0&amp;gt;   // the NoMethodError is raised&lt;br /&gt;
&lt;br /&gt;
===method_missing implementation&amp;lt;ref&amp;gt;http://www.thirdbit.net/articles/2007/08/01/10-things-you-should-know-about-method_missing/&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def say&lt;br /&gt;
 puts &amp;quot; say hi &amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(m,*args,&amp;amp;block)	// defining method_missing&lt;br /&gt;
 puts &amp;quot; This method does not exist&amp;quot;	// body of method_missing&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Calling a method that is not defined&lt;br /&gt;
 &lt;br /&gt;
 a=A.new&lt;br /&gt;
 a.sayhi                                // calling the undefined method sayhi with no arguments&lt;br /&gt;
 =&amp;gt; This method does not exist		// this result returned when method_missing is executed&lt;br /&gt;
&lt;br /&gt;
When the object 'a' traces its method lookup path for a matching method as 'sayhi', upon failure it resorts to method_missing and the body of method_missing is executed. 'method_missing' is the last resort.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Sometimes when a class has many methods that do generally the same kinds of things, and the programmer is not sure in advance which methods the user will call since there are so many of them, and they are all so similar, writing code for all of them seems futile. In these situations method_missing can be defined to take care of different cases. The below 'Generic Handler' example implements this.&lt;br /&gt;
&lt;br /&gt;
===passing parameters to an undefined method call===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def add(a,b)&lt;br /&gt;
 a+b&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(name,*args,&amp;amp;block)    // the method_missing is defined and the *args parameter accepts all the parameters passed during 								                                 &lt;br /&gt;
                                             the method call   &lt;br /&gt;
 puts “You have typed the method name wrong and these were the parameters passed ; #{args[0]}, #{args[1]}”								&lt;br /&gt;
 end                         			&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The passed parameters are stored in the array 'args' and can be accessed like a normal array                &lt;br /&gt;
                                                   &lt;br /&gt;
 &lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.add(1,2)		        // calling the defined method add and passing the parameters (1,2)&lt;br /&gt;
 =&amp;gt; 3                           // result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.adds(4,2) 			// calling the undefined method adds and passing the parameter (4,2)&lt;br /&gt;
 =&amp;gt; You have typed the method name wrong and these were the parameters passed; 4, 2&lt;br /&gt;
&lt;br /&gt;
The user made a genuine mistake by typing 'adds', but this method is not defined. When the 'adds' method with parameters is called, the object 'a' tries to match the method in the method lookup path. Upon failure it invokes method_missing, the args are passed, stored in the array 'args' and the body of method_missing is executed.&lt;br /&gt;
&lt;br /&gt;
===converting numbers from roman representation to integer representation&amp;lt;ref&amp;gt;http://courses.ncsu.edu/csc517/common/lectures/notes/wk2.pdf&amp;lt;/ref&amp;gt;===&lt;br /&gt;
 class Roman&lt;br /&gt;
 DIGITS = {'I'=&amp;gt;1,'V'=&amp;gt;5,'X'=&amp;gt;10,'L'=&amp;gt;50,'C'=&amp;gt;100,'D'=&amp;gt;500,'M'=&amp;gt;1000,}&lt;br /&gt;
 def roman_to_integer(roman_string)&lt;br /&gt;
 last = nil&lt;br /&gt;
 roman_string.to_s.upcase.split(//).reverse.inject(0) do&lt;br /&gt;
 |memo, digit|&lt;br /&gt;
 if digit_value = DIGITS[digit]&lt;br /&gt;
 if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
 memo -= digit_value&lt;br /&gt;
 else&lt;br /&gt;
 memo += digit_value&lt;br /&gt;
 end&lt;br /&gt;
 last = digit_value&lt;br /&gt;
 end&lt;br /&gt;
 memo&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def method_missing(method)&lt;br /&gt;
 str=method.id2name&lt;br /&gt;
 roman_to_integer(str)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calling the undefined methods&lt;br /&gt;
&lt;br /&gt;
 r= Roman.new&lt;br /&gt;
 r.vii&lt;br /&gt;
 r.xxix&lt;br /&gt;
 r.xxiv&lt;br /&gt;
 r.xxvi&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The Output&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; 7&lt;br /&gt;
 =&amp;gt; 29&lt;br /&gt;
 =&amp;gt; 24&lt;br /&gt;
&lt;br /&gt;
===method_missing to log method calls&amp;lt;ref&amp;gt;http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2007/wiki1b_2_22&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Another application that makes use of method_missing could be a simple logger used for debugging purposes. Many times, it may be required to log the trace of called methods and provide information such as: called method-name, arguments, return type. It can be tedious to repeat this part of code in every method. A simple solution to this problem can be obtained using method_missing as:&lt;br /&gt;
&lt;br /&gt;
  class SimpleCallLogger&lt;br /&gt;
  def initialize(o)&lt;br /&gt;
  @obj = o&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(methodname, *args)&lt;br /&gt;
  puts &amp;quot;called: #{methodname}(#{args})&amp;quot;&lt;br /&gt;
  a = @obj.send(methodname, *args)&lt;br /&gt;
  puts &amp;quot;\t-&amp;gt; returned: #{a}&amp;quot;&lt;br /&gt;
  return a&lt;br /&gt;
  end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
This program makes use of method_missing in a way that it wraps around called method to output the logging information on entry and on exit, it logs the return type. Further, method_missing intercepts the method call and forward it to internal object with ‘send’ method of ruby. Hence, this use of method_missing acts as wrapper.&lt;br /&gt;
&lt;br /&gt;
===Generic Handler===&lt;br /&gt;
 class NoBar&lt;br /&gt;
 def method_missing(methodname, *args)&lt;br /&gt;
 define_method(:bar) if &amp;quot;bar&amp;quot; == methodname.to_s&lt;br /&gt;
 define_method(:nobar) if &amp;quot;nobar&amp;quot; == methodname.to_s&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This is an example of using method_missing as a generic handler to handle when a calling method is not exist. You can use missing_method to dynamically create a method at a runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Advantages of method_missing'''==&lt;br /&gt;
&lt;br /&gt;
*In addition to specifying the error messages for the undefined methods, method_missing provides a more dynamic behavior in the programming environment.&lt;br /&gt;
*If we are unfamiliar with the usage of the objects we created, then using method_missing is a good technique.&lt;br /&gt;
*Handles problems at runtime.&lt;br /&gt;
*Define's a generic method_missing and handle's any undefined method, a big advantage over Java. In Java, when you call an undefined method, the program will not compile.&lt;br /&gt;
*method_missing falls under the general technique of [http://en.wikipedia.org/wiki/Metaprogramming meta-programming]. Employ meta-programming in missing_function to write an another function to handle the call.&lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages of method_missing'''==	&lt;br /&gt;
*Slower than conventional method lookup. Simple tests indicate that method dispatch with method_missing is at least two to three times as expensive in time as conventional dispatch.&lt;br /&gt;
&lt;br /&gt;
*Since the methods being called never actually exist—they are just intercepted at the last step of the method lookup process—they cannot be documented or introspected as conventional methods can.&lt;br /&gt;
&lt;br /&gt;
*method_missing restricts compatibility with future versions of an [http://en.wikipedia.org/wiki/Application_programming_interface API]. Introducing new methods in a future API version can break users' expectations.&lt;br /&gt;
&lt;br /&gt;
=='''Key Points'''==&lt;br /&gt;
&lt;br /&gt;
*In the example below, class A defines only method method_missing() and no other method. When a new object of class A tries to access a method say 'foo', the respond_to? will return the value 'false'. When you actually try to implement it using “a.foo”, the code will get executed, courtesy of method_missing(). Even though the respond_to? says that you cannot access 'foo' method using object of class A, if you have method_missing() defined, you can access the method.&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In method_missing&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)&lt;br /&gt;
 a.foo&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 false&lt;br /&gt;
 In method_missing&lt;br /&gt;
&lt;br /&gt;
*In the following example, if within method_missing() we define an undefined method. &lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 @@i = 0&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In Method Missing #{@@i}&amp;quot;&lt;br /&gt;
 @@i += 1&lt;br /&gt;
 self.fun&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 a.foo &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 The result is a 'stack level too deep' error. &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
When the 'foo' method is called, after no method match the method_missing is run and this block has a method “self.fun” that is undefined.     Here when the program execution encounters 'self.fun' it once again calls method_missing. This goes on in an endless loop till the stack memory is full.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Ruby knows method_missing( ) exists, because it's a private instance method of 'BasicObject' that every object inherits. The BasicObject#method_missing( ) responds by raising the NoMethodError. Overriding this method_missing( ) allows you to call methods that don't really exist. &lt;br /&gt;
&lt;br /&gt;
*If method_missing is only looking for certain method names, don't forget to call the [http://en.wikibooks.org/wiki/Java_Programming/Keywords/super super] keyword if you haven't found what you're looking for, so that the other superclass' method_missing can handle it.&lt;br /&gt;
&lt;br /&gt;
*[http://www.prateekdayal.net/2007/10/16/rubys-responds_to-for-checking-if-a-method-exists/ obj.respond_to?] function returns 'true' if the obj responds to the given method. So if you want to know whether your class will respond to a function you can use respond_to? to know the answer. But if method_missing() is used, the output may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
*http://www.rubyinside.com/ &lt;br /&gt;
*https://www.youtube.com/watch?v=SAEiCkixrdE&amp;amp;feature=relmfu&lt;br /&gt;
*http://blog.jayfields.com/2008/02/ruby-replace-methodmissing-with-dynamic.html &lt;br /&gt;
*http://liquiddevelopment.blogspot.com/2006/04/twisting-and-shaping-dsls-using-ruby.html &lt;br /&gt;
*http://blog.rubybestpractices.com/posts/gregory/031-issue-2-method-lookup.html&lt;br /&gt;
*http://phrogz.net/RubyLibs/RubyMethodLookupFlow.pdf&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65291</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w22 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65291"/>
		<updated>2012-09-19T23:40:38Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* Key Points */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''method_missing in Ruby:'''  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Introduction&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_method_missing.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
A method of a class is called by creating an object of the class and passing the method name to the object as a message. The object then looks up into its [http://www.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html method lookup path] and tries to match the called method with the defined methods in the class. On success, the method is executed along with the parameters passed and the result is returned.&lt;br /&gt;
&lt;br /&gt;
If the object does not find a match in its method lookup, in normal circumstances the [http://www.ruby-doc.org/core-1.9.3/NoMethodError.html NoMethodError Exception] is raised .&lt;br /&gt;
&lt;br /&gt;
In cases where the user wants to handle the methods which are not defined but still called, “method_missing” can be defined and the user can handle the methods as he/she sees fit.&lt;br /&gt;
&lt;br /&gt;
=='''Format for defining method_missing'''==&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; def method_missing(m,*args,&amp;amp;block)&lt;br /&gt;
&lt;br /&gt;
(i) '''m-&amp;gt;''' accepts the symbol/name of the undefined method (ii) '''*args-&amp;gt;''' accepts the array of arguments passed in the method call  (iii) '''&amp;amp;block-&amp;gt;'''accepts a block passed to the method&lt;br /&gt;
&lt;br /&gt;
=='''Ruby method lookup flow'''==&lt;br /&gt;
When the object of a class receives a method name to be executed, the following steps are carried out for matching and executing the method:&lt;br /&gt;
&lt;br /&gt;
*First, the object looks in its own [http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html instance methods].&lt;br /&gt;
*Second, it looks in the list of instance methods that all objects of that class share.&lt;br /&gt;
*Third, in each of the included [http://www.tutorialspoint.com/ruby/ruby_modules.html modules] of that class, in reverse order of inclusion. &lt;br /&gt;
*Fourth, it looks in that class’s superclass. &lt;br /&gt;
*Fifth, in the superclass’s included modules, all the way up until it reaches the class Object. &lt;br /&gt;
*Sixth, if it still can’t find a method, the very last place it looks is in the [http://linux.die.net/lkmpg/x40.html Kernel module], included in the class Object. &lt;br /&gt;
*Finally, it calls method_missing (if defined in the class), else throws up the NOMethodError exception.&lt;br /&gt;
&lt;br /&gt;
This entire tracing that the object does is the method lookup path.&lt;br /&gt;
&lt;br /&gt;
=='''Examples'''==&lt;br /&gt;
===Calling defined and undefined methods===&lt;br /&gt;
&lt;br /&gt;
 class A		// creating a class 'A'&lt;br /&gt;
 def say		// defining a method 'say'&lt;br /&gt;
 puts &amp;quot; say Hi &amp;quot; // body of method say&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Creating the object of the class&lt;br /&gt;
 &lt;br /&gt;
  a=A.new	       // object of the class&lt;br /&gt;
  =&amp;gt; #&amp;lt;A:0x2a082e0&amp;gt;     //object id&lt;br /&gt;
&lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.say                  // defined method&lt;br /&gt;
 =&amp;gt; say Hi	       // returned result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.sayhi                // undefined method sayhi&lt;br /&gt;
 NoMethodError: undefined method `sayhi' for #&amp;lt;A:0x2a082e0&amp;gt;   // the NoMethodError is raised&lt;br /&gt;
&lt;br /&gt;
===method_missing implementation&amp;lt;ref&amp;gt;http://www.thirdbit.net/articles/2007/08/01/10-things-you-should-know-about-method_missing/&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def say&lt;br /&gt;
 puts &amp;quot; say hi &amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(m,*args,&amp;amp;block)	// defining method_missing&lt;br /&gt;
 puts &amp;quot; This method does not exist&amp;quot;	// body of method_missing&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Calling a method that is not defined&lt;br /&gt;
 &lt;br /&gt;
 a=A.new&lt;br /&gt;
 a.sayhi                                // calling the undefined method sayhi with no arguments&lt;br /&gt;
 =&amp;gt; This method does not exist		// this result returned when method_missing is executed&lt;br /&gt;
&lt;br /&gt;
When the object 'a' traces its method lookup path for a matching method as 'sayhi', upon failure it resorts to method_missing and the body of method_missing is executed. 'method_missing' is the last resort.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Sometimes when a class has many methods that do generally the same kinds of things, and the programmer is not sure in advance which methods the user will call since there are so many of them, and they are all so similar, writing code for all of them seems futile. In these situations method_missing can be defined to take care of different cases. The below 'Generic Handler' example implements this.&lt;br /&gt;
&lt;br /&gt;
===passing parameters to an undefined method call===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def add(a,b)&lt;br /&gt;
 a+b&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(name,*args,&amp;amp;block)    // the method_missing is defined and the *args parameter accepts all the parameters passed during 								                                 &lt;br /&gt;
                                             the method call   &lt;br /&gt;
 puts “You have typed the method name wrong and these were the parameters passed ; #{args[0]}, #{args[1]}”								&lt;br /&gt;
 end                         			&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The passed parameters are stored in the array 'args' and can be accessed like a normal array                &lt;br /&gt;
                                                   &lt;br /&gt;
 &lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.add(1,2)		        // calling the defined method add and passing the parameters (1,2)&lt;br /&gt;
 =&amp;gt; 3                           // result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.adds(4,2) 			// calling the undefined method adds and passing the parameter (4,2)&lt;br /&gt;
 =&amp;gt; You have typed the method name wrong and these were the parameters passed; 4, 2&lt;br /&gt;
&lt;br /&gt;
The user made a genuine mistake by typing 'adds', but this method is not defined. When the 'adds' method with parameters is called, the object 'a' tries to match the method in the method lookup path. Upon failure it invokes method_missing, the args are passed, stored in the array 'args' and the body of method_missing is executed.&lt;br /&gt;
&lt;br /&gt;
===converting numbers from roman representation to integer representation&amp;lt;ref&amp;gt;http://courses.ncsu.edu/csc517/common/lectures/notes/wk2.pdf&amp;lt;/ref&amp;gt;===&lt;br /&gt;
 class Roman&lt;br /&gt;
 DIGITS = {'I'=&amp;gt;1,'V'=&amp;gt;5,'X'=&amp;gt;10,'L'=&amp;gt;50,'C'=&amp;gt;100,'D'=&amp;gt;500,'M'=&amp;gt;1000,}&lt;br /&gt;
 def roman_to_integer(roman_string)&lt;br /&gt;
 last = nil&lt;br /&gt;
 roman_string.to_s.upcase.split(//).reverse.inject(0) do&lt;br /&gt;
 |memo, digit|&lt;br /&gt;
 if digit_value = DIGITS[digit]&lt;br /&gt;
 if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
 memo -= digit_value&lt;br /&gt;
 else&lt;br /&gt;
 memo += digit_value&lt;br /&gt;
 end&lt;br /&gt;
 last = digit_value&lt;br /&gt;
 end&lt;br /&gt;
 memo&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def method_missing(method)&lt;br /&gt;
 str=method.id2name&lt;br /&gt;
 roman_to_integer(str)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calling the undefined methods&lt;br /&gt;
&lt;br /&gt;
 r= Roman.new&lt;br /&gt;
 r.vii&lt;br /&gt;
 r.xxix&lt;br /&gt;
 r.xxiv&lt;br /&gt;
 r.xxvi&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The Output&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; 7&lt;br /&gt;
 =&amp;gt; 29&lt;br /&gt;
 =&amp;gt; 24&lt;br /&gt;
&lt;br /&gt;
===method_missing to log method calls&amp;lt;ref&amp;gt;http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2007/wiki1b_2_22&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Another application that makes use of method_missing could be a simple logger used for debugging purposes. Many times, it may be required to log the trace of called methods and provide information such as: called method-name, arguments, return type. It can be tedious to repeat this part of code in every method. A simple solution to this problem can be obtained using method_missing as:&lt;br /&gt;
&lt;br /&gt;
  class SimpleCallLogger&lt;br /&gt;
  def initialize(o)&lt;br /&gt;
  @obj = o&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(methodname, *args)&lt;br /&gt;
  puts &amp;quot;called: #{methodname}(#{args})&amp;quot;&lt;br /&gt;
  a = @obj.send(methodname, *args)&lt;br /&gt;
  puts &amp;quot;\t-&amp;gt; returned: #{a}&amp;quot;&lt;br /&gt;
  return a&lt;br /&gt;
  end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
This program makes use of method_missing in a way that it wraps around called method to output the logging information on entry and on exit, it logs the return type. Further, method_missing intercepts the method call and forward it to internal object with ‘send’ method of ruby. Hence, this use of method_missing acts as wrapper.&lt;br /&gt;
&lt;br /&gt;
===Generic Handler===&lt;br /&gt;
 class NoBar&lt;br /&gt;
 def method_missing(methodname, *args)&lt;br /&gt;
 define_method(:bar) if &amp;quot;bar&amp;quot; == methodname.to_s&lt;br /&gt;
 define_method(:nobar) if &amp;quot;nobar&amp;quot; == methodname.to_s&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This is an example of using method_missing as a generic handler to handle when a calling method is not exist. You can use missing_method to dynamically create a method at a runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Advantages of method_missing'''==&lt;br /&gt;
&lt;br /&gt;
*In addition to specifying the error messages for the undefined methods, method_missing provides a more dynamic behavior in the programming environment.&lt;br /&gt;
*If we are unfamiliar with the usage of the objects we created, then using method_missing is a good technique.&lt;br /&gt;
*Handles problems at runtime.&lt;br /&gt;
*Define's a generic method_missing and handle's any undefined method, a big advantage over Java. In Java, when you call an undefined method, the program will not compile.&lt;br /&gt;
*method_missing falls under the general technique of [http://en.wikipedia.org/wiki/Metaprogramming meta-programming]. Employ meta-programming in missing_function to write an another function to handle the call.&lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages of method_missing'''==	&lt;br /&gt;
*Slower than conventional method lookup. Simple tests indicate that method dispatch with method_missing is at least two to three times as expensive in time as conventional dispatch.&lt;br /&gt;
&lt;br /&gt;
*Since the methods being called never actually exist—they are just intercepted at the last step of the method lookup process—they cannot be documented or introspected as conventional methods can.&lt;br /&gt;
&lt;br /&gt;
*method_missing restricts compatibility with future versions of an [http://en.wikipedia.org/wiki/Application_programming_interface API]. Introducing new methods in a future API version can break users' expectations.&lt;br /&gt;
&lt;br /&gt;
=='''Key Points'''==&lt;br /&gt;
&lt;br /&gt;
*In the example below, class A defines only method method_missing() and no other method. When a new object of class A tries to access a method say 'foo', the respond_to? will return the value 'false'. When you actually try to implement it using “a.foo”, the code will get executed, courtesy of method_missing(). Even though the respond_to? says that you cannot access 'foo' method using object of class A, if you have method_missing() defined, you can access the method.&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In method_missing&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)&lt;br /&gt;
 a.foo&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 false&lt;br /&gt;
 In method_missing&lt;br /&gt;
&lt;br /&gt;
*In the following example, if within method_missing() we define an undefined method. &lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 @@i = 0&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In Method Missing #{@@i}&amp;quot;&lt;br /&gt;
 @@i += 1&lt;br /&gt;
 self.fun&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 a.foo &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 The result is a 'stack level too deep' error. &lt;br /&gt;
 When the 'foo' method is called, after no method match the method_missing is run and this block has a method “self.fun” that is undefined. Here when the program execution encounters 'self.fun' it once again calls method_missing. This goes on in an endless loop till the stack memory is full.&lt;br /&gt;
&lt;br /&gt;
*Ruby knows method_missing( ) exists, because it's a private instance method of 'BasicObject' that every object inherits. The BasicObject#method_missing( ) responds by raising the NoMethodError. Overriding this method_missing( ) allows you to call methods that don't really exist. &lt;br /&gt;
&lt;br /&gt;
*If method_missing is only looking for certain method names, don't forget to call the [http://en.wikibooks.org/wiki/Java_Programming/Keywords/super super] keyword if you haven't found what you're looking for, so that the other superclass' method_missing can handle it.&lt;br /&gt;
&lt;br /&gt;
*[http://www.prateekdayal.net/2007/10/16/rubys-responds_to-for-checking-if-a-method-exists/ obj.respond_to?] function returns 'true' if the obj responds to the given method. So if you want to know whether your class will respond to a function you can use respond_to? to know the answer. But if method_missing() is used, the output may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
*http://www.rubyinside.com/ &lt;br /&gt;
*https://www.youtube.com/watch?v=SAEiCkixrdE&amp;amp;feature=relmfu&lt;br /&gt;
*http://blog.jayfields.com/2008/02/ruby-replace-methodmissing-with-dynamic.html &lt;br /&gt;
*http://liquiddevelopment.blogspot.com/2006/04/twisting-and-shaping-dsls-using-ruby.html &lt;br /&gt;
*http://blog.rubybestpractices.com/posts/gregory/031-issue-2-method-lookup.html&lt;br /&gt;
*http://phrogz.net/RubyLibs/RubyMethodLookupFlow.pdf&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65290</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w22 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65290"/>
		<updated>2012-09-19T23:39:51Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* Key Points */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''method_missing in Ruby:'''  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Introduction&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_method_missing.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
A method of a class is called by creating an object of the class and passing the method name to the object as a message. The object then looks up into its [http://www.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html method lookup path] and tries to match the called method with the defined methods in the class. On success, the method is executed along with the parameters passed and the result is returned.&lt;br /&gt;
&lt;br /&gt;
If the object does not find a match in its method lookup, in normal circumstances the [http://www.ruby-doc.org/core-1.9.3/NoMethodError.html NoMethodError Exception] is raised .&lt;br /&gt;
&lt;br /&gt;
In cases where the user wants to handle the methods which are not defined but still called, “method_missing” can be defined and the user can handle the methods as he/she sees fit.&lt;br /&gt;
&lt;br /&gt;
=='''Format for defining method_missing'''==&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; def method_missing(m,*args,&amp;amp;block)&lt;br /&gt;
&lt;br /&gt;
(i) '''m-&amp;gt;''' accepts the symbol/name of the undefined method (ii) '''*args-&amp;gt;''' accepts the array of arguments passed in the method call  (iii) '''&amp;amp;block-&amp;gt;'''accepts a block passed to the method&lt;br /&gt;
&lt;br /&gt;
=='''Ruby method lookup flow'''==&lt;br /&gt;
When the object of a class receives a method name to be executed, the following steps are carried out for matching and executing the method:&lt;br /&gt;
&lt;br /&gt;
*First, the object looks in its own [http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html instance methods].&lt;br /&gt;
*Second, it looks in the list of instance methods that all objects of that class share.&lt;br /&gt;
*Third, in each of the included [http://www.tutorialspoint.com/ruby/ruby_modules.html modules] of that class, in reverse order of inclusion. &lt;br /&gt;
*Fourth, it looks in that class’s superclass. &lt;br /&gt;
*Fifth, in the superclass’s included modules, all the way up until it reaches the class Object. &lt;br /&gt;
*Sixth, if it still can’t find a method, the very last place it looks is in the [http://linux.die.net/lkmpg/x40.html Kernel module], included in the class Object. &lt;br /&gt;
*Finally, it calls method_missing (if defined in the class), else throws up the NOMethodError exception.&lt;br /&gt;
&lt;br /&gt;
This entire tracing that the object does is the method lookup path.&lt;br /&gt;
&lt;br /&gt;
=='''Examples'''==&lt;br /&gt;
===Calling defined and undefined methods===&lt;br /&gt;
&lt;br /&gt;
 class A		// creating a class 'A'&lt;br /&gt;
 def say		// defining a method 'say'&lt;br /&gt;
 puts &amp;quot; say Hi &amp;quot; // body of method say&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Creating the object of the class&lt;br /&gt;
 &lt;br /&gt;
  a=A.new	       // object of the class&lt;br /&gt;
  =&amp;gt; #&amp;lt;A:0x2a082e0&amp;gt;     //object id&lt;br /&gt;
&lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.say                  // defined method&lt;br /&gt;
 =&amp;gt; say Hi	       // returned result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.sayhi                // undefined method sayhi&lt;br /&gt;
 NoMethodError: undefined method `sayhi' for #&amp;lt;A:0x2a082e0&amp;gt;   // the NoMethodError is raised&lt;br /&gt;
&lt;br /&gt;
===method_missing implementation&amp;lt;ref&amp;gt;http://www.thirdbit.net/articles/2007/08/01/10-things-you-should-know-about-method_missing/&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def say&lt;br /&gt;
 puts &amp;quot; say hi &amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(m,*args,&amp;amp;block)	// defining method_missing&lt;br /&gt;
 puts &amp;quot; This method does not exist&amp;quot;	// body of method_missing&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Calling a method that is not defined&lt;br /&gt;
 &lt;br /&gt;
 a=A.new&lt;br /&gt;
 a.sayhi                                // calling the undefined method sayhi with no arguments&lt;br /&gt;
 =&amp;gt; This method does not exist		// this result returned when method_missing is executed&lt;br /&gt;
&lt;br /&gt;
When the object 'a' traces its method lookup path for a matching method as 'sayhi', upon failure it resorts to method_missing and the body of method_missing is executed. 'method_missing' is the last resort.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Sometimes when a class has many methods that do generally the same kinds of things, and the programmer is not sure in advance which methods the user will call since there are so many of them, and they are all so similar, writing code for all of them seems futile. In these situations method_missing can be defined to take care of different cases. The below 'Generic Handler' example implements this.&lt;br /&gt;
&lt;br /&gt;
===passing parameters to an undefined method call===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def add(a,b)&lt;br /&gt;
 a+b&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(name,*args,&amp;amp;block)    // the method_missing is defined and the *args parameter accepts all the parameters passed during 								                                 &lt;br /&gt;
                                             the method call   &lt;br /&gt;
 puts “You have typed the method name wrong and these were the parameters passed ; #{args[0]}, #{args[1]}”								&lt;br /&gt;
 end                         			&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The passed parameters are stored in the array 'args' and can be accessed like a normal array                &lt;br /&gt;
                                                   &lt;br /&gt;
 &lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.add(1,2)		        // calling the defined method add and passing the parameters (1,2)&lt;br /&gt;
 =&amp;gt; 3                           // result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.adds(4,2) 			// calling the undefined method adds and passing the parameter (4,2)&lt;br /&gt;
 =&amp;gt; You have typed the method name wrong and these were the parameters passed; 4, 2&lt;br /&gt;
&lt;br /&gt;
The user made a genuine mistake by typing 'adds', but this method is not defined. When the 'adds' method with parameters is called, the object 'a' tries to match the method in the method lookup path. Upon failure it invokes method_missing, the args are passed, stored in the array 'args' and the body of method_missing is executed.&lt;br /&gt;
&lt;br /&gt;
===converting numbers from roman representation to integer representation&amp;lt;ref&amp;gt;http://courses.ncsu.edu/csc517/common/lectures/notes/wk2.pdf&amp;lt;/ref&amp;gt;===&lt;br /&gt;
 class Roman&lt;br /&gt;
 DIGITS = {'I'=&amp;gt;1,'V'=&amp;gt;5,'X'=&amp;gt;10,'L'=&amp;gt;50,'C'=&amp;gt;100,'D'=&amp;gt;500,'M'=&amp;gt;1000,}&lt;br /&gt;
 def roman_to_integer(roman_string)&lt;br /&gt;
 last = nil&lt;br /&gt;
 roman_string.to_s.upcase.split(//).reverse.inject(0) do&lt;br /&gt;
 |memo, digit|&lt;br /&gt;
 if digit_value = DIGITS[digit]&lt;br /&gt;
 if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
 memo -= digit_value&lt;br /&gt;
 else&lt;br /&gt;
 memo += digit_value&lt;br /&gt;
 end&lt;br /&gt;
 last = digit_value&lt;br /&gt;
 end&lt;br /&gt;
 memo&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def method_missing(method)&lt;br /&gt;
 str=method.id2name&lt;br /&gt;
 roman_to_integer(str)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calling the undefined methods&lt;br /&gt;
&lt;br /&gt;
 r= Roman.new&lt;br /&gt;
 r.vii&lt;br /&gt;
 r.xxix&lt;br /&gt;
 r.xxiv&lt;br /&gt;
 r.xxvi&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The Output&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; 7&lt;br /&gt;
 =&amp;gt; 29&lt;br /&gt;
 =&amp;gt; 24&lt;br /&gt;
&lt;br /&gt;
===method_missing to log method calls&amp;lt;ref&amp;gt;http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2007/wiki1b_2_22&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Another application that makes use of method_missing could be a simple logger used for debugging purposes. Many times, it may be required to log the trace of called methods and provide information such as: called method-name, arguments, return type. It can be tedious to repeat this part of code in every method. A simple solution to this problem can be obtained using method_missing as:&lt;br /&gt;
&lt;br /&gt;
  class SimpleCallLogger&lt;br /&gt;
  def initialize(o)&lt;br /&gt;
  @obj = o&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(methodname, *args)&lt;br /&gt;
  puts &amp;quot;called: #{methodname}(#{args})&amp;quot;&lt;br /&gt;
  a = @obj.send(methodname, *args)&lt;br /&gt;
  puts &amp;quot;\t-&amp;gt; returned: #{a}&amp;quot;&lt;br /&gt;
  return a&lt;br /&gt;
  end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
This program makes use of method_missing in a way that it wraps around called method to output the logging information on entry and on exit, it logs the return type. Further, method_missing intercepts the method call and forward it to internal object with ‘send’ method of ruby. Hence, this use of method_missing acts as wrapper.&lt;br /&gt;
&lt;br /&gt;
===Generic Handler===&lt;br /&gt;
 class NoBar&lt;br /&gt;
 def method_missing(methodname, *args)&lt;br /&gt;
 define_method(:bar) if &amp;quot;bar&amp;quot; == methodname.to_s&lt;br /&gt;
 define_method(:nobar) if &amp;quot;nobar&amp;quot; == methodname.to_s&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This is an example of using method_missing as a generic handler to handle when a calling method is not exist. You can use missing_method to dynamically create a method at a runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Advantages of method_missing'''==&lt;br /&gt;
&lt;br /&gt;
*In addition to specifying the error messages for the undefined methods, method_missing provides a more dynamic behavior in the programming environment.&lt;br /&gt;
*If we are unfamiliar with the usage of the objects we created, then using method_missing is a good technique.&lt;br /&gt;
*Handles problems at runtime.&lt;br /&gt;
*Define's a generic method_missing and handle's any undefined method, a big advantage over Java. In Java, when you call an undefined method, the program will not compile.&lt;br /&gt;
*method_missing falls under the general technique of [http://en.wikipedia.org/wiki/Metaprogramming meta-programming]. Employ meta-programming in missing_function to write an another function to handle the call.&lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages of method_missing'''==	&lt;br /&gt;
*Slower than conventional method lookup. Simple tests indicate that method dispatch with method_missing is at least two to three times as expensive in time as conventional dispatch.&lt;br /&gt;
&lt;br /&gt;
*Since the methods being called never actually exist—they are just intercepted at the last step of the method lookup process—they cannot be documented or introspected as conventional methods can.&lt;br /&gt;
&lt;br /&gt;
*method_missing restricts compatibility with future versions of an [http://en.wikipedia.org/wiki/Application_programming_interface API]. Introducing new methods in a future API version can break users' expectations.&lt;br /&gt;
&lt;br /&gt;
=='''Key Points'''==&lt;br /&gt;
&lt;br /&gt;
*In the example below, class A defines only method method_missing() and no other method. When a new object of class A tries to access a method say 'foo', the respond_to? will return the value 'false'. When you actually try to implement it using “a.foo”, the code will get executed, courtesy of method_missing(). Even though the respond_to? says that you cannot access 'foo' method using object of class A, if you have method_missing() defined, you can access the method.&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In method_missing&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)&lt;br /&gt;
 a.foo&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 false&lt;br /&gt;
 In method_missing&lt;br /&gt;
&lt;br /&gt;
*In the following example, if within method_missing() we define an undefined method. &lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 @@i = 0&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In Method Missing #{@@i}&amp;quot;&lt;br /&gt;
 @@i += 1&lt;br /&gt;
 self.fun&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 a.foo &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 The result is a 'stack level too deep' error. &lt;br /&gt;
&lt;br /&gt;
When the 'foo' method is called, after no method match the method_missing is run and this block has a method “self.fun” that is undefined. Here when the program execution encounters 'self.fun' it once again calls method_missing. This goes on in an endless loop till the stack memory is full.&lt;br /&gt;
&lt;br /&gt;
*Ruby knows method_missing( ) exists, because it's a private instance method of 'BasicObject' that every object inherits. The BasicObject#method_missing( ) responds by raising the NoMethodError. Overriding this method_missing( ) allows you to call methods that don't really exist. &lt;br /&gt;
&lt;br /&gt;
*If method_missing is only looking for certain method names, don't forget to call the [http://en.wikibooks.org/wiki/Java_Programming/Keywords/super super] keyword if you haven't found what you're looking for, so that the other superclass' method_missing can handle it.&lt;br /&gt;
&lt;br /&gt;
*[http://www.prateekdayal.net/2007/10/16/rubys-responds_to-for-checking-if-a-method-exists/ obj.respond_to?] function returns 'true' if the obj responds to the given method. So if you want to know whether your class will respond to a function you can use respond_to? to know the answer. But if method_missing() is used, the output may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
*http://www.rubyinside.com/ &lt;br /&gt;
*https://www.youtube.com/watch?v=SAEiCkixrdE&amp;amp;feature=relmfu&lt;br /&gt;
*http://blog.jayfields.com/2008/02/ruby-replace-methodmissing-with-dynamic.html &lt;br /&gt;
*http://liquiddevelopment.blogspot.com/2006/04/twisting-and-shaping-dsls-using-ruby.html &lt;br /&gt;
*http://blog.rubybestpractices.com/posts/gregory/031-issue-2-method-lookup.html&lt;br /&gt;
*http://phrogz.net/RubyLibs/RubyMethodLookupFlow.pdf&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65289</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w22 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65289"/>
		<updated>2012-09-19T23:39:23Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* Key Points */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''method_missing in Ruby:'''  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Introduction&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_method_missing.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
A method of a class is called by creating an object of the class and passing the method name to the object as a message. The object then looks up into its [http://www.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html method lookup path] and tries to match the called method with the defined methods in the class. On success, the method is executed along with the parameters passed and the result is returned.&lt;br /&gt;
&lt;br /&gt;
If the object does not find a match in its method lookup, in normal circumstances the [http://www.ruby-doc.org/core-1.9.3/NoMethodError.html NoMethodError Exception] is raised .&lt;br /&gt;
&lt;br /&gt;
In cases where the user wants to handle the methods which are not defined but still called, “method_missing” can be defined and the user can handle the methods as he/she sees fit.&lt;br /&gt;
&lt;br /&gt;
=='''Format for defining method_missing'''==&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; def method_missing(m,*args,&amp;amp;block)&lt;br /&gt;
&lt;br /&gt;
(i) '''m-&amp;gt;''' accepts the symbol/name of the undefined method (ii) '''*args-&amp;gt;''' accepts the array of arguments passed in the method call  (iii) '''&amp;amp;block-&amp;gt;'''accepts a block passed to the method&lt;br /&gt;
&lt;br /&gt;
=='''Ruby method lookup flow'''==&lt;br /&gt;
When the object of a class receives a method name to be executed, the following steps are carried out for matching and executing the method:&lt;br /&gt;
&lt;br /&gt;
*First, the object looks in its own [http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html instance methods].&lt;br /&gt;
*Second, it looks in the list of instance methods that all objects of that class share.&lt;br /&gt;
*Third, in each of the included [http://www.tutorialspoint.com/ruby/ruby_modules.html modules] of that class, in reverse order of inclusion. &lt;br /&gt;
*Fourth, it looks in that class’s superclass. &lt;br /&gt;
*Fifth, in the superclass’s included modules, all the way up until it reaches the class Object. &lt;br /&gt;
*Sixth, if it still can’t find a method, the very last place it looks is in the [http://linux.die.net/lkmpg/x40.html Kernel module], included in the class Object. &lt;br /&gt;
*Finally, it calls method_missing (if defined in the class), else throws up the NOMethodError exception.&lt;br /&gt;
&lt;br /&gt;
This entire tracing that the object does is the method lookup path.&lt;br /&gt;
&lt;br /&gt;
=='''Examples'''==&lt;br /&gt;
===Calling defined and undefined methods===&lt;br /&gt;
&lt;br /&gt;
 class A		// creating a class 'A'&lt;br /&gt;
 def say		// defining a method 'say'&lt;br /&gt;
 puts &amp;quot; say Hi &amp;quot; // body of method say&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Creating the object of the class&lt;br /&gt;
 &lt;br /&gt;
  a=A.new	       // object of the class&lt;br /&gt;
  =&amp;gt; #&amp;lt;A:0x2a082e0&amp;gt;     //object id&lt;br /&gt;
&lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.say                  // defined method&lt;br /&gt;
 =&amp;gt; say Hi	       // returned result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.sayhi                // undefined method sayhi&lt;br /&gt;
 NoMethodError: undefined method `sayhi' for #&amp;lt;A:0x2a082e0&amp;gt;   // the NoMethodError is raised&lt;br /&gt;
&lt;br /&gt;
===method_missing implementation&amp;lt;ref&amp;gt;http://www.thirdbit.net/articles/2007/08/01/10-things-you-should-know-about-method_missing/&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def say&lt;br /&gt;
 puts &amp;quot; say hi &amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(m,*args,&amp;amp;block)	// defining method_missing&lt;br /&gt;
 puts &amp;quot; This method does not exist&amp;quot;	// body of method_missing&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Calling a method that is not defined&lt;br /&gt;
 &lt;br /&gt;
 a=A.new&lt;br /&gt;
 a.sayhi                                // calling the undefined method sayhi with no arguments&lt;br /&gt;
 =&amp;gt; This method does not exist		// this result returned when method_missing is executed&lt;br /&gt;
&lt;br /&gt;
When the object 'a' traces its method lookup path for a matching method as 'sayhi', upon failure it resorts to method_missing and the body of method_missing is executed. 'method_missing' is the last resort.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Sometimes when a class has many methods that do generally the same kinds of things, and the programmer is not sure in advance which methods the user will call since there are so many of them, and they are all so similar, writing code for all of them seems futile. In these situations method_missing can be defined to take care of different cases. The below 'Generic Handler' example implements this.&lt;br /&gt;
&lt;br /&gt;
===passing parameters to an undefined method call===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def add(a,b)&lt;br /&gt;
 a+b&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(name,*args,&amp;amp;block)    // the method_missing is defined and the *args parameter accepts all the parameters passed during 								                                 &lt;br /&gt;
                                             the method call   &lt;br /&gt;
 puts “You have typed the method name wrong and these were the parameters passed ; #{args[0]}, #{args[1]}”								&lt;br /&gt;
 end                         			&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The passed parameters are stored in the array 'args' and can be accessed like a normal array                &lt;br /&gt;
                                                   &lt;br /&gt;
 &lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.add(1,2)		        // calling the defined method add and passing the parameters (1,2)&lt;br /&gt;
 =&amp;gt; 3                           // result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.adds(4,2) 			// calling the undefined method adds and passing the parameter (4,2)&lt;br /&gt;
 =&amp;gt; You have typed the method name wrong and these were the parameters passed; 4, 2&lt;br /&gt;
&lt;br /&gt;
The user made a genuine mistake by typing 'adds', but this method is not defined. When the 'adds' method with parameters is called, the object 'a' tries to match the method in the method lookup path. Upon failure it invokes method_missing, the args are passed, stored in the array 'args' and the body of method_missing is executed.&lt;br /&gt;
&lt;br /&gt;
===converting numbers from roman representation to integer representation&amp;lt;ref&amp;gt;http://courses.ncsu.edu/csc517/common/lectures/notes/wk2.pdf&amp;lt;/ref&amp;gt;===&lt;br /&gt;
 class Roman&lt;br /&gt;
 DIGITS = {'I'=&amp;gt;1,'V'=&amp;gt;5,'X'=&amp;gt;10,'L'=&amp;gt;50,'C'=&amp;gt;100,'D'=&amp;gt;500,'M'=&amp;gt;1000,}&lt;br /&gt;
 def roman_to_integer(roman_string)&lt;br /&gt;
 last = nil&lt;br /&gt;
 roman_string.to_s.upcase.split(//).reverse.inject(0) do&lt;br /&gt;
 |memo, digit|&lt;br /&gt;
 if digit_value = DIGITS[digit]&lt;br /&gt;
 if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
 memo -= digit_value&lt;br /&gt;
 else&lt;br /&gt;
 memo += digit_value&lt;br /&gt;
 end&lt;br /&gt;
 last = digit_value&lt;br /&gt;
 end&lt;br /&gt;
 memo&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def method_missing(method)&lt;br /&gt;
 str=method.id2name&lt;br /&gt;
 roman_to_integer(str)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calling the undefined methods&lt;br /&gt;
&lt;br /&gt;
 r= Roman.new&lt;br /&gt;
 r.vii&lt;br /&gt;
 r.xxix&lt;br /&gt;
 r.xxiv&lt;br /&gt;
 r.xxvi&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The Output&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; 7&lt;br /&gt;
 =&amp;gt; 29&lt;br /&gt;
 =&amp;gt; 24&lt;br /&gt;
&lt;br /&gt;
===method_missing to log method calls&amp;lt;ref&amp;gt;http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2007/wiki1b_2_22&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Another application that makes use of method_missing could be a simple logger used for debugging purposes. Many times, it may be required to log the trace of called methods and provide information such as: called method-name, arguments, return type. It can be tedious to repeat this part of code in every method. A simple solution to this problem can be obtained using method_missing as:&lt;br /&gt;
&lt;br /&gt;
  class SimpleCallLogger&lt;br /&gt;
  def initialize(o)&lt;br /&gt;
  @obj = o&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(methodname, *args)&lt;br /&gt;
  puts &amp;quot;called: #{methodname}(#{args})&amp;quot;&lt;br /&gt;
  a = @obj.send(methodname, *args)&lt;br /&gt;
  puts &amp;quot;\t-&amp;gt; returned: #{a}&amp;quot;&lt;br /&gt;
  return a&lt;br /&gt;
  end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
This program makes use of method_missing in a way that it wraps around called method to output the logging information on entry and on exit, it logs the return type. Further, method_missing intercepts the method call and forward it to internal object with ‘send’ method of ruby. Hence, this use of method_missing acts as wrapper.&lt;br /&gt;
&lt;br /&gt;
===Generic Handler===&lt;br /&gt;
 class NoBar&lt;br /&gt;
 def method_missing(methodname, *args)&lt;br /&gt;
 define_method(:bar) if &amp;quot;bar&amp;quot; == methodname.to_s&lt;br /&gt;
 define_method(:nobar) if &amp;quot;nobar&amp;quot; == methodname.to_s&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This is an example of using method_missing as a generic handler to handle when a calling method is not exist. You can use missing_method to dynamically create a method at a runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Advantages of method_missing'''==&lt;br /&gt;
&lt;br /&gt;
*In addition to specifying the error messages for the undefined methods, method_missing provides a more dynamic behavior in the programming environment.&lt;br /&gt;
*If we are unfamiliar with the usage of the objects we created, then using method_missing is a good technique.&lt;br /&gt;
*Handles problems at runtime.&lt;br /&gt;
*Define's a generic method_missing and handle's any undefined method, a big advantage over Java. In Java, when you call an undefined method, the program will not compile.&lt;br /&gt;
*method_missing falls under the general technique of [http://en.wikipedia.org/wiki/Metaprogramming meta-programming]. Employ meta-programming in missing_function to write an another function to handle the call.&lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages of method_missing'''==	&lt;br /&gt;
*Slower than conventional method lookup. Simple tests indicate that method dispatch with method_missing is at least two to three times as expensive in time as conventional dispatch.&lt;br /&gt;
&lt;br /&gt;
*Since the methods being called never actually exist—they are just intercepted at the last step of the method lookup process—they cannot be documented or introspected as conventional methods can.&lt;br /&gt;
&lt;br /&gt;
*method_missing restricts compatibility with future versions of an [http://en.wikipedia.org/wiki/Application_programming_interface API]. Introducing new methods in a future API version can break users' expectations.&lt;br /&gt;
&lt;br /&gt;
=='''Key Points'''==&lt;br /&gt;
&lt;br /&gt;
*In the below example, class A defines only method method_missing() and no other method. When a new object of class A tries to access a method say 'foo', the respond_to? will return the value 'false'. When you actually try to implement it using “a.foo”, the code will get executed, courtesy of method_missing(). Even though the respond_to? says that you cannot access 'foo' method using object of class A, if you have method_missing() defined, you can access the method.&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In method_missing&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)&lt;br /&gt;
 a.foo&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 false&lt;br /&gt;
 In method_missing&lt;br /&gt;
&lt;br /&gt;
*In the following example, if within method_missing() we define an undefined method. &lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 @@i = 0&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In Method Missing #{@@i}&amp;quot;&lt;br /&gt;
 @@i += 1&lt;br /&gt;
 self.fun&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 a.foo &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 The result is a 'stack level too deep' error. &lt;br /&gt;
&lt;br /&gt;
When the 'foo' method is called, after no method match the method_missing is run and this block has a method “self.fun” that is undefined. Here when the program execution encounters 'self.fun' it once again calls method_missing. This goes on in an endless loop till the stack memory is full.&lt;br /&gt;
&lt;br /&gt;
*Ruby knows method_missing( ) exists, because it's a private instance method of 'BasicObject' that every object inherits. The BasicObject#method_missing( ) responds by raising the NoMethodError. Overriding this method_missing( ) allows you to call methods that don't really exist. &lt;br /&gt;
&lt;br /&gt;
*If method_missing is only looking for certain method names, don't forget to call the [http://en.wikibooks.org/wiki/Java_Programming/Keywords/super super] keyword if you haven't found what you're looking for, so that the other superclass' method_missing can handle it.&lt;br /&gt;
&lt;br /&gt;
*[http://www.prateekdayal.net/2007/10/16/rubys-responds_to-for-checking-if-a-method-exists/ obj.respond_to?] function returns 'true' if the obj responds to the given method. So if you want to know whether your class will respond to a function you can use respond_to? to know the answer. But if method_missing() is used, the output may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
*http://www.rubyinside.com/ &lt;br /&gt;
*https://www.youtube.com/watch?v=SAEiCkixrdE&amp;amp;feature=relmfu&lt;br /&gt;
*http://blog.jayfields.com/2008/02/ruby-replace-methodmissing-with-dynamic.html &lt;br /&gt;
*http://liquiddevelopment.blogspot.com/2006/04/twisting-and-shaping-dsls-using-ruby.html &lt;br /&gt;
*http://blog.rubybestpractices.com/posts/gregory/031-issue-2-method-lookup.html&lt;br /&gt;
*http://phrogz.net/RubyLibs/RubyMethodLookupFlow.pdf&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65288</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w22 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65288"/>
		<updated>2012-09-19T23:38:33Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* Key Points */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''method_missing in Ruby:'''  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Introduction&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_method_missing.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
A method of a class is called by creating an object of the class and passing the method name to the object as a message. The object then looks up into its [http://www.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html method lookup path] and tries to match the called method with the defined methods in the class. On success, the method is executed along with the parameters passed and the result is returned.&lt;br /&gt;
&lt;br /&gt;
If the object does not find a match in its method lookup, in normal circumstances the [http://www.ruby-doc.org/core-1.9.3/NoMethodError.html NoMethodError Exception] is raised .&lt;br /&gt;
&lt;br /&gt;
In cases where the user wants to handle the methods which are not defined but still called, “method_missing” can be defined and the user can handle the methods as he/she sees fit.&lt;br /&gt;
&lt;br /&gt;
=='''Format for defining method_missing'''==&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; def method_missing(m,*args,&amp;amp;block)&lt;br /&gt;
&lt;br /&gt;
(i) '''m-&amp;gt;''' accepts the symbol/name of the undefined method (ii) '''*args-&amp;gt;''' accepts the array of arguments passed in the method call  (iii) '''&amp;amp;block-&amp;gt;'''accepts a block passed to the method&lt;br /&gt;
&lt;br /&gt;
=='''Ruby method lookup flow'''==&lt;br /&gt;
When the object of a class receives a method name to be executed, the following steps are carried out for matching and executing the method:&lt;br /&gt;
&lt;br /&gt;
*First, the object looks in its own [http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html instance methods].&lt;br /&gt;
*Second, it looks in the list of instance methods that all objects of that class share.&lt;br /&gt;
*Third, in each of the included [http://www.tutorialspoint.com/ruby/ruby_modules.html modules] of that class, in reverse order of inclusion. &lt;br /&gt;
*Fourth, it looks in that class’s superclass. &lt;br /&gt;
*Fifth, in the superclass’s included modules, all the way up until it reaches the class Object. &lt;br /&gt;
*Sixth, if it still can’t find a method, the very last place it looks is in the [http://linux.die.net/lkmpg/x40.html Kernel module], included in the class Object. &lt;br /&gt;
*Finally, it calls method_missing (if defined in the class), else throws up the NOMethodError exception.&lt;br /&gt;
&lt;br /&gt;
This entire tracing that the object does is the method lookup path.&lt;br /&gt;
&lt;br /&gt;
=='''Examples'''==&lt;br /&gt;
===Calling defined and undefined methods===&lt;br /&gt;
&lt;br /&gt;
 class A		// creating a class 'A'&lt;br /&gt;
 def say		// defining a method 'say'&lt;br /&gt;
 puts &amp;quot; say Hi &amp;quot; // body of method say&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Creating the object of the class&lt;br /&gt;
 &lt;br /&gt;
  a=A.new	       // object of the class&lt;br /&gt;
  =&amp;gt; #&amp;lt;A:0x2a082e0&amp;gt;     //object id&lt;br /&gt;
&lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.say                  // defined method&lt;br /&gt;
 =&amp;gt; say Hi	       // returned result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.sayhi                // undefined method sayhi&lt;br /&gt;
 NoMethodError: undefined method `sayhi' for #&amp;lt;A:0x2a082e0&amp;gt;   // the NoMethodError is raised&lt;br /&gt;
&lt;br /&gt;
===method_missing implementation&amp;lt;ref&amp;gt;http://www.thirdbit.net/articles/2007/08/01/10-things-you-should-know-about-method_missing/&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def say&lt;br /&gt;
 puts &amp;quot; say hi &amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(m,*args,&amp;amp;block)	// defining method_missing&lt;br /&gt;
 puts &amp;quot; This method does not exist&amp;quot;	// body of method_missing&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Calling a method that is not defined&lt;br /&gt;
 &lt;br /&gt;
 a=A.new&lt;br /&gt;
 a.sayhi                                // calling the undefined method sayhi with no arguments&lt;br /&gt;
 =&amp;gt; This method does not exist		// this result returned when method_missing is executed&lt;br /&gt;
&lt;br /&gt;
When the object 'a' traces its method lookup path for a matching method as 'sayhi', upon failure it resorts to method_missing and the body of method_missing is executed. 'method_missing' is the last resort.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Sometimes when a class has many methods that do generally the same kinds of things, and the programmer is not sure in advance which methods the user will call since there are so many of them, and they are all so similar, writing code for all of them seems futile. In these situations method_missing can be defined to take care of different cases. The below 'Generic Handler' example implements this.&lt;br /&gt;
&lt;br /&gt;
===passing parameters to an undefined method call===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def add(a,b)&lt;br /&gt;
 a+b&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(name,*args,&amp;amp;block)    // the method_missing is defined and the *args parameter accepts all the parameters passed during 								                                 &lt;br /&gt;
                                             the method call   &lt;br /&gt;
 puts “You have typed the method name wrong and these were the parameters passed ; #{args[0]}, #{args[1]}”								&lt;br /&gt;
 end                         			&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The passed parameters are stored in the array 'args' and can be accessed like a normal array                &lt;br /&gt;
                                                   &lt;br /&gt;
 &lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.add(1,2)		        // calling the defined method add and passing the parameters (1,2)&lt;br /&gt;
 =&amp;gt; 3                           // result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.adds(4,2) 			// calling the undefined method adds and passing the parameter (4,2)&lt;br /&gt;
 =&amp;gt; You have typed the method name wrong and these were the parameters passed; 4, 2&lt;br /&gt;
&lt;br /&gt;
The user made a genuine mistake by typing 'adds', but this method is not defined. When the 'adds' method with parameters is called, the object 'a' tries to match the method in the method lookup path. Upon failure it invokes method_missing, the args are passed, stored in the array 'args' and the body of method_missing is executed.&lt;br /&gt;
&lt;br /&gt;
===converting numbers from roman representation to integer representation&amp;lt;ref&amp;gt;http://courses.ncsu.edu/csc517/common/lectures/notes/wk2.pdf&amp;lt;/ref&amp;gt;===&lt;br /&gt;
 class Roman&lt;br /&gt;
 DIGITS = {'I'=&amp;gt;1,'V'=&amp;gt;5,'X'=&amp;gt;10,'L'=&amp;gt;50,'C'=&amp;gt;100,'D'=&amp;gt;500,'M'=&amp;gt;1000,}&lt;br /&gt;
 def roman_to_integer(roman_string)&lt;br /&gt;
 last = nil&lt;br /&gt;
 roman_string.to_s.upcase.split(//).reverse.inject(0) do&lt;br /&gt;
 |memo, digit|&lt;br /&gt;
 if digit_value = DIGITS[digit]&lt;br /&gt;
 if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
 memo -= digit_value&lt;br /&gt;
 else&lt;br /&gt;
 memo += digit_value&lt;br /&gt;
 end&lt;br /&gt;
 last = digit_value&lt;br /&gt;
 end&lt;br /&gt;
 memo&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def method_missing(method)&lt;br /&gt;
 str=method.id2name&lt;br /&gt;
 roman_to_integer(str)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calling the undefined methods&lt;br /&gt;
&lt;br /&gt;
 r= Roman.new&lt;br /&gt;
 r.vii&lt;br /&gt;
 r.xxix&lt;br /&gt;
 r.xxiv&lt;br /&gt;
 r.xxvi&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The Output&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; 7&lt;br /&gt;
 =&amp;gt; 29&lt;br /&gt;
 =&amp;gt; 24&lt;br /&gt;
&lt;br /&gt;
===method_missing to log method calls&amp;lt;ref&amp;gt;http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2007/wiki1b_2_22&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Another application that makes use of method_missing could be a simple logger used for debugging purposes. Many times, it may be required to log the trace of called methods and provide information such as: called method-name, arguments, return type. It can be tedious to repeat this part of code in every method. A simple solution to this problem can be obtained using method_missing as:&lt;br /&gt;
&lt;br /&gt;
  class SimpleCallLogger&lt;br /&gt;
  def initialize(o)&lt;br /&gt;
  @obj = o&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(methodname, *args)&lt;br /&gt;
  puts &amp;quot;called: #{methodname}(#{args})&amp;quot;&lt;br /&gt;
  a = @obj.send(methodname, *args)&lt;br /&gt;
  puts &amp;quot;\t-&amp;gt; returned: #{a}&amp;quot;&lt;br /&gt;
  return a&lt;br /&gt;
  end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
This program makes use of method_missing in a way that it wraps around called method to output the logging information on entry and on exit, it logs the return type. Further, method_missing intercepts the method call and forward it to internal object with ‘send’ method of ruby. Hence, this use of method_missing acts as wrapper.&lt;br /&gt;
&lt;br /&gt;
===Generic Handler===&lt;br /&gt;
 class NoBar&lt;br /&gt;
 def method_missing(methodname, *args)&lt;br /&gt;
 define_method(:bar) if &amp;quot;bar&amp;quot; == methodname.to_s&lt;br /&gt;
 define_method(:nobar) if &amp;quot;nobar&amp;quot; == methodname.to_s&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This is an example of using method_missing as a generic handler to handle when a calling method is not exist. You can use missing_method to dynamically create a method at a runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Advantages of method_missing'''==&lt;br /&gt;
&lt;br /&gt;
*In addition to specifying the error messages for the undefined methods, method_missing provides a more dynamic behavior in the programming environment.&lt;br /&gt;
*If we are unfamiliar with the usage of the objects we created, then using method_missing is a good technique.&lt;br /&gt;
*Handles problems at runtime.&lt;br /&gt;
*Define's a generic method_missing and handle's any undefined method, a big advantage over Java. In Java, when you call an undefined method, the program will not compile.&lt;br /&gt;
*method_missing falls under the general technique of [http://en.wikipedia.org/wiki/Metaprogramming meta-programming]. Employ meta-programming in missing_function to write an another function to handle the call.&lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages of method_missing'''==	&lt;br /&gt;
*Slower than conventional method lookup. Simple tests indicate that method dispatch with method_missing is at least two to three times as expensive in time as conventional dispatch.&lt;br /&gt;
&lt;br /&gt;
*Since the methods being called never actually exist—they are just intercepted at the last step of the method lookup process—they cannot be documented or introspected as conventional methods can.&lt;br /&gt;
&lt;br /&gt;
*method_missing restricts compatibility with future versions of an [http://en.wikipedia.org/wiki/Application_programming_interface API]. Introducing new methods in a future API version can break users' expectations.&lt;br /&gt;
&lt;br /&gt;
=='''Key Points'''==&lt;br /&gt;
*Ruby knows method_missing( ) exists, because it's a private instance method of 'BasicObject' that every object inherits. The BasicObject#method_missing( ) responds by raising the NoMethodError. Overriding this method_missing( ) allows you to call methods that don't really exist. &lt;br /&gt;
&lt;br /&gt;
*If method_missing is only looking for certain method names, don't forget to call the [http://en.wikibooks.org/wiki/Java_Programming/Keywords/super super] keyword if you haven't found what you're looking for, so that the other superclass' method_missing can handle it.&lt;br /&gt;
&lt;br /&gt;
*[http://www.prateekdayal.net/2007/10/16/rubys-responds_to-for-checking-if-a-method-exists/ obj.respond_to?] function returns 'true' if the obj responds to the given method. So if you want to know whether your class will respond to a function you can use respond_to? to know the answer. But if method_missing() is used, the output may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
*In the below example, class A defines only method method_missing() and no other method. When a new object of class A tries to access a method say 'foo', the respond_to? will return the value 'false'. When you actually try to implement it using “a.foo”, the code will get executed, courtesy of method_missing(). Even though the respond_to? says that you cannot access 'foo' method using object of class A, if you have method_missing() defined, you can access the method.&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In method_missing&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)&lt;br /&gt;
 a.foo&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 false&lt;br /&gt;
 In method_missing&lt;br /&gt;
&lt;br /&gt;
*In the following example, if within method_missing() we define an undefined method. &lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 @@i = 0&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In Method Missing #{@@i}&amp;quot;&lt;br /&gt;
 @@i += 1&lt;br /&gt;
 self.fun&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 a.foo &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 The result is a 'stack level too deep' error. &lt;br /&gt;
&lt;br /&gt;
When the 'foo' method is called, after no method match the method_missing is run and this block has a method “self.fun” that is undefined. Here when the program execution encounters 'self.fun' it once again calls method_missing. This goes on in an endless loop till the stack memory is full.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
*http://www.rubyinside.com/ &lt;br /&gt;
*https://www.youtube.com/watch?v=SAEiCkixrdE&amp;amp;feature=relmfu&lt;br /&gt;
*http://blog.jayfields.com/2008/02/ruby-replace-methodmissing-with-dynamic.html &lt;br /&gt;
*http://liquiddevelopment.blogspot.com/2006/04/twisting-and-shaping-dsls-using-ruby.html &lt;br /&gt;
*http://blog.rubybestpractices.com/posts/gregory/031-issue-2-method-lookup.html&lt;br /&gt;
*http://phrogz.net/RubyLibs/RubyMethodLookupFlow.pdf&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65287</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w22 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65287"/>
		<updated>2012-09-19T23:37:26Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* Key Points */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''method_missing in Ruby:'''  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Introduction&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_method_missing.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
A method of a class is called by creating an object of the class and passing the method name to the object as a message. The object then looks up into its [http://www.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html method lookup path] and tries to match the called method with the defined methods in the class. On success, the method is executed along with the parameters passed and the result is returned.&lt;br /&gt;
&lt;br /&gt;
If the object does not find a match in its method lookup, in normal circumstances the [http://www.ruby-doc.org/core-1.9.3/NoMethodError.html NoMethodError Exception] is raised .&lt;br /&gt;
&lt;br /&gt;
In cases where the user wants to handle the methods which are not defined but still called, “method_missing” can be defined and the user can handle the methods as he/she sees fit.&lt;br /&gt;
&lt;br /&gt;
=='''Format for defining method_missing'''==&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; def method_missing(m,*args,&amp;amp;block)&lt;br /&gt;
&lt;br /&gt;
(i) '''m-&amp;gt;''' accepts the symbol/name of the undefined method (ii) '''*args-&amp;gt;''' accepts the array of arguments passed in the method call  (iii) '''&amp;amp;block-&amp;gt;'''accepts a block passed to the method&lt;br /&gt;
&lt;br /&gt;
=='''Ruby method lookup flow'''==&lt;br /&gt;
When the object of a class receives a method name to be executed, the following steps are carried out for matching and executing the method:&lt;br /&gt;
&lt;br /&gt;
*First, the object looks in its own [http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html instance methods].&lt;br /&gt;
*Second, it looks in the list of instance methods that all objects of that class share.&lt;br /&gt;
*Third, in each of the included [http://www.tutorialspoint.com/ruby/ruby_modules.html modules] of that class, in reverse order of inclusion. &lt;br /&gt;
*Fourth, it looks in that class’s superclass. &lt;br /&gt;
*Fifth, in the superclass’s included modules, all the way up until it reaches the class Object. &lt;br /&gt;
*Sixth, if it still can’t find a method, the very last place it looks is in the [http://linux.die.net/lkmpg/x40.html Kernel module], included in the class Object. &lt;br /&gt;
*Finally, it calls method_missing (if defined in the class), else throws up the NOMethodError exception.&lt;br /&gt;
&lt;br /&gt;
This entire tracing that the object does is the method lookup path.&lt;br /&gt;
&lt;br /&gt;
=='''Examples'''==&lt;br /&gt;
===Calling defined and undefined methods===&lt;br /&gt;
&lt;br /&gt;
 class A		// creating a class 'A'&lt;br /&gt;
 def say		// defining a method 'say'&lt;br /&gt;
 puts &amp;quot; say Hi &amp;quot; // body of method say&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Creating the object of the class&lt;br /&gt;
 &lt;br /&gt;
  a=A.new	       // object of the class&lt;br /&gt;
  =&amp;gt; #&amp;lt;A:0x2a082e0&amp;gt;     //object id&lt;br /&gt;
&lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.say                  // defined method&lt;br /&gt;
 =&amp;gt; say Hi	       // returned result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.sayhi                // undefined method sayhi&lt;br /&gt;
 NoMethodError: undefined method `sayhi' for #&amp;lt;A:0x2a082e0&amp;gt;   // the NoMethodError is raised&lt;br /&gt;
&lt;br /&gt;
===method_missing implementation&amp;lt;ref&amp;gt;http://www.thirdbit.net/articles/2007/08/01/10-things-you-should-know-about-method_missing/&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def say&lt;br /&gt;
 puts &amp;quot; say hi &amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(m,*args,&amp;amp;block)	// defining method_missing&lt;br /&gt;
 puts &amp;quot; This method does not exist&amp;quot;	// body of method_missing&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Calling a method that is not defined&lt;br /&gt;
 &lt;br /&gt;
 a=A.new&lt;br /&gt;
 a.sayhi                                // calling the undefined method sayhi with no arguments&lt;br /&gt;
 =&amp;gt; This method does not exist		// this result returned when method_missing is executed&lt;br /&gt;
&lt;br /&gt;
When the object 'a' traces its method lookup path for a matching method as 'sayhi', upon failure it resorts to method_missing and the body of method_missing is executed. 'method_missing' is the last resort.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Sometimes when a class has many methods that do generally the same kinds of things, and the programmer is not sure in advance which methods the user will call since there are so many of them, and they are all so similar, writing code for all of them seems futile. In these situations method_missing can be defined to take care of different cases. The below 'Generic Handler' example implements this.&lt;br /&gt;
&lt;br /&gt;
===passing parameters to an undefined method call===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def add(a,b)&lt;br /&gt;
 a+b&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(name,*args,&amp;amp;block)    // the method_missing is defined and the *args parameter accepts all the parameters passed during 								                                 &lt;br /&gt;
                                             the method call   &lt;br /&gt;
 puts “You have typed the method name wrong and these were the parameters passed ; #{args[0]}, #{args[1]}”								&lt;br /&gt;
 end                         			&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The passed parameters are stored in the array 'args' and can be accessed like a normal array                &lt;br /&gt;
                                                   &lt;br /&gt;
 &lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.add(1,2)		        // calling the defined method add and passing the parameters (1,2)&lt;br /&gt;
 =&amp;gt; 3                           // result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.adds(4,2) 			// calling the undefined method adds and passing the parameter (4,2)&lt;br /&gt;
 =&amp;gt; You have typed the method name wrong and these were the parameters passed; 4, 2&lt;br /&gt;
&lt;br /&gt;
The user made a genuine mistake by typing 'adds', but this method is not defined. When the 'adds' method with parameters is called, the object 'a' tries to match the method in the method lookup path. Upon failure it invokes method_missing, the args are passed, stored in the array 'args' and the body of method_missing is executed.&lt;br /&gt;
&lt;br /&gt;
===converting numbers from roman representation to integer representation&amp;lt;ref&amp;gt;http://courses.ncsu.edu/csc517/common/lectures/notes/wk2.pdf&amp;lt;/ref&amp;gt;===&lt;br /&gt;
 class Roman&lt;br /&gt;
 DIGITS = {'I'=&amp;gt;1,'V'=&amp;gt;5,'X'=&amp;gt;10,'L'=&amp;gt;50,'C'=&amp;gt;100,'D'=&amp;gt;500,'M'=&amp;gt;1000,}&lt;br /&gt;
 def roman_to_integer(roman_string)&lt;br /&gt;
 last = nil&lt;br /&gt;
 roman_string.to_s.upcase.split(//).reverse.inject(0) do&lt;br /&gt;
 |memo, digit|&lt;br /&gt;
 if digit_value = DIGITS[digit]&lt;br /&gt;
 if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
 memo -= digit_value&lt;br /&gt;
 else&lt;br /&gt;
 memo += digit_value&lt;br /&gt;
 end&lt;br /&gt;
 last = digit_value&lt;br /&gt;
 end&lt;br /&gt;
 memo&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def method_missing(method)&lt;br /&gt;
 str=method.id2name&lt;br /&gt;
 roman_to_integer(str)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calling the undefined methods&lt;br /&gt;
&lt;br /&gt;
 r= Roman.new&lt;br /&gt;
 r.vii&lt;br /&gt;
 r.xxix&lt;br /&gt;
 r.xxiv&lt;br /&gt;
 r.xxvi&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The Output&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; 7&lt;br /&gt;
 =&amp;gt; 29&lt;br /&gt;
 =&amp;gt; 24&lt;br /&gt;
&lt;br /&gt;
===method_missing to log method calls&amp;lt;ref&amp;gt;http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2007/wiki1b_2_22&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Another application that makes use of method_missing could be a simple logger used for debugging purposes. Many times, it may be required to log the trace of called methods and provide information such as: called method-name, arguments, return type. It can be tedious to repeat this part of code in every method. A simple solution to this problem can be obtained using method_missing as:&lt;br /&gt;
&lt;br /&gt;
  class SimpleCallLogger&lt;br /&gt;
  def initialize(o)&lt;br /&gt;
  @obj = o&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(methodname, *args)&lt;br /&gt;
  puts &amp;quot;called: #{methodname}(#{args})&amp;quot;&lt;br /&gt;
  a = @obj.send(methodname, *args)&lt;br /&gt;
  puts &amp;quot;\t-&amp;gt; returned: #{a}&amp;quot;&lt;br /&gt;
  return a&lt;br /&gt;
  end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
This program makes use of method_missing in a way that it wraps around called method to output the logging information on entry and on exit, it logs the return type. Further, method_missing intercepts the method call and forward it to internal object with ‘send’ method of ruby. Hence, this use of method_missing acts as wrapper.&lt;br /&gt;
&lt;br /&gt;
===Generic Handler===&lt;br /&gt;
 class NoBar&lt;br /&gt;
 def method_missing(methodname, *args)&lt;br /&gt;
 define_method(:bar) if &amp;quot;bar&amp;quot; == methodname.to_s&lt;br /&gt;
 define_method(:nobar) if &amp;quot;nobar&amp;quot; == methodname.to_s&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This is an example of using method_missing as a generic handler to handle when a calling method is not exist. You can use missing_method to dynamically create a method at a runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Advantages of method_missing'''==&lt;br /&gt;
&lt;br /&gt;
*In addition to specifying the error messages for the undefined methods, method_missing provides a more dynamic behavior in the programming environment.&lt;br /&gt;
*If we are unfamiliar with the usage of the objects we created, then using method_missing is a good technique.&lt;br /&gt;
*Handles problems at runtime.&lt;br /&gt;
*Define's a generic method_missing and handle's any undefined method, a big advantage over Java. In Java, when you call an undefined method, the program will not compile.&lt;br /&gt;
*method_missing falls under the general technique of [http://en.wikipedia.org/wiki/Metaprogramming meta-programming]. Employ meta-programming in missing_function to write an another function to handle the call.&lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages of method_missing'''==	&lt;br /&gt;
*Slower than conventional method lookup. Simple tests indicate that method dispatch with method_missing is at least two to three times as expensive in time as conventional dispatch.&lt;br /&gt;
&lt;br /&gt;
*Since the methods being called never actually exist—they are just intercepted at the last step of the method lookup process—they cannot be documented or introspected as conventional methods can.&lt;br /&gt;
&lt;br /&gt;
*method_missing restricts compatibility with future versions of an [http://en.wikipedia.org/wiki/Application_programming_interface API]. Introducing new methods in a future API version can break users' expectations.&lt;br /&gt;
&lt;br /&gt;
=='''Key Points'''==&lt;br /&gt;
*Ruby knows method_missing( ) exists, because it's a private instance method of 'BasicObject' that every object inherits. The BasicObject#method_missing( ) responds by raising the NoMethodError. Overriding this method_missing( ) allows you to call methods that don't really exist. &lt;br /&gt;
&lt;br /&gt;
*If method_missing is only looking for certain method names, don't forget to call the [http://en.wikibooks.org/wiki/Java_Programming/Keywords/super super] keyword if you haven't found what you're looking for, so that the other superclass' method_missing can handle it.&lt;br /&gt;
&lt;br /&gt;
*[http://www.prateekdayal.net/2007/10/16/rubys-responds_to-for-checking-if-a-method-exists/ obj.respond_to?] function returns 'true' if the obj responds to the given method. So if you want to know whether your class will respond to a function you can use respond_to? to know the answer. But if method_missing() is used, the output may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
*In the below example, class A defines only method method_missing() and no other method. When a new object of class A tries to access a method say 'foo', the respond_to? will return the value 'false'. When you actually try to implement it using “a.foo”, the code will get executed, courtesy of method_missing(). Even though the respond_to? says that you cannot access 'foo' method using object of class A, if you have method_missing() defined, you can access the method.&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In method_missing&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)&lt;br /&gt;
 a.foo&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 false&lt;br /&gt;
 In method_missing&lt;br /&gt;
&lt;br /&gt;
*If within method_missing() we define an undefined method. &lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 @@i = 0&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In Method Missing #{@@i}&amp;quot;&lt;br /&gt;
 @@i += 1&lt;br /&gt;
 self.fun&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 a.foo &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 The result is a 'stack level too deep' error. &lt;br /&gt;
&lt;br /&gt;
When the 'foo' method is called, after no method match the method_missing is run and this block has a method “self.fun” that is undefined. Here when the program execution encounters 'self.fun' it once again calls method_missing. This goes on in an endless loop till the stack memory is full.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
*http://www.rubyinside.com/ &lt;br /&gt;
*https://www.youtube.com/watch?v=SAEiCkixrdE&amp;amp;feature=relmfu&lt;br /&gt;
*http://blog.jayfields.com/2008/02/ruby-replace-methodmissing-with-dynamic.html &lt;br /&gt;
*http://liquiddevelopment.blogspot.com/2006/04/twisting-and-shaping-dsls-using-ruby.html &lt;br /&gt;
*http://blog.rubybestpractices.com/posts/gregory/031-issue-2-method-lookup.html&lt;br /&gt;
*http://phrogz.net/RubyLibs/RubyMethodLookupFlow.pdf&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65284</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w22 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65284"/>
		<updated>2012-09-19T23:32:03Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* Key Points */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''method_missing in Ruby:'''  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Introduction&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_method_missing.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
A method of a class is called by creating an object of the class and passing the method name to the object as a message. The object then looks up into its [http://www.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html method lookup path] and tries to match the called method with the defined methods in the class. On success, the method is executed along with the parameters passed and the result is returned.&lt;br /&gt;
&lt;br /&gt;
If the object does not find a match in its method lookup, in normal circumstances the [http://www.ruby-doc.org/core-1.9.3/NoMethodError.html NoMethodError Exception] is raised .&lt;br /&gt;
&lt;br /&gt;
In cases where the user wants to handle the methods which are not defined but still called, “method_missing” can be defined and the user can handle the methods as he/she sees fit.&lt;br /&gt;
&lt;br /&gt;
=='''Format for defining method_missing'''==&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; def method_missing(m,*args,&amp;amp;block)&lt;br /&gt;
&lt;br /&gt;
(i) '''m-&amp;gt;''' accepts the symbol/name of the undefined method (ii) '''*args-&amp;gt;''' accepts the array of arguments passed in the method call  (iii) '''&amp;amp;block-&amp;gt;'''accepts a block passed to the method&lt;br /&gt;
&lt;br /&gt;
=='''Ruby method lookup flow'''==&lt;br /&gt;
When the object of a class receives a method name to be executed, the following steps are carried out for matching and executing the method:&lt;br /&gt;
&lt;br /&gt;
*First, the object looks in its own [http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html instance methods].&lt;br /&gt;
*Second, it looks in the list of instance methods that all objects of that class share.&lt;br /&gt;
*Third, in each of the included [http://www.tutorialspoint.com/ruby/ruby_modules.html modules] of that class, in reverse order of inclusion. &lt;br /&gt;
*Fourth, it looks in that class’s superclass. &lt;br /&gt;
*Fifth, in the superclass’s included modules, all the way up until it reaches the class Object. &lt;br /&gt;
*Sixth, if it still can’t find a method, the very last place it looks is in the [http://linux.die.net/lkmpg/x40.html Kernel module], included in the class Object. &lt;br /&gt;
*Finally, it calls method_missing (if defined in the class), else throws up the NOMethodError exception.&lt;br /&gt;
&lt;br /&gt;
This entire tracing that the object does is the method lookup path.&lt;br /&gt;
&lt;br /&gt;
=='''Examples'''==&lt;br /&gt;
===Calling defined and undefined methods===&lt;br /&gt;
&lt;br /&gt;
 class A		// creating a class 'A'&lt;br /&gt;
 def say		// defining a method 'say'&lt;br /&gt;
 puts &amp;quot; say Hi &amp;quot; // body of method say&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Creating the object of the class&lt;br /&gt;
 &lt;br /&gt;
  a=A.new	       // object of the class&lt;br /&gt;
  =&amp;gt; #&amp;lt;A:0x2a082e0&amp;gt;     //object id&lt;br /&gt;
&lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.say                  // defined method&lt;br /&gt;
 =&amp;gt; say Hi	       // returned result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.sayhi                // undefined method sayhi&lt;br /&gt;
 NoMethodError: undefined method `sayhi' for #&amp;lt;A:0x2a082e0&amp;gt;   // the NoMethodError is raised&lt;br /&gt;
&lt;br /&gt;
===method_missing implementation&amp;lt;ref&amp;gt;http://www.thirdbit.net/articles/2007/08/01/10-things-you-should-know-about-method_missing/&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def say&lt;br /&gt;
 puts &amp;quot; say hi &amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(m,*args,&amp;amp;block)	// defining method_missing&lt;br /&gt;
 puts &amp;quot; This method does not exist&amp;quot;	// body of method_missing&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Calling a method that is not defined&lt;br /&gt;
 &lt;br /&gt;
 a=A.new&lt;br /&gt;
 a.sayhi                                // calling the undefined method sayhi with no arguments&lt;br /&gt;
 =&amp;gt; This method does not exist		// this result returned when method_missing is executed&lt;br /&gt;
&lt;br /&gt;
When the object 'a' traces its method lookup path for a matching method as 'sayhi', upon failure it resorts to method_missing and the body of method_missing is executed. 'method_missing' is the last resort.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Sometimes when a class has many methods that do generally the same kinds of things, and the programmer is not sure in advance which methods the user will call since there are so many of them, and they are all so similar, writing code for all of them seems futile. In these situations method_missing can be defined to take care of different cases. The below 'Generic Handler' example implements this.&lt;br /&gt;
&lt;br /&gt;
===passing parameters to an undefined method call===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def add(a,b)&lt;br /&gt;
 a+b&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(name,*args,&amp;amp;block)    // the method_missing is defined and the *args parameter accepts all the parameters passed during 								                                 &lt;br /&gt;
                                             the method call   &lt;br /&gt;
 puts “You have typed the method name wrong and these were the parameters passed ; #{args[0]}, #{args[1]}”								&lt;br /&gt;
 end                         			&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The passed parameters are stored in the array 'args' and can be accessed like a normal array                &lt;br /&gt;
                                                   &lt;br /&gt;
 &lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.add(1,2)		        // calling the defined method add and passing the parameters (1,2)&lt;br /&gt;
 =&amp;gt; 3                           // result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.adds(4,2) 			// calling the undefined method adds and passing the parameter (4,2)&lt;br /&gt;
 =&amp;gt; You have typed the method name wrong and these were the parameters passed; 4, 2&lt;br /&gt;
&lt;br /&gt;
The user made a genuine mistake by typing 'adds', but this method is not defined. When the 'adds' method with parameters is called, the object 'a' tries to match the method in the method lookup path. Upon failure it invokes method_missing, the args are passed, stored in the array 'args' and the body of method_missing is executed.&lt;br /&gt;
&lt;br /&gt;
===converting numbers from roman representation to integer representation&amp;lt;ref&amp;gt;http://courses.ncsu.edu/csc517/common/lectures/notes/wk2.pdf&amp;lt;/ref&amp;gt;===&lt;br /&gt;
 class Roman&lt;br /&gt;
 DIGITS = {'I'=&amp;gt;1,'V'=&amp;gt;5,'X'=&amp;gt;10,'L'=&amp;gt;50,'C'=&amp;gt;100,'D'=&amp;gt;500,'M'=&amp;gt;1000,}&lt;br /&gt;
 def roman_to_integer(roman_string)&lt;br /&gt;
 last = nil&lt;br /&gt;
 roman_string.to_s.upcase.split(//).reverse.inject(0) do&lt;br /&gt;
 |memo, digit|&lt;br /&gt;
 if digit_value = DIGITS[digit]&lt;br /&gt;
 if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
 memo -= digit_value&lt;br /&gt;
 else&lt;br /&gt;
 memo += digit_value&lt;br /&gt;
 end&lt;br /&gt;
 last = digit_value&lt;br /&gt;
 end&lt;br /&gt;
 memo&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def method_missing(method)&lt;br /&gt;
 str=method.id2name&lt;br /&gt;
 roman_to_integer(str)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calling the undefined methods&lt;br /&gt;
&lt;br /&gt;
 r= Roman.new&lt;br /&gt;
 r.vii&lt;br /&gt;
 r.xxix&lt;br /&gt;
 r.xxiv&lt;br /&gt;
 r.xxvi&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The Output&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; 7&lt;br /&gt;
 =&amp;gt; 29&lt;br /&gt;
 =&amp;gt; 24&lt;br /&gt;
&lt;br /&gt;
===method_missing to log method calls&amp;lt;ref&amp;gt;http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2007/wiki1b_2_22&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Another application that makes use of method_missing could be a simple logger used for debugging purposes. Many times, it may be required to log the trace of called methods and provide information such as: called method-name, arguments, return type. It can be tedious to repeat this part of code in every method. A simple solution to this problem can be obtained using method_missing as:&lt;br /&gt;
&lt;br /&gt;
  class SimpleCallLogger&lt;br /&gt;
  def initialize(o)&lt;br /&gt;
  @obj = o&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(methodname, *args)&lt;br /&gt;
  puts &amp;quot;called: #{methodname}(#{args})&amp;quot;&lt;br /&gt;
  a = @obj.send(methodname, *args)&lt;br /&gt;
  puts &amp;quot;\t-&amp;gt; returned: #{a}&amp;quot;&lt;br /&gt;
  return a&lt;br /&gt;
  end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
This program makes use of method_missing in a way that it wraps around called method to output the logging information on entry and on exit, it logs the return type. Further, method_missing intercepts the method call and forward it to internal object with ‘send’ method of ruby. Hence, this use of method_missing acts as wrapper.&lt;br /&gt;
&lt;br /&gt;
===Generic Handler===&lt;br /&gt;
 class NoBar&lt;br /&gt;
 def method_missing(methodname, *args)&lt;br /&gt;
 define_method(:bar) if &amp;quot;bar&amp;quot; == methodname.to_s&lt;br /&gt;
 define_method(:nobar) if &amp;quot;nobar&amp;quot; == methodname.to_s&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This is an example of using method_missing as a generic handler to handle when a calling method is not exist. You can use missing_method to dynamically create a method at a runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Advantages of method_missing'''==&lt;br /&gt;
&lt;br /&gt;
*In addition to specifying the error messages for the undefined methods, method_missing provides a more dynamic behavior in the programming environment.&lt;br /&gt;
*If we are unfamiliar with the usage of the objects we created, then using method_missing is a good technique.&lt;br /&gt;
*Handles problems at runtime.&lt;br /&gt;
*Define's a generic method_missing and handle's any undefined method, a big advantage over Java. In Java, when you call an undefined method, the program will not compile.&lt;br /&gt;
*method_missing falls under the general technique of [http://en.wikipedia.org/wiki/Metaprogramming meta-programming]. Employ meta-programming in missing_function to write an another function to handle the call.&lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages of method_missing'''==	&lt;br /&gt;
*Slower than conventional method lookup. Simple tests indicate that method dispatch with method_missing is at least two to three times as expensive in time as conventional dispatch.&lt;br /&gt;
&lt;br /&gt;
*Since the methods being called never actually exist—they are just intercepted at the last step of the method lookup process—they cannot be documented or introspected as conventional methods can.&lt;br /&gt;
&lt;br /&gt;
*method_missing restricts compatibility with future versions of an [http://en.wikipedia.org/wiki/Application_programming_interface API]. Introducing new methods in a future API version can break users' expectations.&lt;br /&gt;
&lt;br /&gt;
=='''Key Points'''==&lt;br /&gt;
*Ruby knows method_missing( ) exists, because it's a private instance method of 'BasicObject' that every object inherits. The BasicObject#method_missing( ) responds by raising the NoMethodError. Overriding this method_missing( ) allows you to call methods that don't really exist. &lt;br /&gt;
&lt;br /&gt;
*If method_missing is only looking for certain method names, don't forget to call the [http://en.wikibooks.org/wiki/Java_Programming/Keywords/super super] keyword if you haven't found what you're looking for, so that the other superclass' method_missing can handle it.&lt;br /&gt;
&lt;br /&gt;
*[http://www.prateekdayal.net/2007/10/16/rubys-responds_to-for-checking-if-a-method-exists/ obj.respond_to?] function returns 'true' if the obj responds to the given method. So if you want to know whether your class will respond to a function you can use respond_to? to know the answer. But if method_missing() is used, the output may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
*Below class A defines only method method_missing() and no other method. When a new object of class A tries to access a method say 'foo', the respond_to? will return the value 'false'. When you actually try to implement it using “a.foo”, the code will get executed, courtesy of method_missing(). Even though the respond_to? says that you cannot access 'foo' method using object of class A, if you have method_missing() defined, you can access the method.&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In method_missing&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)&lt;br /&gt;
 a.foo&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 false&lt;br /&gt;
 In method_missing&lt;br /&gt;
&lt;br /&gt;
*If within method_missing() we define an undefined method. &lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 @@i = 0&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In Method Missing #{@@i}&amp;quot;&lt;br /&gt;
 @@i += 1&lt;br /&gt;
 self.fun&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 a.foo &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 The result is a 'stack level too deep' error. &lt;br /&gt;
&lt;br /&gt;
When the 'foo' method is called, after no method match the method_missing is run and this block has a method “self.fun” that is undefined. Here when the program execution encounters 'self.fun' it once again calls method_missing. This goes on in an endless loop till the stack memory is full.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
*http://www.rubyinside.com/ &lt;br /&gt;
*https://www.youtube.com/watch?v=SAEiCkixrdE&amp;amp;feature=relmfu&lt;br /&gt;
*http://blog.jayfields.com/2008/02/ruby-replace-methodmissing-with-dynamic.html &lt;br /&gt;
*http://liquiddevelopment.blogspot.com/2006/04/twisting-and-shaping-dsls-using-ruby.html &lt;br /&gt;
*http://blog.rubybestpractices.com/posts/gregory/031-issue-2-method-lookup.html&lt;br /&gt;
*http://phrogz.net/RubyLibs/RubyMethodLookupFlow.pdf&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65283</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w22 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65283"/>
		<updated>2012-09-19T23:31:09Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* dfs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''method_missing in Ruby:'''  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Introduction&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_method_missing.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
A method of a class is called by creating an object of the class and passing the method name to the object as a message. The object then looks up into its [http://www.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html method lookup path] and tries to match the called method with the defined methods in the class. On success, the method is executed along with the parameters passed and the result is returned.&lt;br /&gt;
&lt;br /&gt;
If the object does not find a match in its method lookup, in normal circumstances the [http://www.ruby-doc.org/core-1.9.3/NoMethodError.html NoMethodError Exception] is raised .&lt;br /&gt;
&lt;br /&gt;
In cases where the user wants to handle the methods which are not defined but still called, “method_missing” can be defined and the user can handle the methods as he/she sees fit.&lt;br /&gt;
&lt;br /&gt;
=='''Format for defining method_missing'''==&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; def method_missing(m,*args,&amp;amp;block)&lt;br /&gt;
&lt;br /&gt;
(i) '''m-&amp;gt;''' accepts the symbol/name of the undefined method (ii) '''*args-&amp;gt;''' accepts the array of arguments passed in the method call  (iii) '''&amp;amp;block-&amp;gt;'''accepts a block passed to the method&lt;br /&gt;
&lt;br /&gt;
=='''Ruby method lookup flow'''==&lt;br /&gt;
When the object of a class receives a method name to be executed, the following steps are carried out for matching and executing the method:&lt;br /&gt;
&lt;br /&gt;
*First, the object looks in its own [http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html instance methods].&lt;br /&gt;
*Second, it looks in the list of instance methods that all objects of that class share.&lt;br /&gt;
*Third, in each of the included [http://www.tutorialspoint.com/ruby/ruby_modules.html modules] of that class, in reverse order of inclusion. &lt;br /&gt;
*Fourth, it looks in that class’s superclass. &lt;br /&gt;
*Fifth, in the superclass’s included modules, all the way up until it reaches the class Object. &lt;br /&gt;
*Sixth, if it still can’t find a method, the very last place it looks is in the [http://linux.die.net/lkmpg/x40.html Kernel module], included in the class Object. &lt;br /&gt;
*Finally, it calls method_missing (if defined in the class), else throws up the NOMethodError exception.&lt;br /&gt;
&lt;br /&gt;
This entire tracing that the object does is the method lookup path.&lt;br /&gt;
&lt;br /&gt;
=='''Examples'''==&lt;br /&gt;
===Calling defined and undefined methods===&lt;br /&gt;
&lt;br /&gt;
 class A		// creating a class 'A'&lt;br /&gt;
 def say		// defining a method 'say'&lt;br /&gt;
 puts &amp;quot; say Hi &amp;quot; // body of method say&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Creating the object of the class&lt;br /&gt;
 &lt;br /&gt;
  a=A.new	       // object of the class&lt;br /&gt;
  =&amp;gt; #&amp;lt;A:0x2a082e0&amp;gt;     //object id&lt;br /&gt;
&lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.say                  // defined method&lt;br /&gt;
 =&amp;gt; say Hi	       // returned result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.sayhi                // undefined method sayhi&lt;br /&gt;
 NoMethodError: undefined method `sayhi' for #&amp;lt;A:0x2a082e0&amp;gt;   // the NoMethodError is raised&lt;br /&gt;
&lt;br /&gt;
===method_missing implementation&amp;lt;ref&amp;gt;http://www.thirdbit.net/articles/2007/08/01/10-things-you-should-know-about-method_missing/&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def say&lt;br /&gt;
 puts &amp;quot; say hi &amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(m,*args,&amp;amp;block)	// defining method_missing&lt;br /&gt;
 puts &amp;quot; This method does not exist&amp;quot;	// body of method_missing&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Calling a method that is not defined&lt;br /&gt;
 &lt;br /&gt;
 a=A.new&lt;br /&gt;
 a.sayhi                                // calling the undefined method sayhi with no arguments&lt;br /&gt;
 =&amp;gt; This method does not exist		// this result returned when method_missing is executed&lt;br /&gt;
&lt;br /&gt;
When the object 'a' traces its method lookup path for a matching method as 'sayhi', upon failure it resorts to method_missing and the body of method_missing is executed. 'method_missing' is the last resort.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Sometimes when a class has many methods that do generally the same kinds of things, and the programmer is not sure in advance which methods the user will call since there are so many of them, and they are all so similar, writing code for all of them seems futile. In these situations method_missing can be defined to take care of different cases. The below 'Generic Handler' example implements this.&lt;br /&gt;
&lt;br /&gt;
===passing parameters to an undefined method call===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def add(a,b)&lt;br /&gt;
 a+b&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(name,*args,&amp;amp;block)    // the method_missing is defined and the *args parameter accepts all the parameters passed during 								                                 &lt;br /&gt;
                                             the method call   &lt;br /&gt;
 puts “You have typed the method name wrong and these were the parameters passed ; #{args[0]}, #{args[1]}”								&lt;br /&gt;
 end                         			&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The passed parameters are stored in the array 'args' and can be accessed like a normal array                &lt;br /&gt;
                                                   &lt;br /&gt;
 &lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.add(1,2)		        // calling the defined method add and passing the parameters (1,2)&lt;br /&gt;
 =&amp;gt; 3                           // result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.adds(4,2) 			// calling the undefined method adds and passing the parameter (4,2)&lt;br /&gt;
 =&amp;gt; You have typed the method name wrong and these were the parameters passed; 4, 2&lt;br /&gt;
&lt;br /&gt;
The user made a genuine mistake by typing 'adds', but this method is not defined. When the 'adds' method with parameters is called, the object 'a' tries to match the method in the method lookup path. Upon failure it invokes method_missing, the args are passed, stored in the array 'args' and the body of method_missing is executed.&lt;br /&gt;
&lt;br /&gt;
===converting numbers from roman representation to integer representation&amp;lt;ref&amp;gt;http://courses.ncsu.edu/csc517/common/lectures/notes/wk2.pdf&amp;lt;/ref&amp;gt;===&lt;br /&gt;
 class Roman&lt;br /&gt;
 DIGITS = {'I'=&amp;gt;1,'V'=&amp;gt;5,'X'=&amp;gt;10,'L'=&amp;gt;50,'C'=&amp;gt;100,'D'=&amp;gt;500,'M'=&amp;gt;1000,}&lt;br /&gt;
 def roman_to_integer(roman_string)&lt;br /&gt;
 last = nil&lt;br /&gt;
 roman_string.to_s.upcase.split(//).reverse.inject(0) do&lt;br /&gt;
 |memo, digit|&lt;br /&gt;
 if digit_value = DIGITS[digit]&lt;br /&gt;
 if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
 memo -= digit_value&lt;br /&gt;
 else&lt;br /&gt;
 memo += digit_value&lt;br /&gt;
 end&lt;br /&gt;
 last = digit_value&lt;br /&gt;
 end&lt;br /&gt;
 memo&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def method_missing(method)&lt;br /&gt;
 str=method.id2name&lt;br /&gt;
 roman_to_integer(str)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calling the undefined methods&lt;br /&gt;
&lt;br /&gt;
 r= Roman.new&lt;br /&gt;
 r.vii&lt;br /&gt;
 r.xxix&lt;br /&gt;
 r.xxiv&lt;br /&gt;
 r.xxvi&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The Output&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; 7&lt;br /&gt;
 =&amp;gt; 29&lt;br /&gt;
 =&amp;gt; 24&lt;br /&gt;
&lt;br /&gt;
===method_missing to log method calls&amp;lt;ref&amp;gt;http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2007/wiki1b_2_22&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Another application that makes use of method_missing could be a simple logger used for debugging purposes. Many times, it may be required to log the trace of called methods and provide information such as: called method-name, arguments, return type. It can be tedious to repeat this part of code in every method. A simple solution to this problem can be obtained using method_missing as:&lt;br /&gt;
&lt;br /&gt;
  class SimpleCallLogger&lt;br /&gt;
  def initialize(o)&lt;br /&gt;
  @obj = o&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(methodname, *args)&lt;br /&gt;
  puts &amp;quot;called: #{methodname}(#{args})&amp;quot;&lt;br /&gt;
  a = @obj.send(methodname, *args)&lt;br /&gt;
  puts &amp;quot;\t-&amp;gt; returned: #{a}&amp;quot;&lt;br /&gt;
  return a&lt;br /&gt;
  end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
This program makes use of method_missing in a way that it wraps around called method to output the logging information on entry and on exit, it logs the return type. Further, method_missing intercepts the method call and forward it to internal object with ‘send’ method of ruby. Hence, this use of method_missing acts as wrapper.&lt;br /&gt;
&lt;br /&gt;
===Generic Handler===&lt;br /&gt;
 class NoBar&lt;br /&gt;
 def method_missing(methodname, *args)&lt;br /&gt;
 define_method(:bar) if &amp;quot;bar&amp;quot; == methodname.to_s&lt;br /&gt;
 define_method(:nobar) if &amp;quot;nobar&amp;quot; == methodname.to_s&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This is an example of using method_missing as a generic handler to handle when a calling method is not exist. You can use missing_method to dynamically create a method at a runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Advantages of method_missing'''==&lt;br /&gt;
&lt;br /&gt;
*In addition to specifying the error messages for the undefined methods, method_missing provides a more dynamic behavior in the programming environment.&lt;br /&gt;
*If we are unfamiliar with the usage of the objects we created, then using method_missing is a good technique.&lt;br /&gt;
*Handles problems at runtime.&lt;br /&gt;
*Define's a generic method_missing and handle's any undefined method, a big advantage over Java. In Java, when you call an undefined method, the program will not compile.&lt;br /&gt;
*method_missing falls under the general technique of [http://en.wikipedia.org/wiki/Metaprogramming meta-programming]. Employ meta-programming in missing_function to write an another function to handle the call.&lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages of method_missing'''==	&lt;br /&gt;
*Slower than conventional method lookup. Simple tests indicate that method dispatch with method_missing is at least two to three times as expensive in time as conventional dispatch.&lt;br /&gt;
&lt;br /&gt;
*Since the methods being called never actually exist—they are just intercepted at the last step of the method lookup process—they cannot be documented or introspected as conventional methods can.&lt;br /&gt;
&lt;br /&gt;
*method_missing restricts compatibility with future versions of an [http://en.wikipedia.org/wiki/Application_programming_interface API]. Introducing new methods in a future API version can break users' expectations.&lt;br /&gt;
&lt;br /&gt;
=='''Key Points'''==&lt;br /&gt;
*Ruby knows method_missing( ) exists, because it's a private instance method of 'BasicObject' that every object inherits. The BasicObject#method_missing( ) responds by raising the NoMethodError. Overriding this method_missing( ) allows you to call methods that don't really exist. &lt;br /&gt;
&lt;br /&gt;
*If method_missing is only looking for certain method names, don't forget to call the [http://en.wikibooks.org/wiki/Java_Programming/Keywords/super super] keyword if you haven't found what you're looking for, so that the other superclass' method_missing can handle it.&lt;br /&gt;
&lt;br /&gt;
*[http://www.prateekdayal.net/2007/10/16/rubys-responds_to-for-checking-if-a-method-exists/ obj.respond_to?] function returns 'true' if the obj responds to the given method. So if you want to know whether your class will respond to a function you can use respond_to? to know the answer. But if method_missing() is used, the output may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
*Below class A defines only method method_missing() and no other method. When a new object of class A tries to access a method say 'foo', the respond_to? will return the value 'false'. When you actually try to implement it using “a.foo”, the code will get executed, courtesy of method_missing(). Even though the respond_to? says that you cannot access 'foo' method using object of class A, if you have method_missing() defined, you can access the method.&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In method_missing&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)&lt;br /&gt;
 a.foo&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 false&lt;br /&gt;
 In method_missing&lt;br /&gt;
&lt;br /&gt;
*If within method_missing() we define an undefined method. &lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 @@i = 0&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In Method Missing #{@@i}&amp;quot;&lt;br /&gt;
 @@i += 1&lt;br /&gt;
 self.fun&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)	// just checking whether the receiver 'a' responds to the method 'foo'&lt;br /&gt;
				  &lt;br /&gt;
 a.foo &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 The result is a 'stack level too deep' error. &lt;br /&gt;
&lt;br /&gt;
When the 'foo' method is called, after no method match the method_missing is run and this block has a method “self.fun” that is undefined. Here when the program execution encounters 'self.fun' it once again calls method_missing. This goes on in an endless loop till the stack memory is full.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
*http://www.rubyinside.com/ &lt;br /&gt;
*https://www.youtube.com/watch?v=SAEiCkixrdE&amp;amp;feature=relmfu&lt;br /&gt;
*http://blog.jayfields.com/2008/02/ruby-replace-methodmissing-with-dynamic.html &lt;br /&gt;
*http://liquiddevelopment.blogspot.com/2006/04/twisting-and-shaping-dsls-using-ruby.html &lt;br /&gt;
*http://blog.rubybestpractices.com/posts/gregory/031-issue-2-method-lookup.html&lt;br /&gt;
*http://phrogz.net/RubyLibs/RubyMethodLookupFlow.pdf&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65282</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w22 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65282"/>
		<updated>2012-09-19T23:30:14Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* Different types of methods */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''method_missing in Ruby:'''  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Introduction&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_method_missing.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
A method of a class is called by creating an object of the class and passing the method name to the object as a message. The object then looks up into its [http://www.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html method lookup path] and tries to match the called method with the defined methods in the class. On success, the method is executed along with the parameters passed and the result is returned.&lt;br /&gt;
&lt;br /&gt;
If the object does not find a match in its method lookup, in normal circumstances the [http://www.ruby-doc.org/core-1.9.3/NoMethodError.html NoMethodError Exception] is raised .&lt;br /&gt;
&lt;br /&gt;
In cases where the user wants to handle the methods which are not defined but still called, “method_missing” can be defined and the user can handle the methods as he/she sees fit.&lt;br /&gt;
&lt;br /&gt;
=='''Format for defining method_missing'''==&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; def method_missing(m,*args,&amp;amp;block)&lt;br /&gt;
&lt;br /&gt;
(i) '''m-&amp;gt;''' accepts the symbol/name of the undefined method (ii) '''*args-&amp;gt;''' accepts the array of arguments passed in the method call  (iii) '''&amp;amp;block-&amp;gt;'''accepts a block passed to the method&lt;br /&gt;
&lt;br /&gt;
=='''dfs'''==&lt;br /&gt;
When the object of a class receives a method name to be executed, the following steps are carried out for matching and executing the method:&lt;br /&gt;
&lt;br /&gt;
*First, the object looks in its own [http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html instance methods].&lt;br /&gt;
*Second, it looks in the list of instance methods that all objects of that class share.&lt;br /&gt;
*Third, in each of the included [http://www.tutorialspoint.com/ruby/ruby_modules.html modules] of that class, in reverse order of inclusion. &lt;br /&gt;
*Fourth, it looks in that class’s superclass. &lt;br /&gt;
*Fifth, in the superclass’s included modules, all the way up until it reaches the class Object. &lt;br /&gt;
*Sixth, if it still can’t find a method, the very last place it looks is in the [http://linux.die.net/lkmpg/x40.html Kernel module], included in the class Object. &lt;br /&gt;
*Finally, it calls method_missing (if defined in the class), else throws up the NOMethodError exception.&lt;br /&gt;
&lt;br /&gt;
This entire tracing that the object does is the method lookup path.&lt;br /&gt;
&lt;br /&gt;
=='''Examples'''==&lt;br /&gt;
===Calling defined and undefined methods===&lt;br /&gt;
&lt;br /&gt;
 class A		// creating a class 'A'&lt;br /&gt;
 def say		// defining a method 'say'&lt;br /&gt;
 puts &amp;quot; say Hi &amp;quot; // body of method say&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Creating the object of the class&lt;br /&gt;
 &lt;br /&gt;
  a=A.new	       // object of the class&lt;br /&gt;
  =&amp;gt; #&amp;lt;A:0x2a082e0&amp;gt;     //object id&lt;br /&gt;
&lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.say                  // defined method&lt;br /&gt;
 =&amp;gt; say Hi	       // returned result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.sayhi                // undefined method sayhi&lt;br /&gt;
 NoMethodError: undefined method `sayhi' for #&amp;lt;A:0x2a082e0&amp;gt;   // the NoMethodError is raised&lt;br /&gt;
&lt;br /&gt;
===method_missing implementation&amp;lt;ref&amp;gt;http://www.thirdbit.net/articles/2007/08/01/10-things-you-should-know-about-method_missing/&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def say&lt;br /&gt;
 puts &amp;quot; say hi &amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(m,*args,&amp;amp;block)	// defining method_missing&lt;br /&gt;
 puts &amp;quot; This method does not exist&amp;quot;	// body of method_missing&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Calling a method that is not defined&lt;br /&gt;
 &lt;br /&gt;
 a=A.new&lt;br /&gt;
 a.sayhi                                // calling the undefined method sayhi with no arguments&lt;br /&gt;
 =&amp;gt; This method does not exist		// this result returned when method_missing is executed&lt;br /&gt;
&lt;br /&gt;
When the object 'a' traces its method lookup path for a matching method as 'sayhi', upon failure it resorts to method_missing and the body of method_missing is executed. 'method_missing' is the last resort.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Sometimes when a class has many methods that do generally the same kinds of things, and the programmer is not sure in advance which methods the user will call since there are so many of them, and they are all so similar, writing code for all of them seems futile. In these situations method_missing can be defined to take care of different cases. The below 'Generic Handler' example implements this.&lt;br /&gt;
&lt;br /&gt;
===passing parameters to an undefined method call===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def add(a,b)&lt;br /&gt;
 a+b&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(name,*args,&amp;amp;block)    // the method_missing is defined and the *args parameter accepts all the parameters passed during 								                                 &lt;br /&gt;
                                             the method call   &lt;br /&gt;
 puts “You have typed the method name wrong and these were the parameters passed ; #{args[0]}, #{args[1]}”								&lt;br /&gt;
 end                         			&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The passed parameters are stored in the array 'args' and can be accessed like a normal array                &lt;br /&gt;
                                                   &lt;br /&gt;
 &lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.add(1,2)		        // calling the defined method add and passing the parameters (1,2)&lt;br /&gt;
 =&amp;gt; 3                           // result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.adds(4,2) 			// calling the undefined method adds and passing the parameter (4,2)&lt;br /&gt;
 =&amp;gt; You have typed the method name wrong and these were the parameters passed; 4, 2&lt;br /&gt;
&lt;br /&gt;
The user made a genuine mistake by typing 'adds', but this method is not defined. When the 'adds' method with parameters is called, the object 'a' tries to match the method in the method lookup path. Upon failure it invokes method_missing, the args are passed, stored in the array 'args' and the body of method_missing is executed.&lt;br /&gt;
&lt;br /&gt;
===converting numbers from roman representation to integer representation&amp;lt;ref&amp;gt;http://courses.ncsu.edu/csc517/common/lectures/notes/wk2.pdf&amp;lt;/ref&amp;gt;===&lt;br /&gt;
 class Roman&lt;br /&gt;
 DIGITS = {'I'=&amp;gt;1,'V'=&amp;gt;5,'X'=&amp;gt;10,'L'=&amp;gt;50,'C'=&amp;gt;100,'D'=&amp;gt;500,'M'=&amp;gt;1000,}&lt;br /&gt;
 def roman_to_integer(roman_string)&lt;br /&gt;
 last = nil&lt;br /&gt;
 roman_string.to_s.upcase.split(//).reverse.inject(0) do&lt;br /&gt;
 |memo, digit|&lt;br /&gt;
 if digit_value = DIGITS[digit]&lt;br /&gt;
 if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
 memo -= digit_value&lt;br /&gt;
 else&lt;br /&gt;
 memo += digit_value&lt;br /&gt;
 end&lt;br /&gt;
 last = digit_value&lt;br /&gt;
 end&lt;br /&gt;
 memo&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def method_missing(method)&lt;br /&gt;
 str=method.id2name&lt;br /&gt;
 roman_to_integer(str)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calling the undefined methods&lt;br /&gt;
&lt;br /&gt;
 r= Roman.new&lt;br /&gt;
 r.vii&lt;br /&gt;
 r.xxix&lt;br /&gt;
 r.xxiv&lt;br /&gt;
 r.xxvi&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The Output&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; 7&lt;br /&gt;
 =&amp;gt; 29&lt;br /&gt;
 =&amp;gt; 24&lt;br /&gt;
&lt;br /&gt;
===method_missing to log method calls&amp;lt;ref&amp;gt;http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2007/wiki1b_2_22&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Another application that makes use of method_missing could be a simple logger used for debugging purposes. Many times, it may be required to log the trace of called methods and provide information such as: called method-name, arguments, return type. It can be tedious to repeat this part of code in every method. A simple solution to this problem can be obtained using method_missing as:&lt;br /&gt;
&lt;br /&gt;
  class SimpleCallLogger&lt;br /&gt;
  def initialize(o)&lt;br /&gt;
  @obj = o&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(methodname, *args)&lt;br /&gt;
  puts &amp;quot;called: #{methodname}(#{args})&amp;quot;&lt;br /&gt;
  a = @obj.send(methodname, *args)&lt;br /&gt;
  puts &amp;quot;\t-&amp;gt; returned: #{a}&amp;quot;&lt;br /&gt;
  return a&lt;br /&gt;
  end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
This program makes use of method_missing in a way that it wraps around called method to output the logging information on entry and on exit, it logs the return type. Further, method_missing intercepts the method call and forward it to internal object with ‘send’ method of ruby. Hence, this use of method_missing acts as wrapper.&lt;br /&gt;
&lt;br /&gt;
===Generic Handler===&lt;br /&gt;
 class NoBar&lt;br /&gt;
 def method_missing(methodname, *args)&lt;br /&gt;
 define_method(:bar) if &amp;quot;bar&amp;quot; == methodname.to_s&lt;br /&gt;
 define_method(:nobar) if &amp;quot;nobar&amp;quot; == methodname.to_s&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This is an example of using method_missing as a generic handler to handle when a calling method is not exist. You can use missing_method to dynamically create a method at a runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Advantages of method_missing'''==&lt;br /&gt;
&lt;br /&gt;
*In addition to specifying the error messages for the undefined methods, method_missing provides a more dynamic behavior in the programming environment.&lt;br /&gt;
*If we are unfamiliar with the usage of the objects we created, then using method_missing is a good technique.&lt;br /&gt;
*Handles problems at runtime.&lt;br /&gt;
*Define's a generic method_missing and handle's any undefined method, a big advantage over Java. In Java, when you call an undefined method, the program will not compile.&lt;br /&gt;
*method_missing falls under the general technique of [http://en.wikipedia.org/wiki/Metaprogramming meta-programming]. Employ meta-programming in missing_function to write an another function to handle the call.&lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages of method_missing'''==	&lt;br /&gt;
*Slower than conventional method lookup. Simple tests indicate that method dispatch with method_missing is at least two to three times as expensive in time as conventional dispatch.&lt;br /&gt;
&lt;br /&gt;
*Since the methods being called never actually exist—they are just intercepted at the last step of the method lookup process—they cannot be documented or introspected as conventional methods can.&lt;br /&gt;
&lt;br /&gt;
*method_missing restricts compatibility with future versions of an [http://en.wikipedia.org/wiki/Application_programming_interface API]. Introducing new methods in a future API version can break users' expectations.&lt;br /&gt;
&lt;br /&gt;
=='''Key Points'''==&lt;br /&gt;
*Ruby knows method_missing( ) exists, because it's a private instance method of 'BasicObject' that every object inherits. The BasicObject#method_missing( ) responds by raising the NoMethodError. Overriding this method_missing( ) allows you to call methods that don't really exist. &lt;br /&gt;
&lt;br /&gt;
*If method_missing is only looking for certain method names, don't forget to call the [http://en.wikibooks.org/wiki/Java_Programming/Keywords/super super] keyword if you haven't found what you're looking for, so that the other superclass' method_missing can handle it.&lt;br /&gt;
&lt;br /&gt;
*[http://www.prateekdayal.net/2007/10/16/rubys-responds_to-for-checking-if-a-method-exists/ obj.respond_to?] function returns 'true' if the obj responds to the given method. So if you want to know whether your class will respond to a function you can use respond_to? to know the answer. But if method_missing() is used, the output may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
*Below class A defines only method method_missing() and no other method. When a new object of class A tries to access a method say 'foo', the respond_to? will return the value 'false'. When you actually try to implement it using “a.foo”, the code will get executed, courtesy of method_missing(). Even though the respond_to? says that you cannot access 'foo' method using object of class A, if you have method_missing() defined, you can access the method.&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In method_missing&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)&lt;br /&gt;
 a.foo&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 false&lt;br /&gt;
 In method_missing&lt;br /&gt;
&lt;br /&gt;
*If within method_missing() we define an undefined method. &lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 @@i = 0&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In Method Missing #{@@i}&amp;quot;&lt;br /&gt;
 @@i += 1&lt;br /&gt;
 self.fun&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)	// just checking whether the receiver 'a' responds to the method 'foo'&lt;br /&gt;
				  &lt;br /&gt;
 a.foo &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 The result is a 'stack level too deep' error. &lt;br /&gt;
&lt;br /&gt;
When the 'foo' method is called, after no method match the method_missing is run and this block has a method “self.fun” that is undefined. Here when the program execution encounters 'self.fun' it once again calls method_missing. This goes on in an endless loop till the stack memory is full.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
*http://www.rubyinside.com/ &lt;br /&gt;
*https://www.youtube.com/watch?v=SAEiCkixrdE&amp;amp;feature=relmfu&lt;br /&gt;
*http://blog.jayfields.com/2008/02/ruby-replace-methodmissing-with-dynamic.html &lt;br /&gt;
*http://liquiddevelopment.blogspot.com/2006/04/twisting-and-shaping-dsls-using-ruby.html &lt;br /&gt;
*http://blog.rubybestpractices.com/posts/gregory/031-issue-2-method-lookup.html&lt;br /&gt;
*http://phrogz.net/RubyLibs/RubyMethodLookupFlow.pdf&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65280</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w22 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65280"/>
		<updated>2012-09-19T23:24:44Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* Key Points */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''method_missing in Ruby:'''  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Introduction&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_method_missing.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
A method of a class is called by creating an object of the class and passing the method name to the object as a message. The object then looks up into its [http://www.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html method lookup path] and tries to match the called method with the defined methods in the class. On success, the method is executed along with the parameters passed and the result is returned.&lt;br /&gt;
&lt;br /&gt;
If the object does not find a match in its method lookup, in normal circumstances the [http://www.ruby-doc.org/core-1.9.3/NoMethodError.html NoMethodError Exception] is raised .&lt;br /&gt;
&lt;br /&gt;
In cases where the user wants to handle the methods which are not defined but still called, “method_missing” can be defined and the user can handle the methods as he/she sees fit.&lt;br /&gt;
&lt;br /&gt;
=='''Format for defining method_missing'''==&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; def method_missing(m,*args,&amp;amp;block)&lt;br /&gt;
&lt;br /&gt;
(i) '''m-&amp;gt;''' accepts the symbol/name of the undefined method (ii) '''*args-&amp;gt;''' accepts the array of arguments passed in the method call  (iii) '''&amp;amp;block-&amp;gt;'''accepts a block passed to the method&lt;br /&gt;
&lt;br /&gt;
=='''Different types of methods'''==&lt;br /&gt;
When the object of a class receives a method name to be executed, the following steps are carried out for matching and executing the method:&lt;br /&gt;
&lt;br /&gt;
*First, the object looks in its own [http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html instance methods].&lt;br /&gt;
*Second, it looks in the list of instance methods that all objects of that class share.&lt;br /&gt;
*Third, in each of the included [http://www.tutorialspoint.com/ruby/ruby_modules.html modules] of that class, in reverse order of inclusion. &lt;br /&gt;
*Fourth, it looks in that class’s superclass. &lt;br /&gt;
*Fifth, in the superclass’s included modules, all the way up until it reaches the class Object. &lt;br /&gt;
*Sixth, if it still can’t find a method, the very last place it looks is in the [http://linux.die.net/lkmpg/x40.html Kernel module], included in the class Object. &lt;br /&gt;
*Finally, it calls method_missing (if defined in the class), else throws up the NOMethodError exception.&lt;br /&gt;
&lt;br /&gt;
This entire tracing that the object does is the method lookup path.&lt;br /&gt;
&lt;br /&gt;
=='''Examples'''==&lt;br /&gt;
===Calling defined and undefined methods===&lt;br /&gt;
&lt;br /&gt;
 class A		// creating a class 'A'&lt;br /&gt;
 def say		// defining a method 'say'&lt;br /&gt;
 puts &amp;quot; say Hi &amp;quot; // body of method say&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Creating the object of the class&lt;br /&gt;
 &lt;br /&gt;
  a=A.new	       // object of the class&lt;br /&gt;
  =&amp;gt; #&amp;lt;A:0x2a082e0&amp;gt;     //object id&lt;br /&gt;
&lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.say                  // defined method&lt;br /&gt;
 =&amp;gt; say Hi	       // returned result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.sayhi                // undefined method sayhi&lt;br /&gt;
 NoMethodError: undefined method `sayhi' for #&amp;lt;A:0x2a082e0&amp;gt;   // the NoMethodError is raised&lt;br /&gt;
&lt;br /&gt;
===method_missing implementation&amp;lt;ref&amp;gt;http://www.thirdbit.net/articles/2007/08/01/10-things-you-should-know-about-method_missing/&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def say&lt;br /&gt;
 puts &amp;quot; say hi &amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(m,*args,&amp;amp;block)	// defining method_missing&lt;br /&gt;
 puts &amp;quot; This method does not exist&amp;quot;	// body of method_missing&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Calling a method that is not defined&lt;br /&gt;
 &lt;br /&gt;
 a=A.new&lt;br /&gt;
 a.sayhi                                // calling the undefined method sayhi with no arguments&lt;br /&gt;
 =&amp;gt; This method does not exist		// this result returned when method_missing is executed&lt;br /&gt;
&lt;br /&gt;
When the object 'a' traces its method lookup path for a matching method as 'sayhi', upon failure it resorts to method_missing and the body of method_missing is executed. 'method_missing' is the last resort.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Sometimes when a class has many methods that do generally the same kinds of things, and the programmer is not sure in advance which methods the user will call since there are so many of them, and they are all so similar, writing code for all of them seems futile. In these situations method_missing can be defined to take care of different cases. The below 'Generic Handler' example implements this.&lt;br /&gt;
&lt;br /&gt;
===passing parameters to an undefined method call===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def add(a,b)&lt;br /&gt;
 a+b&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(name,*args,&amp;amp;block)    // the method_missing is defined and the *args parameter accepts all the parameters passed during 								                                 &lt;br /&gt;
                                             the method call   &lt;br /&gt;
 puts “You have typed the method name wrong and these were the parameters passed ; #{args[0]}, #{args[1]}”								&lt;br /&gt;
 end                         			&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The passed parameters are stored in the array 'args' and can be accessed like a normal array                &lt;br /&gt;
                                                   &lt;br /&gt;
 &lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.add(1,2)		        // calling the defined method add and passing the parameters (1,2)&lt;br /&gt;
 =&amp;gt; 3                           // result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.adds(4,2) 			// calling the undefined method adds and passing the parameter (4,2)&lt;br /&gt;
 =&amp;gt; You have typed the method name wrong and these were the parameters passed; 4, 2&lt;br /&gt;
&lt;br /&gt;
The user made a genuine mistake by typing 'adds', but this method is not defined. When the 'adds' method with parameters is called, the object 'a' tries to match the method in the method lookup path. Upon failure it invokes method_missing, the args are passed, stored in the array 'args' and the body of method_missing is executed.&lt;br /&gt;
&lt;br /&gt;
===converting numbers from roman representation to integer representation&amp;lt;ref&amp;gt;http://courses.ncsu.edu/csc517/common/lectures/notes/wk2.pdf&amp;lt;/ref&amp;gt;===&lt;br /&gt;
 class Roman&lt;br /&gt;
 DIGITS = {'I'=&amp;gt;1,'V'=&amp;gt;5,'X'=&amp;gt;10,'L'=&amp;gt;50,'C'=&amp;gt;100,'D'=&amp;gt;500,'M'=&amp;gt;1000,}&lt;br /&gt;
 def roman_to_integer(roman_string)&lt;br /&gt;
 last = nil&lt;br /&gt;
 roman_string.to_s.upcase.split(//).reverse.inject(0) do&lt;br /&gt;
 |memo, digit|&lt;br /&gt;
 if digit_value = DIGITS[digit]&lt;br /&gt;
 if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
 memo -= digit_value&lt;br /&gt;
 else&lt;br /&gt;
 memo += digit_value&lt;br /&gt;
 end&lt;br /&gt;
 last = digit_value&lt;br /&gt;
 end&lt;br /&gt;
 memo&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def method_missing(method)&lt;br /&gt;
 str=method.id2name&lt;br /&gt;
 roman_to_integer(str)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calling the undefined methods&lt;br /&gt;
&lt;br /&gt;
 r= Roman.new&lt;br /&gt;
 r.vii&lt;br /&gt;
 r.xxix&lt;br /&gt;
 r.xxiv&lt;br /&gt;
 r.xxvi&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The Output&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; 7&lt;br /&gt;
 =&amp;gt; 29&lt;br /&gt;
 =&amp;gt; 24&lt;br /&gt;
&lt;br /&gt;
===method_missing to log method calls&amp;lt;ref&amp;gt;http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2007/wiki1b_2_22&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Another application that makes use of method_missing could be a simple logger used for debugging purposes. Many times, it may be required to log the trace of called methods and provide information such as: called method-name, arguments, return type. It can be tedious to repeat this part of code in every method. A simple solution to this problem can be obtained using method_missing as:&lt;br /&gt;
&lt;br /&gt;
  class SimpleCallLogger&lt;br /&gt;
  def initialize(o)&lt;br /&gt;
  @obj = o&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(methodname, *args)&lt;br /&gt;
  puts &amp;quot;called: #{methodname}(#{args})&amp;quot;&lt;br /&gt;
  a = @obj.send(methodname, *args)&lt;br /&gt;
  puts &amp;quot;\t-&amp;gt; returned: #{a}&amp;quot;&lt;br /&gt;
  return a&lt;br /&gt;
  end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
This program makes use of method_missing in a way that it wraps around called method to output the logging information on entry and on exit, it logs the return type. Further, method_missing intercepts the method call and forward it to internal object with ‘send’ method of ruby. Hence, this use of method_missing acts as wrapper.&lt;br /&gt;
&lt;br /&gt;
===Generic Handler===&lt;br /&gt;
 class NoBar&lt;br /&gt;
 def method_missing(methodname, *args)&lt;br /&gt;
 define_method(:bar) if &amp;quot;bar&amp;quot; == methodname.to_s&lt;br /&gt;
 define_method(:nobar) if &amp;quot;nobar&amp;quot; == methodname.to_s&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This is an example of using method_missing as a generic handler to handle when a calling method is not exist. You can use missing_method to dynamically create a method at a runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Advantages of method_missing'''==&lt;br /&gt;
&lt;br /&gt;
*In addition to specifying the error messages for the undefined methods, method_missing provides a more dynamic behavior in the programming environment.&lt;br /&gt;
*If we are unfamiliar with the usage of the objects we created, then using method_missing is a good technique.&lt;br /&gt;
*Handles problems at runtime.&lt;br /&gt;
*Define's a generic method_missing and handle's any undefined method, a big advantage over Java. In Java, when you call an undefined method, the program will not compile.&lt;br /&gt;
*method_missing falls under the general technique of [http://en.wikipedia.org/wiki/Metaprogramming meta-programming]. Employ meta-programming in missing_function to write an another function to handle the call.&lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages of method_missing'''==	&lt;br /&gt;
*Slower than conventional method lookup. Simple tests indicate that method dispatch with method_missing is at least two to three times as expensive in time as conventional dispatch.&lt;br /&gt;
&lt;br /&gt;
*Since the methods being called never actually exist—they are just intercepted at the last step of the method lookup process—they cannot be documented or introspected as conventional methods can.&lt;br /&gt;
&lt;br /&gt;
*method_missing restricts compatibility with future versions of an [http://en.wikipedia.org/wiki/Application_programming_interface API]. Introducing new methods in a future API version can break users' expectations.&lt;br /&gt;
&lt;br /&gt;
=='''Key Points'''==&lt;br /&gt;
*Ruby knows method_missing( ) exists, because it's a private instance method of 'BasicObject' that every object inherits. The BasicObject#method_missing( ) responds by raising the NoMethodError. Overriding this method_missing( ) allows you to call methods that don't really exist. &lt;br /&gt;
&lt;br /&gt;
*If method_missing is only looking for certain method names, don't forget to call the [http://en.wikibooks.org/wiki/Java_Programming/Keywords/super super] keyword if you haven't found what you're looking for, so that the other superclass' method_missing can handle it.&lt;br /&gt;
&lt;br /&gt;
*[http://www.prateekdayal.net/2007/10/16/rubys-responds_to-for-checking-if-a-method-exists/ obj.respond_to?] function returns 'true' if the obj responds to the given method. So if you want to know whether your class will respond to a function you can use respond_to? to know the answer. But if method_missing() is used, the output may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
*Below class A defines only method method_missing() and no other method. When a new object of class A tries to access a method say 'foo', the respond_to? will return the value 'false'. When you actually try to implement it using “a.foo”, the code will get executed, courtesy of method_missing(). Even though the respond_to? says that you cannot access 'foo' method using object of class A, if you have method_missing() defined, you can access the method.&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In method_missing&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)&lt;br /&gt;
 a.foo&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 false&lt;br /&gt;
 In method_missing&lt;br /&gt;
&lt;br /&gt;
*If within method_missing() we define an undefined method. &lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 @@i = 0&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In Method Missing #{@@i}&amp;quot;&lt;br /&gt;
 @@i += 1&lt;br /&gt;
 self.fun&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)	// just checking whether the receiver 'a' responds to the method 'foo'&lt;br /&gt;
				  &lt;br /&gt;
 a.foo &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 The result is a 'stack level too deep' error. &lt;br /&gt;
&lt;br /&gt;
When the 'foo' method is called, after no method match the method_missing is run and this block has a method “self.fun” that is undefined. Here when the program execution encounters 'self.fun' it once again calls method_missing. This goes on in an endless loop till the stack memory is full.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
*http://www.rubyinside.com/ &lt;br /&gt;
*https://www.youtube.com/watch?v=SAEiCkixrdE&amp;amp;feature=relmfu&lt;br /&gt;
*http://blog.jayfields.com/2008/02/ruby-replace-methodmissing-with-dynamic.html &lt;br /&gt;
*http://liquiddevelopment.blogspot.com/2006/04/twisting-and-shaping-dsls-using-ruby.html &lt;br /&gt;
*http://blog.rubybestpractices.com/posts/gregory/031-issue-2-method-lookup.html&lt;br /&gt;
*http://phrogz.net/RubyLibs/RubyMethodLookupFlow.pdf&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65120</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w22 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65120"/>
		<updated>2012-09-15T02:51:38Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* Disadvantages of method_missing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''method_missing in Ruby:'''  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Introduction&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_method_missing.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
A method of a class is called by creating an object of the class and passing the method name to the object as a message. The object then looks up into its [http://www.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html method lookup path] and tries to match the called method with the defined methods in the class. On success, the method is executed along with the parameters passed and the result is returned.&lt;br /&gt;
&lt;br /&gt;
If the object does not find a match in its method lookup, in normal circumstances the [http://www.ruby-doc.org/core-1.9.3/NoMethodError.html NoMethodError Exception] is raised .&lt;br /&gt;
&lt;br /&gt;
In cases where the user wants to handle the methods which are not defined but still called, “method_missing” can be defined and the user can handle the methods as he/she sees fit.&lt;br /&gt;
&lt;br /&gt;
=='''Format for defining method_missing'''==&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; def method_missing(m,*args,&amp;amp;block)&lt;br /&gt;
&lt;br /&gt;
(i) '''m-&amp;gt;''' accepts the symbol/name of the undefined method (ii) '''*args-&amp;gt;''' accepts the array of arguments passed in the method call  (iii) '''&amp;amp;block-&amp;gt;'''accepts a block passed to the method&lt;br /&gt;
&lt;br /&gt;
=='''Different types of methods'''==&lt;br /&gt;
When the object of a class receives a method name to be executed, the following steps are carried out for matching and executing the method:&lt;br /&gt;
&lt;br /&gt;
*First, the object looks in its own [http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html instance methods].&lt;br /&gt;
*Second, it looks in the list of instance methods that all objects of that class share.&lt;br /&gt;
*Third, in each of the included [http://www.tutorialspoint.com/ruby/ruby_modules.html modules] of that class, in reverse order of inclusion. &lt;br /&gt;
*Fourth, it looks in that class’s superclass. &lt;br /&gt;
*Fifth, in the superclass’s included modules, all the way up until it reaches the class Object. &lt;br /&gt;
*Sixth, if it still can’t find a method, the very last place it looks is in the [http://linux.die.net/lkmpg/x40.html Kernel module], included in the class Object. &lt;br /&gt;
*Finally, it calls method_missing (if defined in the class), else throws up the NOMethodError exception.&lt;br /&gt;
&lt;br /&gt;
This entire tracing that the object does is the method lookup path.&lt;br /&gt;
&lt;br /&gt;
=='''Examples'''==&lt;br /&gt;
===Calling defined and undefined methods===&lt;br /&gt;
&lt;br /&gt;
 class A		// creating a class 'A'&lt;br /&gt;
 def say		// defining a method 'say'&lt;br /&gt;
 puts &amp;quot; say Hi &amp;quot; // body of method say&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Creating the object of the class&lt;br /&gt;
 &lt;br /&gt;
  a=A.new	       // object of the class&lt;br /&gt;
  =&amp;gt; #&amp;lt;A:0x2a082e0&amp;gt;     //object id&lt;br /&gt;
&lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.say                  // defined method&lt;br /&gt;
 =&amp;gt; say Hi	       // returned result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.sayhi                // undefined method sayhi&lt;br /&gt;
 NoMethodError: undefined method `sayhi' for #&amp;lt;A:0x2a082e0&amp;gt;   // the NoMethodError is raised&lt;br /&gt;
&lt;br /&gt;
===method_missing implementation&amp;lt;ref&amp;gt;http://www.thirdbit.net/articles/2007/08/01/10-things-you-should-know-about-method_missing/&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def say&lt;br /&gt;
 puts &amp;quot; say hi &amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(m,*args,&amp;amp;block)	// defining method_missing&lt;br /&gt;
 puts &amp;quot; This method does not exist&amp;quot;	// body of method_missing&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Calling a method that is not defined&lt;br /&gt;
 &lt;br /&gt;
 a=A.new&lt;br /&gt;
 a.sayhi                                // calling the undefined method sayhi with no arguments&lt;br /&gt;
 =&amp;gt; This method does not exist		// this result returned when method_missing is executed&lt;br /&gt;
&lt;br /&gt;
When the object 'a' traces its method lookup path for a matching method as 'sayhi', upon failure it resorts to method_missing and the body of method_missing is executed. 'method_missing' is the last resort.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Sometimes when a class has many methods that do generally the same kinds of things, and the programmer is not sure in advance which methods the user will call since there are so many of them, and they are all so similar, writing code for all of them seems futile. In these situations method_missing can be defined to take care of different cases. The below 'Generic Handler' example implements this.&lt;br /&gt;
&lt;br /&gt;
===passing parameters to an undefined method call===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def add(a,b)&lt;br /&gt;
 a+b&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(name,*args,&amp;amp;block)    // the method_missing is defined and the *args parameter accepts all the parameters passed during 								                                 &lt;br /&gt;
                                             the method call   &lt;br /&gt;
 puts “You have typed the method name wrong and these were the parameters passed ; #{args[0]}, #{args[1]}”								&lt;br /&gt;
 end                         			&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The passed parameters are stored in the array 'args' and can be accessed like a normal array                &lt;br /&gt;
                                                   &lt;br /&gt;
 &lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.add(1,2)		        // calling the defined method add and passing the parameters (1,2)&lt;br /&gt;
 =&amp;gt; 3                           // result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.adds(4,2) 			// calling the undefined method adds and passing the parameter (4,2)&lt;br /&gt;
 =&amp;gt; You have typed the method name wrong and these were the parameters passed; 4, 2&lt;br /&gt;
&lt;br /&gt;
The user made a genuine mistake by typing 'adds', but this method is not defined. When the 'adds' method with parameters is called, the object 'a' tries to match the method in the method lookup path. Upon failure it invokes method_missing, the args are passed, stored in the array 'args' and the body of method_missing is executed.&lt;br /&gt;
&lt;br /&gt;
===converting numbers from roman representation to integer representation&amp;lt;ref&amp;gt;http://courses.ncsu.edu/csc517/common/lectures/notes/wk2.pdf&amp;lt;/ref&amp;gt;===&lt;br /&gt;
 class Roman&lt;br /&gt;
 DIGITS = {'I'=&amp;gt;1,'V'=&amp;gt;5,'X'=&amp;gt;10,'L'=&amp;gt;50,'C'=&amp;gt;100,'D'=&amp;gt;500,'M'=&amp;gt;1000,}&lt;br /&gt;
 def roman_to_integer(roman_string)&lt;br /&gt;
 last = nil&lt;br /&gt;
 roman_string.to_s.upcase.split(//).reverse.inject(0) do&lt;br /&gt;
 |memo, digit|&lt;br /&gt;
 if digit_value = DIGITS[digit]&lt;br /&gt;
 if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
 memo -= digit_value&lt;br /&gt;
 else&lt;br /&gt;
 memo += digit_value&lt;br /&gt;
 end&lt;br /&gt;
 last = digit_value&lt;br /&gt;
 end&lt;br /&gt;
 memo&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def method_missing(method)&lt;br /&gt;
 str=method.id2name&lt;br /&gt;
 roman_to_integer(str)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calling the undefined methods&lt;br /&gt;
&lt;br /&gt;
 r= Roman.new&lt;br /&gt;
 r.vii&lt;br /&gt;
 r.xxix&lt;br /&gt;
 r.xxiv&lt;br /&gt;
 r.xxvi&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The Output&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; 7&lt;br /&gt;
 =&amp;gt; 29&lt;br /&gt;
 =&amp;gt; 24&lt;br /&gt;
&lt;br /&gt;
===method_missing to log method calls&amp;lt;ref&amp;gt;http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2007/wiki1b_2_22&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Another application that makes use of method_missing could be a simple logger used for debugging purposes. Many times, it may be required to log the trace of called methods and provide information such as: called method-name, arguments, return type. It can be tedious to repeat this part of code in every method. A simple solution to this problem can be obtained using method_missing as:&lt;br /&gt;
&lt;br /&gt;
  class SimpleCallLogger&lt;br /&gt;
  def initialize(o)&lt;br /&gt;
  @obj = o&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(methodname, *args)&lt;br /&gt;
  puts &amp;quot;called: #{methodname}(#{args})&amp;quot;&lt;br /&gt;
  a = @obj.send(methodname, *args)&lt;br /&gt;
  puts &amp;quot;\t-&amp;gt; returned: #{a}&amp;quot;&lt;br /&gt;
  return a&lt;br /&gt;
  end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
This program makes use of method_missing in a way that it wraps around called method to output the logging information on entry and on exit, it logs the return type. Further, method_missing intercepts the method call and forward it to internal object with ‘send’ method of ruby. Hence, this use of method_missing acts as wrapper.&lt;br /&gt;
&lt;br /&gt;
===Generic Handler===&lt;br /&gt;
 class NoBar&lt;br /&gt;
 def method_missing(methodname, *args)&lt;br /&gt;
 define_method(:bar) if &amp;quot;bar&amp;quot; == methodname.to_s&lt;br /&gt;
 define_method(:nobar) if &amp;quot;nobar&amp;quot; == methodname.to_s&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This is an example of using method_missing as a generic handler to handle when a calling method is not exist. You can use missing_method to dynamically create a method at a runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Advantages of method_missing'''==&lt;br /&gt;
&lt;br /&gt;
*In addition to specifying the error messages for the undefined methods, method_missing provides a more dynamic behavior in the programming environment.&lt;br /&gt;
*If we are unfamiliar with the usage of the objects we created, then using method_missing is a good technique.&lt;br /&gt;
*Handles problems at runtime.&lt;br /&gt;
*Define's a generic method_missing and handle's any undefined method, a big advantage over Java. In Java, when you call an undefined method, the program will not compile.&lt;br /&gt;
*method_missing falls under the general technique of [http://en.wikipedia.org/wiki/Metaprogramming meta-programming]. Employ meta-programming in missing_function to write an another function to handle the call.&lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages of method_missing'''==	&lt;br /&gt;
*Slower than conventional method lookup. Simple tests indicate that method dispatch with method_missing is at least two to three times as expensive in time as conventional dispatch.&lt;br /&gt;
&lt;br /&gt;
*Since the methods being called never actually exist—they are just intercepted at the last step of the method lookup process—they cannot be documented or introspected as conventional methods can.&lt;br /&gt;
&lt;br /&gt;
*method_missing restricts compatibility with future versions of an [http://en.wikipedia.org/wiki/Application_programming_interface API]. Introducing new methods in a future API version can break users' expectations.&lt;br /&gt;
&lt;br /&gt;
=='''Key Points'''==&lt;br /&gt;
*Ruby knows method_missing( ) exisits, because it's a private instance method of 'BasicObject' that every object inherits. The BasicObject#method_missing( ) responds by raising the NoMethodError. Overriding this method_missing( ) allows you to call methods that don't really exist. &lt;br /&gt;
&lt;br /&gt;
*If method_missing is only looking for certain method names, don't forget to call the [http://en.wikibooks.org/wiki/Java_Programming/Keywords/super super] keyword if you haven't found what you're looking for, so that the other superclass' method_missing can handle it.&lt;br /&gt;
&lt;br /&gt;
*[http://www.prateekdayal.net/2007/10/16/rubys-responds_to-for-checking-if-a-method-exists/ obj.respond_to?] function returns 'true' if the obj responds to the given method. So if you want to know whether your class will respond to a function you can use respond_to? to know the answer. But if method_missing() is used, the output may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
*Below class A defines only method method_missing() and no other method. When a new object of class A tries to access a method say 'foo', the respond_to? will return the value 'false'. When you actually try to implement it using “a.foo”, the code will get executed, courtesy of method_missing(). Even though the respond_to? says that you cannot access 'foo' method using object of class A, if you have method_missing() defined, you can access the method.&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In method_missing&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)&lt;br /&gt;
 a.foo&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 false&lt;br /&gt;
 In method_missing&lt;br /&gt;
&lt;br /&gt;
*If within method_missing() we define an undefined method. &lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 @@i = 0&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In Method Missing #{@@i}&amp;quot;&lt;br /&gt;
 @@i += 1&lt;br /&gt;
 self.fun&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)	// just checking whether the receiver 'a' responds to the method 'foo'&lt;br /&gt;
				  &lt;br /&gt;
 a.foo &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 The result is a 'stack level too deep' error. &lt;br /&gt;
&lt;br /&gt;
When the 'foo' method is called, after no method match the method_missing is run and this block has a method “self.fun” that is undefined. Here when the program execution encounters 'self.fun' it once again calls method_missing. This goes on in an endless loop till the stack memory is full.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
*http://www.rubyinside.com/ &lt;br /&gt;
*https://www.youtube.com/watch?v=SAEiCkixrdE&amp;amp;feature=relmfu&lt;br /&gt;
*http://blog.jayfields.com/2008/02/ruby-replace-methodmissing-with-dynamic.html &lt;br /&gt;
*http://liquiddevelopment.blogspot.com/2006/04/twisting-and-shaping-dsls-using-ruby.html &lt;br /&gt;
*http://blog.rubybestpractices.com/posts/gregory/031-issue-2-method-lookup.html&lt;br /&gt;
*http://phrogz.net/RubyLibs/RubyMethodLookupFlow.pdf&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=64325</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w22 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=64325"/>
		<updated>2012-09-14T12:27:07Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* Further Suggested Reading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''method_missing in Ruby:'''  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Introduction&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_method_missing.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
A method of a class is called by creating an object of the class and passing the method name to the object as a message. The object then looks up into its [http://www.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html method lookup path] and tries to match the called method with the defined methods in the class. On success, the method is executed along with the parameters passed and the result is returned.&lt;br /&gt;
&lt;br /&gt;
If the object does not find a match in its method lookup, in normal circumstances the [http://www.ruby-doc.org/core-1.9.3/NoMethodError.html NoMethodError Exception] is raised .&lt;br /&gt;
&lt;br /&gt;
“method_missing” is defined as a method in the class and is invoked if a called method is not found.&lt;br /&gt;
&lt;br /&gt;
=='''Format for defining method_missing'''==&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; def method_missing(m,*args,&amp;amp;block)&lt;br /&gt;
&lt;br /&gt;
(i) '''m-&amp;gt;''' accepts the symbol/name of the undefined method (ii) '''*args-&amp;gt;''' accepts the array of arguments passed in the method call  (iii) '''&amp;amp;block-&amp;gt;'''accepts a block passed to the method&lt;br /&gt;
&lt;br /&gt;
=='''Different types of methods'''==&lt;br /&gt;
The object of a class receives a method name to be executed, the following steps are carried out for matching and executing the method:&lt;br /&gt;
&lt;br /&gt;
*First, the object looks in its own [http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html instance methods].&lt;br /&gt;
*Second, it looks in the list of instance methods that all objects of that class share.&lt;br /&gt;
*Third, in each of the included [http://www.tutorialspoint.com/ruby/ruby_modules.html modules] of that class, in reverse order of inclusion. &lt;br /&gt;
*Fourth, it looks in that class’s superclass. &lt;br /&gt;
*Fifth, in the superclass’s included modules, all the way up until it reaches the class Object. &lt;br /&gt;
*Sixth, if it still can’t find a method, the very last place it looks is in the [http://linux.die.net/lkmpg/x40.html Kernel module], included in the class Object. &lt;br /&gt;
*Finally, it calls method_missing (if defined in the class), else throws up the NOMethodError exception.&lt;br /&gt;
&lt;br /&gt;
This entire tracing that the object does is the method lookup path.&lt;br /&gt;
&lt;br /&gt;
=='''Examples'''==&lt;br /&gt;
===Calling defined and undefined methods===&lt;br /&gt;
&lt;br /&gt;
 class A		// creating a class 'A'&lt;br /&gt;
 def say		// defining a method 'say'&lt;br /&gt;
 puts &amp;quot; say Hi &amp;quot; // body of method say&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Creating the object of the class&lt;br /&gt;
 &lt;br /&gt;
  a=A.new	       // object of the class&lt;br /&gt;
  =&amp;gt; #&amp;lt;A:0x2a082e0&amp;gt;     //object id&lt;br /&gt;
&lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.say                  // defined method&lt;br /&gt;
 =&amp;gt; say Hi	       // returned result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.sayhi                // undefined method sayhi&lt;br /&gt;
 NoMethodError: undefined method `sayhi' for #&amp;lt;A:0x2a082e0&amp;gt;   // the NoMethodError is raised&lt;br /&gt;
&lt;br /&gt;
===method_missing implementation&amp;lt;ref&amp;gt;http://www.thirdbit.net/articles/2007/08/01/10-things-you-should-know-about-method_missing/&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def say&lt;br /&gt;
 puts &amp;quot; say hi &amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(m,*args,&amp;amp;block)	// defining method_missing&lt;br /&gt;
 puts &amp;quot; This method does not exist&amp;quot;	// body of method_missing&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Calling a method that is not defined&lt;br /&gt;
 &lt;br /&gt;
 a=A.new&lt;br /&gt;
 a.sayhi                                // calling the undefined method sayhi with no arguments&lt;br /&gt;
 =&amp;gt; This method does not exist		// this result returned when method_missing is executed&lt;br /&gt;
&lt;br /&gt;
When the object 'a' traces its method lookup path for a matching method as 'sayhi', upon failure it resorts to method_missing and the body of method_missing is executed. 'method_missing' is the last resort.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Sometimes when a class has many methods that do generally the same kinds of things, and the programmer is not sure in advance which methods the user will call since there are so many of them, and they are all so similar, implementing all of them by hand seems futile. In these situations method_missing makes a new method that was previously not defined and adds it to the class. The below 'Generic Handler' example implements this.&lt;br /&gt;
&lt;br /&gt;
===passing parameters to an undefined method call===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def add(a,b)&lt;br /&gt;
 a+b&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(name,*args,&amp;amp;block)    // the method_missing is defined and the *args parameter accepts all the parameters passed during 								                                 &lt;br /&gt;
                                             the method call   &lt;br /&gt;
 puts “You have typed the method name wrong and these were the parameters passed ; #{args[0]}, #{args[1]}”								&lt;br /&gt;
 end                         			&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The passed parameters are stored in the array 'args' and can be accessed like a normal array                &lt;br /&gt;
                                                   &lt;br /&gt;
 &lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.add(1,2)		        // calling the defined method add and passing the parameters (1,2)&lt;br /&gt;
 =&amp;gt; 3                           // result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.adds(4,2) 			// calling the undefined method adds and passing the parameter (4,2)&lt;br /&gt;
 =&amp;gt; You have typed the method name wrong and these were the parameters passed; 4, 2&lt;br /&gt;
&lt;br /&gt;
The user made a genuine mistake by typing 'adds', but this method is not defined. When the 'adds' method with parameters is called, the object 'a' tries to match the method in the method lookup path. Upon failure it invokes method_missing, the args are passed, stored in the array 'args' and the body of method_missing is executed.&lt;br /&gt;
&lt;br /&gt;
===converting numbers from roman representation to integer representation&amp;lt;ref&amp;gt;http://courses.ncsu.edu/csc517/common/lectures/notes/wk2.pdf&amp;lt;/ref&amp;gt;===&lt;br /&gt;
 class Roman&lt;br /&gt;
 DIGITS = {'I'=&amp;gt;1,'V'=&amp;gt;5,'X'=&amp;gt;10,'L'=&amp;gt;50,'C'=&amp;gt;100,'D'=&amp;gt;500,'M'=&amp;gt;1000,}&lt;br /&gt;
 def roman_to_integer(roman_string)&lt;br /&gt;
 last = nil&lt;br /&gt;
 roman_string.to_s.upcase.split(//).reverse.inject(0) do&lt;br /&gt;
 |memo, digit|&lt;br /&gt;
 if digit_value = DIGITS[digit]&lt;br /&gt;
 if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
 memo -= digit_value&lt;br /&gt;
 else&lt;br /&gt;
 memo += digit_value&lt;br /&gt;
 end&lt;br /&gt;
 last = digit_value&lt;br /&gt;
 end&lt;br /&gt;
 memo&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def method_missing(method)&lt;br /&gt;
 str=method.id2name&lt;br /&gt;
 roman_to_integer(str)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calling the undefined methods&lt;br /&gt;
&lt;br /&gt;
 r= Roman.new&lt;br /&gt;
 r.vii&lt;br /&gt;
 r.xxix&lt;br /&gt;
 r.xxiv&lt;br /&gt;
 r.xxvi&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The Output&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; 7&lt;br /&gt;
 =&amp;gt; 29&lt;br /&gt;
 =&amp;gt; 24&lt;br /&gt;
&lt;br /&gt;
===method_missing to log method calls&amp;lt;ref&amp;gt;http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2007/wiki1b_2_22&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Another application that makes use of method_missing could be a simple logger used for debugging purposes. Many times, it may be required to log the trace of called methods and provide information such as: called method-name, arguments, return type. It can be tedious to repeat this part of code in every method. A simple solution to this problem can be obtained using method_missing as:&lt;br /&gt;
&lt;br /&gt;
  class SimpleCallLogger&lt;br /&gt;
  def initialize(o)&lt;br /&gt;
  @obj = o&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(methodname, *args)&lt;br /&gt;
  puts &amp;quot;called: #{methodname}(#{args})&amp;quot;&lt;br /&gt;
  a = @obj.send(methodname, *args)&lt;br /&gt;
  puts &amp;quot;\t-&amp;gt; returned: #{a}&amp;quot;&lt;br /&gt;
  return a&lt;br /&gt;
  end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
This program makes use of method_missing in a way that it wraps around called method to output the logging information on entry and on exit, it logs the return type. Further, method_missing intercepts the method call and forward it to internal object with ‘send’ method of ruby. Hence, this use of method_missing acts as wrapper.&lt;br /&gt;
&lt;br /&gt;
===Generic Handler===&lt;br /&gt;
 class NoBar&lt;br /&gt;
 def method_missing(methodname, *args)&lt;br /&gt;
 define_method(:bar) if &amp;quot;bar&amp;quot; == methodname.to_s&lt;br /&gt;
 define_method(:nobar) if &amp;quot;nobar&amp;quot; == methodname.to_s&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This is an example of using method_missing as a generic handler to handle when a calling method is not exist. You can use missing_method to dynamically create a method at a runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Advantages of method_missing'''==&lt;br /&gt;
&lt;br /&gt;
*In addition to specifying the error messages for the undefined methods, method_missing provides a more dynamic behavior in the programming environment.&lt;br /&gt;
*If we are unfamiliar with the usage of the objects we created, then using method_missing is a good technique.&lt;br /&gt;
*Handles problems at runtime.&lt;br /&gt;
*Define's a generic method_missing and handle's any undefined method, a big advantage over Java. In Java, when you call an undefined method, the program will not compile.&lt;br /&gt;
*method_missing falls under the general technique of [http://en.wikipedia.org/wiki/Metaprogramming meta-programming]. Employ meta-programming in missing_function to write an another function to handle the call.&lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages of method_missing'''==	&lt;br /&gt;
*Slower than conventional method lookup. Simple tests indicate that method dispatch with method_missing is at least two to three times as expensive in time as conventional dispatch.&lt;br /&gt;
&lt;br /&gt;
*Since the methods being called never actually exist—they are just intercepted at the last step of the method lookup process—they cannot be documented or introspected as conventional methods can.&lt;br /&gt;
&lt;br /&gt;
*[http://blog.jayfields.com/2008/02/ruby-dynamically-define-method.html Dynamic methods] must go through the method_missing method, the body of that method can become quite large if there are many different aspects of the code that needs to add methods dynamically.&lt;br /&gt;
&lt;br /&gt;
*method_missing restricts compatibility with future versions of an [http://en.wikipedia.org/wiki/Application_programming_interface API]. Introducing new methods in a future API version can break users' expectations.&lt;br /&gt;
&lt;br /&gt;
=='''Key Points'''==&lt;br /&gt;
*Ruby knows method_missing( ) exisits, because it's a private instance method of 'BasicObject' that every object inherits. The BasicObject#method_missing( ) responds by raising the NoMethodError. Overriding this method_missing( ) allows you to call methods that don't really exist. &lt;br /&gt;
&lt;br /&gt;
*If method_missing is only looking for certain method names, don't forget to call the [http://en.wikibooks.org/wiki/Java_Programming/Keywords/super super] keyword if you haven't found what you're looking for, so that the other superclass' method_missing can handle it.&lt;br /&gt;
&lt;br /&gt;
*[http://www.prateekdayal.net/2007/10/16/rubys-responds_to-for-checking-if-a-method-exists/ obj.respond_to?] function returns 'true' if the obj responds to the given method. So if you want to know whether your class will respond to a function you can use respond_to? to know the answer. But if method_missing() is used, the output may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
*Below class A defines only method method_missing() and no other method. When a new object of class A tries to access a method say 'foo', the respond_to? will return the value 'false'. When you actually try to implement it using “a.foo”, the code will get executed, courtesy of method_missing(). Even though the respond_to? says that you cannot access 'foo' method using object of class A, if you have method_missing() defined, you can access the method.&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In method_missing&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)&lt;br /&gt;
 a.foo&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 false&lt;br /&gt;
 In method_missing&lt;br /&gt;
&lt;br /&gt;
*If within method_missing() we define an undefined method. &lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 @@i = 0&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In Method Missing #{@@i}&amp;quot;&lt;br /&gt;
 @@i += 1&lt;br /&gt;
 self.fun&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)	// just checking whether the receiver 'a' responds to the method 'foo'&lt;br /&gt;
				  &lt;br /&gt;
 a.foo &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 The result was a 'stack level too deep' error. &lt;br /&gt;
&lt;br /&gt;
When the 'foo' method is called, after no method match the method_missing is run and this block has a method “self.fun” that is undefined. Here when the program execution encounters 'self.fun' it once again calls method_missing. This goes on in an endless loop till the stack memory is full.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
*http://www.rubyinside.com/ &lt;br /&gt;
*https://www.youtube.com/watch?v=SAEiCkixrdE&amp;amp;feature=relmfu&lt;br /&gt;
*http://blog.jayfields.com/2008/02/ruby-replace-methodmissing-with-dynamic.html &lt;br /&gt;
*http://liquiddevelopment.blogspot.com/2006/04/twisting-and-shaping-dsls-using-ruby.html &lt;br /&gt;
*http://blog.rubybestpractices.com/posts/gregory/031-issue-2-method-lookup.html&lt;br /&gt;
*http://phrogz.net/RubyLibs/RubyMethodLookupFlow.pdf&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=64273</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w22 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=64273"/>
		<updated>2012-09-14T04:22:42Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* Key Points */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''method_missing in Ruby:'''  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Introduction&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_method_missing.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
A method of a class is called by creating an object of the class and passing the method name to the object as a message. The object then looks up into its [http://www.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html method lookup path] and tries to match the called method with the defined methods in the class. On success, the method is executed along with the parameters passed and the result is returned.&lt;br /&gt;
&lt;br /&gt;
If the object does not find a match in its method lookup, in normal circumstances the [http://www.ruby-doc.org/core-1.9.3/NoMethodError.html NoMethodError Exception] is raised .&lt;br /&gt;
&lt;br /&gt;
“method_missing” is defined as a method in the class and is invoked if a called method is not found.&lt;br /&gt;
&lt;br /&gt;
=='''Format for defining method_missing'''==&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; def method_missing(m,*args,&amp;amp;block)&lt;br /&gt;
&lt;br /&gt;
(i) '''m-&amp;gt;''' accepts the symbol/name of the undefined method (ii) '''*args-&amp;gt;''' accepts the array of arguments passed in the method call  (iii) '''&amp;amp;block-&amp;gt;'''accepts a block passed to the method&lt;br /&gt;
&lt;br /&gt;
=='''Different types of methods'''==&lt;br /&gt;
The object of a class receives a method name to be executed, the following steps are carried out for matching and executing the method:&lt;br /&gt;
&lt;br /&gt;
*First, the object looks in its own [http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html instance methods].&lt;br /&gt;
*Second, it looks in the list of instance methods that all objects of that class share.&lt;br /&gt;
*Third, in each of the included [http://www.tutorialspoint.com/ruby/ruby_modules.html modules] of that class, in reverse order of inclusion. &lt;br /&gt;
*Fourth, it looks in that class’s superclass. &lt;br /&gt;
*Fifth, in the superclass’s included modules, all the way up until it reaches the class Object. &lt;br /&gt;
*Sixth, if it still can’t find a method, the very last place it looks is in the [http://linux.die.net/lkmpg/x40.html Kernel module], included in the class Object. &lt;br /&gt;
*Finally, it calls method_missing (if defined in the class), else throws up the NOMethodError exception.&lt;br /&gt;
&lt;br /&gt;
This entire tracing that the object does is the method lookup path.&lt;br /&gt;
&lt;br /&gt;
=='''Examples'''==&lt;br /&gt;
===Calling defined and undefined methods===&lt;br /&gt;
&lt;br /&gt;
 class A		// creating a class 'A'&lt;br /&gt;
 def say		// defining a method 'say'&lt;br /&gt;
 puts &amp;quot; say Hi &amp;quot; // body of method say&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Creating the object of the class&lt;br /&gt;
 &lt;br /&gt;
  a=A.new	       // object of the class&lt;br /&gt;
  =&amp;gt; #&amp;lt;A:0x2a082e0&amp;gt;     //object id&lt;br /&gt;
&lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.say                  // defined method&lt;br /&gt;
 =&amp;gt; say Hi	       // returned result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.sayhi                // undefined method sayhi&lt;br /&gt;
 NoMethodError: undefined method `sayhi' for #&amp;lt;A:0x2a082e0&amp;gt;   // the NoMethodError is raised&lt;br /&gt;
&lt;br /&gt;
===method_missing implementation&amp;lt;ref&amp;gt;http://www.thirdbit.net/articles/2007/08/01/10-things-you-should-know-about-method_missing/&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def say&lt;br /&gt;
 puts &amp;quot; say hi &amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(m,*args,&amp;amp;block)	// defining method_missing&lt;br /&gt;
 puts &amp;quot; This method does not exist&amp;quot;	// body of method_missing&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Calling a method that is not defined&lt;br /&gt;
 &lt;br /&gt;
 a=A.new&lt;br /&gt;
 a.sayhi                                // calling the undefined method sayhi with no arguments&lt;br /&gt;
 =&amp;gt; This method does not exist		// this result returned when method_missing is executed&lt;br /&gt;
&lt;br /&gt;
When the object 'a' traces its method lookup path for a matching method as 'sayhi', upon failure it resorts to method_missing and the body of method_missing is executed. 'method_missing' is the last resort.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Sometimes when a class has many methods that do generally the same kinds of things, and the programmer is not sure in advance which methods the user will call since there are so many of them, and they are all so similar, implementing all of them by hand seems futile. In these situations method_missing makes a new method that was previously not defined and adds it to the class. The below 'Generic Handler' example implements this.&lt;br /&gt;
&lt;br /&gt;
===passing parameters to an undefined method call===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def add(a,b)&lt;br /&gt;
 a+b&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(name,*args,&amp;amp;block)    // the method_missing is defined and the *args parameter accepts all the parameters passed during 								                                 &lt;br /&gt;
                                             the method call   &lt;br /&gt;
 puts “You have typed the method name wrong and these were the parameters passed ; #{args[0]}, #{args[1]}”								&lt;br /&gt;
 end                         			&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The passed parameters are stored in the array 'args' and can be accessed like a normal array                &lt;br /&gt;
                                                   &lt;br /&gt;
 &lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.add(1,2)		        // calling the defined method add and passing the parameters (1,2)&lt;br /&gt;
 =&amp;gt; 3                           // result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.adds(4,2) 			// calling the undefined method adds and passing the parameter (4,2)&lt;br /&gt;
 =&amp;gt; You have typed the method name wrong and these were the parameters passed; 4, 2&lt;br /&gt;
&lt;br /&gt;
The user made a genuine mistake by typing 'adds', but this method is not defined. When the 'adds' method with parameters is called, the object 'a' tries to match the method in the method lookup path. Upon failure it invokes method_missing, the args are passed, stored in the array 'args' and the body of method_missing is executed.&lt;br /&gt;
&lt;br /&gt;
===converting numbers from roman representation to integer representation&amp;lt;ref&amp;gt;http://courses.ncsu.edu/csc517/common/lectures/notes/wk2.pdf&amp;lt;/ref&amp;gt;===&lt;br /&gt;
 class Roman&lt;br /&gt;
 DIGITS = {'I'=&amp;gt;1,'V'=&amp;gt;5,'X'=&amp;gt;10,'L'=&amp;gt;50,'C'=&amp;gt;100,'D'=&amp;gt;500,'M'=&amp;gt;1000,}&lt;br /&gt;
 def roman_to_integer(roman_string)&lt;br /&gt;
 last = nil&lt;br /&gt;
 roman_string.to_s.upcase.split(//).reverse.inject(0) do&lt;br /&gt;
 |memo, digit|&lt;br /&gt;
 if digit_value = DIGITS[digit]&lt;br /&gt;
 if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
 memo -= digit_value&lt;br /&gt;
 else&lt;br /&gt;
 memo += digit_value&lt;br /&gt;
 end&lt;br /&gt;
 last = digit_value&lt;br /&gt;
 end&lt;br /&gt;
 memo&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def method_missing(method)&lt;br /&gt;
 str=method.id2name&lt;br /&gt;
 roman_to_integer(str)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calling the undefined methods&lt;br /&gt;
&lt;br /&gt;
 r= Roman.new&lt;br /&gt;
 r.vii&lt;br /&gt;
 r.xxix&lt;br /&gt;
 r.xxiv&lt;br /&gt;
 r.xxvi&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The Output&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; 7&lt;br /&gt;
 =&amp;gt; 29&lt;br /&gt;
 =&amp;gt; 24&lt;br /&gt;
&lt;br /&gt;
===method_missing to log method calls&amp;lt;ref&amp;gt;http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2007/wiki1b_2_22&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Another application that makes use of method_missing could be a simple logger used for debugging purposes. Many times, it may be required to log the trace of called methods and provide information such as: called method-name, arguments, return type. It can be tedious to repeat this part of code in every method. A simple solution to this problem can be obtained using method_missing as:&lt;br /&gt;
&lt;br /&gt;
  class SimpleCallLogger&lt;br /&gt;
  def initialize(o)&lt;br /&gt;
  @obj = o&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(methodname, *args)&lt;br /&gt;
  puts &amp;quot;called: #{methodname}(#{args})&amp;quot;&lt;br /&gt;
  a = @obj.send(methodname, *args)&lt;br /&gt;
  puts &amp;quot;\t-&amp;gt; returned: #{a}&amp;quot;&lt;br /&gt;
  return a&lt;br /&gt;
  end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
This program makes use of method_missing in a way that it wraps around called method to output the logging information on entry and on exit, it logs the return type. Further, method_missing intercepts the method call and forward it to internal object with ‘send’ method of ruby. Hence, this use of method_missing acts as wrapper.&lt;br /&gt;
&lt;br /&gt;
===Generic Handler===&lt;br /&gt;
 class NoBar&lt;br /&gt;
 def method_missing(methodname, *args)&lt;br /&gt;
 define_method(:bar) if &amp;quot;bar&amp;quot; == methodname.to_s&lt;br /&gt;
 define_method(:nobar) if &amp;quot;nobar&amp;quot; == methodname.to_s&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This is an example of using method_missing as a generic handler to handle when a calling method is not exist. You can use missing_method to dynamically create a method at a runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Advantages of method_missing'''==&lt;br /&gt;
&lt;br /&gt;
*In addition to specifying the error messages for the undefined methods, method_missing provides a more dynamic behavior in the programming environment.&lt;br /&gt;
*If we are unfamiliar with the usage of the objects we created, then using method_missing is a good technique.&lt;br /&gt;
*Handles problems at runtime.&lt;br /&gt;
*Define's a generic method_missing and handle's any undefined method, a big advantage over Java. In Java, when you call an undefined method, the program will not compile.&lt;br /&gt;
*method_missing falls under the general technique of [http://en.wikipedia.org/wiki/Metaprogramming meta-programming]. Employ meta-programming in missing_function to write an another function to handle the call.&lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages of method_missing'''==	&lt;br /&gt;
*Slower than conventional method lookup. Simple tests indicate that method dispatch with method_missing is at least two to three times as expensive in time as conventional dispatch.&lt;br /&gt;
&lt;br /&gt;
*Since the methods being called never actually exist—they are just intercepted at the last step of the method lookup process—they cannot be documented or introspected as conventional methods can.&lt;br /&gt;
&lt;br /&gt;
*[http://blog.jayfields.com/2008/02/ruby-dynamically-define-method.html Dynamic methods] must go through the method_missing method, the body of that method can become quite large if there are many different aspects of the code that needs to add methods dynamically.&lt;br /&gt;
&lt;br /&gt;
*method_missing restricts compatibility with future versions of an [http://en.wikipedia.org/wiki/Application_programming_interface API]. Introducing new methods in a future API version can break users' expectations.&lt;br /&gt;
&lt;br /&gt;
=='''Key Points'''==&lt;br /&gt;
*Ruby knows method_missing( ) exisits, because it's a private instance method of 'BasicObject' that every object inherits. The BasicObject#method_missing( ) responds by raising the NoMethodError. Overriding this method_missing( ) allows you to call methods that don't really exist. &lt;br /&gt;
&lt;br /&gt;
*If method_missing is only looking for certain method names, don't forget to call the [http://en.wikibooks.org/wiki/Java_Programming/Keywords/super super] keyword if you haven't found what you're looking for, so that the other superclass' method_missing can handle it.&lt;br /&gt;
&lt;br /&gt;
*[http://www.prateekdayal.net/2007/10/16/rubys-responds_to-for-checking-if-a-method-exists/ obj.respond_to?] function returns 'true' if the obj responds to the given method. So if you want to know whether your class will respond to a function you can use respond_to? to know the answer. But if method_missing() is used, the output may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
*Below class A defines only method method_missing() and no other method. When a new object of class A tries to access a method say 'foo', the respond_to? will return the value 'false'. When you actually try to implement it using “a.foo”, the code will get executed, courtesy of method_missing(). Even though the respond_to? says that you cannot access 'foo' method using object of class A, if you have method_missing() defined, you can access the method.&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In method_missing&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)&lt;br /&gt;
 a.foo&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 false&lt;br /&gt;
 In method_missing&lt;br /&gt;
&lt;br /&gt;
*If within method_missing() we define an undefined method. &lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 @@i = 0&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In Method Missing #{@@i}&amp;quot;&lt;br /&gt;
 @@i += 1&lt;br /&gt;
 self.fun&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)	// just checking whether the receiver 'a' responds to the method 'foo'&lt;br /&gt;
				  &lt;br /&gt;
 a.foo &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 The result was a 'stack level too deep' error. &lt;br /&gt;
&lt;br /&gt;
When the 'foo' method is called, after no method match the method_missing is run and this block has a method “self.fun” that is undefined. Here when the program execution encounters 'self.fun' it once again calls method_missing. This goes on in an endless loop till the stack memory is full.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
*http://www.rubyinside.com/ &lt;br /&gt;
*http://blog.jayfields.com/2008/02/ruby-replace-methodmissing-with-dynamic.html &lt;br /&gt;
*http://liquiddevelopment.blogspot.com/2006/04/twisting-and-shaping-dsls-using-ruby.html &lt;br /&gt;
*http://blog.rubybestpractices.com/posts/gregory/031-issue-2-method-lookup.html&lt;br /&gt;
*http://phrogz.net/RubyLibs/RubyMethodLookupFlow.pdf&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=64060</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w22 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=64060"/>
		<updated>2012-09-13T17:00:38Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* converting numbers from roman representation to integer representationhttp://courses.ncsu.edu/csc517/common/lectures/notes/wk2.pdf */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''method_missing in Ruby:'''  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Introduction&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_method_missing.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
A method of a class is called by creating an object of the class and passing the method name to the object as a message. The object then looks up into its [http://www.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html method lookup path] and tries to match the called method with the defined methods in the class. On success, the method is executed along with the parameters passed and the result is returned.&lt;br /&gt;
&lt;br /&gt;
If the object does not find a match in its method lookup, in normal circumstances the [http://www.ruby-doc.org/core-1.9.3/NoMethodError.html NoMethodError Exception] is raised .&lt;br /&gt;
&lt;br /&gt;
“method_missing” is defined as a method in the class and is invoked if a called method is not found.&lt;br /&gt;
&lt;br /&gt;
=='''Format for defining method_missing'''==&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; def method_missing(m,*args,&amp;amp;block)&lt;br /&gt;
&lt;br /&gt;
(i) '''m-&amp;gt;''' accepts the symbol/name of the undefined method (ii) '''*args-&amp;gt;''' accepts the array of arguments passed in the method call  (iii) '''&amp;amp;block-&amp;gt;'''accepts a block passed to the method&lt;br /&gt;
&lt;br /&gt;
=='''Different types of methods'''==&lt;br /&gt;
The object of a class receives a method name to be executed, the following steps are carried out for matching and executing the method:&lt;br /&gt;
&lt;br /&gt;
*First, the object looks in its own [http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html instance methods].&lt;br /&gt;
*Second, it looks in the list of instance methods that all objects of that class share.&lt;br /&gt;
*Third, in each of the included [http://www.tutorialspoint.com/ruby/ruby_modules.html modules] of that class, in reverse order of inclusion. &lt;br /&gt;
*Fourth, it looks in that class’s superclass. &lt;br /&gt;
*Fifth, in the superclass’s included modules, all the way up until it reaches the class Object. &lt;br /&gt;
*Sixth, if it still can’t find a method, the very last place it looks is in the [http://linux.die.net/lkmpg/x40.html Kernel module], included in the class Object. &lt;br /&gt;
*Finally, it calls method_missing (if defined in the class), else throws up the NOMethodError exception.&lt;br /&gt;
&lt;br /&gt;
This entire tracing that the object does is the method lookup path.&lt;br /&gt;
&lt;br /&gt;
=='''Examples'''==&lt;br /&gt;
===Calling defined and undefined methods===&lt;br /&gt;
&lt;br /&gt;
 class A		// creating a class 'A'&lt;br /&gt;
 def say		// defining a method 'say'&lt;br /&gt;
 puts &amp;quot; say Hi &amp;quot; // body of method say&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Creating the object of the class&lt;br /&gt;
 &lt;br /&gt;
  a=A.new	       // object of the class&lt;br /&gt;
  =&amp;gt; #&amp;lt;A:0x2a082e0&amp;gt;     //object id&lt;br /&gt;
&lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.say                  // defined method&lt;br /&gt;
 =&amp;gt; say Hi	       // returned result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.sayhi                // undefined method sayhi&lt;br /&gt;
 NoMethodError: undefined method `sayhi' for #&amp;lt;A:0x2a082e0&amp;gt;   // the NoMethodError is raised&lt;br /&gt;
&lt;br /&gt;
===method_missing implementation&amp;lt;ref&amp;gt;http://www.thirdbit.net/articles/2007/08/01/10-things-you-should-know-about-method_missing/&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def say&lt;br /&gt;
 puts &amp;quot; say hi &amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(m,*args,&amp;amp;block)	// defining method_missing&lt;br /&gt;
 puts &amp;quot; This method does not exist&amp;quot;	// body of method_missing&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Calling a method that is not defined&lt;br /&gt;
 &lt;br /&gt;
 a=A.new&lt;br /&gt;
 a.sayhi                                // calling the undefined method sayhi with no arguments&lt;br /&gt;
 =&amp;gt; This method does not exist		// this result returned when method_missing is executed&lt;br /&gt;
&lt;br /&gt;
When the object 'a' traces its method lookup path for a matching method as 'sayhi', upon failure it resorts to method_missing and the body of method_missing is executed. 'method_missing' is the last resort.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Sometimes when a class has many methods that do generally the same kinds of things, and the programmer is not sure in advance which methods the user will call since there are so many of them, and they are all so similar, implementing all of them by hand seems futile. In these situations method_missing makes a new method that was previously not defined and adds it to the class. The below 'Generic Handler' example implements this.&lt;br /&gt;
&lt;br /&gt;
===passing parameters to an undefined method call===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def add(a,b)&lt;br /&gt;
 a+b&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(name,*args,&amp;amp;block)    // the method_missing is defined and the *args parameter accepts all the parameters passed during 								                                 &lt;br /&gt;
                                             the method call   &lt;br /&gt;
 puts “You have typed the method name wrong and these were the parameters passed ; #{args[0]}, #{args[1]}”								&lt;br /&gt;
 end                         			&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The passed parameters are stored in the array 'args' and can be accessed like a normal array                &lt;br /&gt;
                                                   &lt;br /&gt;
 &lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.add(1,2)		        // calling the defined method add and passing the parameters (1,2)&lt;br /&gt;
 =&amp;gt; 3                           // result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.adds(4,2) 			// calling the undefined method adds and passing the parameter (4,2)&lt;br /&gt;
 =&amp;gt; You have typed the method name wrong and these were the parameters passed; 4, 2&lt;br /&gt;
&lt;br /&gt;
The user made a genuine mistake by typing 'adds', but this method is not defined. When the 'adds' method with parameters is called, the object 'a' tries to match the method in the method lookup path. Upon failure it invokes method_missing, the args are passed, stored in the array 'args' and the body of method_missing is executed.&lt;br /&gt;
&lt;br /&gt;
===converting numbers from roman representation to integer representation&amp;lt;ref&amp;gt;http://courses.ncsu.edu/csc517/common/lectures/notes/wk2.pdf&amp;lt;/ref&amp;gt;===&lt;br /&gt;
 class Roman&lt;br /&gt;
 DIGITS = {'I'=&amp;gt;1,'V'=&amp;gt;5,'X'=&amp;gt;10,'L'=&amp;gt;50,'C'=&amp;gt;100,'D'=&amp;gt;500,'M'=&amp;gt;1000,}&lt;br /&gt;
 def roman_to_integer(roman_string)&lt;br /&gt;
 last = nil&lt;br /&gt;
 roman_string.to_s.upcase.split(//).reverse.inject(0) do&lt;br /&gt;
 |memo, digit|&lt;br /&gt;
 if digit_value = DIGITS[digit]&lt;br /&gt;
 if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
 memo -= digit_value&lt;br /&gt;
 else&lt;br /&gt;
 memo += digit_value&lt;br /&gt;
 end&lt;br /&gt;
 last = digit_value&lt;br /&gt;
 end&lt;br /&gt;
 memo&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def method_missing(method)&lt;br /&gt;
 str=method.id2name&lt;br /&gt;
 roman_to_integer(str)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calling the undefined methods&lt;br /&gt;
&lt;br /&gt;
 r= Roman.new&lt;br /&gt;
 r.vii&lt;br /&gt;
 r.xxix&lt;br /&gt;
 r.xxiv&lt;br /&gt;
 r.xxvi&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The Output&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; 7&lt;br /&gt;
 =&amp;gt; 29&lt;br /&gt;
 =&amp;gt; 24&lt;br /&gt;
&lt;br /&gt;
===method_missing to log method calls&amp;lt;ref&amp;gt;http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2007/wiki1b_2_22&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Another application that makes use of method_missing could be a simple logger used for debugging purposes. Many times, it may be required to log the trace of called methods and provide information such as: called method-name, arguments, return type. It can be tedious to repeat this part of code in every method. A simple solution to this problem can be obtained using method_missing as:&lt;br /&gt;
&lt;br /&gt;
  class SimpleCallLogger&lt;br /&gt;
  def initialize(o)&lt;br /&gt;
  @obj = o&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(methodname, *args)&lt;br /&gt;
  puts &amp;quot;called: #{methodname}(#{args})&amp;quot;&lt;br /&gt;
  a = @obj.send(methodname, *args)&lt;br /&gt;
  puts &amp;quot;\t-&amp;gt; returned: #{a}&amp;quot;&lt;br /&gt;
  return a&lt;br /&gt;
  end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
This program makes use of method_missing in a way that it wraps around called method to output the logging information on entry and on exit, it logs the return type. Further, method_missing intercepts the method call and forward it to internal object with ‘send’ method of ruby. Hence, this use of method_missing acts as wrapper.&lt;br /&gt;
&lt;br /&gt;
===Generic Handler===&lt;br /&gt;
 class NoBar&lt;br /&gt;
 def method_missing(methodname, *args)&lt;br /&gt;
 define_method(:bar) if &amp;quot;bar&amp;quot; == methodname.to_s&lt;br /&gt;
 define_method(:nobar) if &amp;quot;nobar&amp;quot; == methodname.to_s&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This is an example of using method_missing as a generic handler to handle when a calling method is not exist. You can use missing_method to dynamically create a method at a runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Advantages of method_missing'''==&lt;br /&gt;
&lt;br /&gt;
*In addition to specifying the error messages for the undefined methods, method_missing provides a more dynamic behavior in the programming environment.&lt;br /&gt;
*If we are unfamiliar with the usage of the objects we created, then using method_missing is a good technique.&lt;br /&gt;
*Handles problems at runtime.&lt;br /&gt;
*Define's a generic method_missing and handle's any undefined method, a big advantage over Java. In Java, when you call an undefined method, the program will not compile.&lt;br /&gt;
*method_missing falls under the general technique of [http://en.wikipedia.org/wiki/Metaprogramming meta-programming]. Employ meta-programming in missing_function to write an another function to handle the call.&lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages of method_missing'''==	&lt;br /&gt;
*Slower than conventional method lookup. Simple tests indicate that method dispatch with method_missing is at least two to three times as expensive in time as conventional dispatch.&lt;br /&gt;
&lt;br /&gt;
*Since the methods being called never actually exist—they are just intercepted at the last step of the method lookup process—they cannot be documented or introspected as conventional methods can.&lt;br /&gt;
&lt;br /&gt;
*[http://blog.jayfields.com/2008/02/ruby-dynamically-define-method.html Dynamic methods] must go through the method_missing method, the body of that method can become quite large if there are many different aspects of the code that needs to add methods dynamically.&lt;br /&gt;
&lt;br /&gt;
*method_missing restricts compatibility with future versions of an [http://en.wikipedia.org/wiki/Application_programming_interface API]. Introducing new methods in a future API version can break users' expectations.&lt;br /&gt;
&lt;br /&gt;
=='''Key Points'''==&lt;br /&gt;
*Ruby knows method_missing( ) exisits, because it's a private instance method of 'BasicObject' that every object inherits. The BasicObject#method_missing( ) responds by raising the NoMethodError. Overriding this method_missing( ) allows you to call methods that don't really exist. &lt;br /&gt;
&lt;br /&gt;
*If method_missing is only looking for certain method names, don't forget to call the [http://en.wikibooks.org/wiki/Java_Programming/Keywords/super super] keyword if you haven't found what you're looking for, so that the other superclass' method_missing can handle it.&lt;br /&gt;
&lt;br /&gt;
*[http://www.prateekdayal.net/2007/10/16/rubys-responds_to-for-checking-if-a-method-exists/ obj.respond_to?] function returns 'true' if the obj responds to the given method. So if you want to know whether your class will respond to a function you can use respond_to? to know the answer. But if method_missing() is used, the output may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
*Below class A defines only method method_missing() and no other method. When a new object of class A tries to access a method say 'foo', the respond_to? will return the value 'false'. When you actually try to implement it using “a.foo”, the code will get executed, courtesy of method_missing(). Even though the respond_to? says that you cannot access 'foo' method using object of class A, if you have method_missing() defined, you can access the method.&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In method_missing&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)&lt;br /&gt;
 a.foo&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 false&lt;br /&gt;
 In method_missing&lt;br /&gt;
&lt;br /&gt;
*If within method_missing() we define an undefined method. &lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 @@i = 0&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In Method Missing #{@@i}&amp;quot;&lt;br /&gt;
 @@i += 1&lt;br /&gt;
 self.fun&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)	// just checking whether the receiver 'a' responds to the method 'foo'&lt;br /&gt;
				  &lt;br /&gt;
 a.foo &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 The expected result would be a 'stack level too deep' error. &lt;br /&gt;
&lt;br /&gt;
When the 'foo' method is called, after no method match the method_missing is run and this block has a method “self.fun” that is undefined. Here when the program execution encounters 'self.fun' it once again calls method_missing. This goes on in an endless loop till the stack memory is full.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
*http://www.rubyinside.com/ &lt;br /&gt;
*http://blog.jayfields.com/2008/02/ruby-replace-methodmissing-with-dynamic.html &lt;br /&gt;
*http://liquiddevelopment.blogspot.com/2006/04/twisting-and-shaping-dsls-using-ruby.html &lt;br /&gt;
*http://blog.rubybestpractices.com/posts/gregory/031-issue-2-method-lookup.html&lt;br /&gt;
*http://phrogz.net/RubyLibs/RubyMethodLookupFlow.pdf&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=64025</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w22 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=64025"/>
		<updated>2012-09-13T08:39:29Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* converting numbers from roman representation to integer representationhttp://www.rubyquiz.com/quiz22.html */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''method_missing in Ruby:'''  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Introduction&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_method_missing.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
A method of a class is called by creating an object of the class and passing the method name to the object as a message. The object then looks up into its [http://www.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html method lookup path] and tries to match the called method with the defined methods in the class. On success, the method is executed along with the parameters passed and the result is returned.&lt;br /&gt;
&lt;br /&gt;
If the object does not find a match in its method lookup, in normal circumstances the [http://www.ruby-doc.org/core-1.9.3/NoMethodError.html NoMethodError Exception] is raised .&lt;br /&gt;
&lt;br /&gt;
“method_missing” is defined as a method in the class and is invoked if a called method is not found.&lt;br /&gt;
&lt;br /&gt;
=='''Format for defining method_missing'''==&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; def method_missing(m,*args,&amp;amp;block)&lt;br /&gt;
&lt;br /&gt;
(i) '''m-&amp;gt;''' accepts the symbol/name of the undefined method (ii) '''*args-&amp;gt;''' accepts the array of arguments passed in the method call  (iii) '''&amp;amp;block-&amp;gt;'''accepts a block passed to the method&lt;br /&gt;
&lt;br /&gt;
=='''Different types of methods'''==&lt;br /&gt;
The object of a class receives a method name to be executed, the following steps are carried out for matching and executing the method:&lt;br /&gt;
&lt;br /&gt;
*First, the object looks in its own [http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html instance methods].&lt;br /&gt;
*Second, it looks in the list of instance methods that all objects of that class share.&lt;br /&gt;
*Third, in each of the included [http://www.tutorialspoint.com/ruby/ruby_modules.html modules] of that class, in reverse order of inclusion. &lt;br /&gt;
*Fourth, it looks in that class’s superclass. &lt;br /&gt;
*Fifth, in the superclass’s included modules, all the way up until it reaches the class Object. &lt;br /&gt;
*Sixth, if it still can’t find a method, the very last place it looks is in the [http://linux.die.net/lkmpg/x40.html Kernel module], included in the class Object. &lt;br /&gt;
*Finally, it calls method_missing (if defined in the class), else throws up the NOMethodError exception.&lt;br /&gt;
&lt;br /&gt;
This entire tracing that the object does is the method lookup path.&lt;br /&gt;
&lt;br /&gt;
=='''Examples'''==&lt;br /&gt;
===Calling defined and undefined methods===&lt;br /&gt;
&lt;br /&gt;
 class A		// creating a class 'A'&lt;br /&gt;
 def say		// defining a method 'say'&lt;br /&gt;
 puts &amp;quot; say Hi &amp;quot; // body of method say&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Creating the object of the class&lt;br /&gt;
 &lt;br /&gt;
  a=A.new	       // object of the class&lt;br /&gt;
  =&amp;gt; #&amp;lt;A:0x2a082e0&amp;gt;     //object id&lt;br /&gt;
&lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.say                  // defined method&lt;br /&gt;
 =&amp;gt; say Hi	       // returned result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.sayhi                // undefined method sayhi&lt;br /&gt;
 NoMethodError: undefined method `sayhi' for #&amp;lt;A:0x2a082e0&amp;gt;   // the NoMethodError is raised&lt;br /&gt;
&lt;br /&gt;
===method_missing implementation&amp;lt;ref&amp;gt;http://www.thirdbit.net/articles/2007/08/01/10-things-you-should-know-about-method_missing/&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def say&lt;br /&gt;
 puts &amp;quot; say hi &amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(m,*args,&amp;amp;block)	// defining method_missing&lt;br /&gt;
 puts &amp;quot; This method does not exist&amp;quot;	// body of method_missing&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Calling a method that is not defined&lt;br /&gt;
 &lt;br /&gt;
 a=A.new&lt;br /&gt;
 a.sayhi                                // calling the undefined method sayhi with no arguments&lt;br /&gt;
 =&amp;gt; This method does not exist		// this result returned when method_missing is executed&lt;br /&gt;
&lt;br /&gt;
When the object 'a' traces its method lookup path for a matching method as 'sayhi', upon failure it resorts to method_missing and the body of method_missing is executed. 'method_missing' is the last resort.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Sometimes when a class has many methods that do generally the same kinds of things, and the programmer is not sure in advance which methods the user will call since there are so many of them, and they are all so similar, implementing all of them by hand seems futile. In these situations method_missing makes a new method that was previously not defined and adds it to the class. The below 'Generic Handler' example implements this.&lt;br /&gt;
&lt;br /&gt;
===passing parameters to an undefined method call===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def add(a,b)&lt;br /&gt;
 a+b&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(name,*args,&amp;amp;block)    // the method_missing is defined and the *args parameter accepts all the parameters passed during 								                                 &lt;br /&gt;
                                             the method call   &lt;br /&gt;
 puts “You have typed the method name wrong and these were the parameters passed ; #{args[0]}, #{args[1]}”								&lt;br /&gt;
 end                         			&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The passed parameters are stored in the array 'args' and can be accessed like a normal array                &lt;br /&gt;
                                                   &lt;br /&gt;
 &lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.add(1,2)		        // calling the defined method add and passing the parameters (1,2)&lt;br /&gt;
 =&amp;gt; 3                           // result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.adds(4,2) 			// calling the undefined method adds and passing the parameter (4,2)&lt;br /&gt;
 =&amp;gt; You have typed the method name wrong and these were the parameters passed; 4, 2&lt;br /&gt;
&lt;br /&gt;
The user made a genuine mistake by typing 'adds', but this method is not defined. When the 'adds' method with parameters is called, the object 'a' tries to match the method in the method lookup path. Upon failure it invokes method_missing, the args are passed, stored in the array 'args' and the body of method_missing is executed.&lt;br /&gt;
&lt;br /&gt;
===converting numbers from roman representation to integer representation&amp;lt;ref&amp;gt;http://courses.ncsu.edu/csc517/common/lectures/notes/wk2.pdf&amp;lt;/ref&amp;gt;===&lt;br /&gt;
 class Roman&lt;br /&gt;
 DIGITS = {'I'=&amp;gt;1,'V'=&amp;gt;5,'X'=&amp;gt;10,'L'=&amp;gt;50,'C'=&amp;gt;100,'D'=&amp;gt;500,'M'=&amp;gt;1000,}&lt;br /&gt;
 def roman_to_integer(roman_string)&lt;br /&gt;
 last = nil&lt;br /&gt;
 roman_string.to_s.upcase.split(//).reverse.inject(0) do&lt;br /&gt;
 |memo, digit|&lt;br /&gt;
 if digit_value = DIGITS[digit]&lt;br /&gt;
 if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
 memo -= digit_value&lt;br /&gt;
 else&lt;br /&gt;
 memo += digit_value&lt;br /&gt;
 end&lt;br /&gt;
 last = digit_value&lt;br /&gt;
 end&lt;br /&gt;
 memo&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def method_missing(method)&lt;br /&gt;
 str=method.id2name&lt;br /&gt;
 roman_to_integer(str)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calling the undefined methods&lt;br /&gt;
&lt;br /&gt;
 r= Roman.new&lt;br /&gt;
 r.vii&lt;br /&gt;
 r.iClx&lt;br /&gt;
 r.xxix&lt;br /&gt;
 r.xxxi&lt;br /&gt;
 r.xxiv&lt;br /&gt;
 r.xxvi&lt;br /&gt;
 r.vx&lt;br /&gt;
&lt;br /&gt;
The Output&lt;br /&gt;
&lt;br /&gt;
 Numeric Value for vii is: 7&lt;br /&gt;
 Roman string is invalid&lt;br /&gt;
 Numeric Value for xxix is: 29&lt;br /&gt;
 Numeric Value for xxxi is: 31&lt;br /&gt;
 Numeric Value for xxiv is: 24&lt;br /&gt;
 Numeric Value for xxvi is: 26&lt;br /&gt;
 Roman string is invalid&lt;br /&gt;
&lt;br /&gt;
===method_missing to log method calls&amp;lt;ref&amp;gt;http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2007/wiki1b_2_22&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Another application that makes use of method_missing could be a simple logger used for debugging purposes. Many times, it may be required to log the trace of called methods and provide information such as: called method-name, arguments, return type. It can be tedious to repeat this part of code in every method. A simple solution to this problem can be obtained using method_missing as:&lt;br /&gt;
&lt;br /&gt;
  class SimpleCallLogger&lt;br /&gt;
  def initialize(o)&lt;br /&gt;
  @obj = o&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(methodname, *args)&lt;br /&gt;
  puts &amp;quot;called: #{methodname}(#{args})&amp;quot;&lt;br /&gt;
  a = @obj.send(methodname, *args)&lt;br /&gt;
  puts &amp;quot;\t-&amp;gt; returned: #{a}&amp;quot;&lt;br /&gt;
  return a&lt;br /&gt;
  end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
This program makes use of method_missing in a way that it wraps around called method to output the logging information on entry and on exit, it logs the return type. Further, method_missing intercepts the method call and forward it to internal object with ‘send’ method of ruby. Hence, this use of method_missing acts as wrapper.&lt;br /&gt;
&lt;br /&gt;
===Generic Handler===&lt;br /&gt;
 class NoBar&lt;br /&gt;
 def method_missing(methodname, *args)&lt;br /&gt;
 define_method(:bar) if &amp;quot;bar&amp;quot; == methodname.to_s&lt;br /&gt;
 define_method(:nobar) if &amp;quot;nobar&amp;quot; == methodname.to_s&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This is an example of using method_missing as a generic handler to handle when a calling method is not exist. You can use missing_method to dynamically create a method at a runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Advantages of method_missing'''==&lt;br /&gt;
&lt;br /&gt;
*In addition to specifying the error messages for the undefined methods, method_missing provides a more dynamic behavior in the programming environment.&lt;br /&gt;
*If we are unfamiliar with the usage of the objects we created, then using method_missing is a good technique.&lt;br /&gt;
*Handles problems at runtime.&lt;br /&gt;
*Define's a generic method_missing and handle's any undefined method, a big advantage over Java. In Java, when you call an undefined method, the program will not compile.&lt;br /&gt;
*method_missing falls under the general technique of [http://en.wikipedia.org/wiki/Metaprogramming meta-programming]. Employ meta-programming in missing_function to write an another function to handle the call.&lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages of method_missing'''==	&lt;br /&gt;
*Slower than conventional method lookup. Simple tests indicate that method dispatch with method_missing is at least two to three times as expensive in time as conventional dispatch.&lt;br /&gt;
&lt;br /&gt;
*Since the methods being called never actually exist—they are just intercepted at the last step of the method lookup process—they cannot be documented or introspected as conventional methods can.&lt;br /&gt;
&lt;br /&gt;
*[http://blog.jayfields.com/2008/02/ruby-dynamically-define-method.html Dynamic methods] must go through the method_missing method, the body of that method can become quite large if there are many different aspects of the code that needs to add methods dynamically.&lt;br /&gt;
&lt;br /&gt;
*method_missing restricts compatibility with future versions of an [http://en.wikipedia.org/wiki/Application_programming_interface API]. Introducing new methods in a future API version can break users' expectations.&lt;br /&gt;
&lt;br /&gt;
=='''Key Points'''==&lt;br /&gt;
*Ruby knows method_missing( ) exisits, because it's a private instance method of 'BasicObject' that every object inherits. The BasicObject#method_missing( ) responds by raising the NoMethodError. Overriding this method_missing( ) allows you to call methods that don't really exist. &lt;br /&gt;
&lt;br /&gt;
*If method_missing is only looking for certain method names, don't forget to call the [http://en.wikibooks.org/wiki/Java_Programming/Keywords/super super] keyword if you haven't found what you're looking for, so that the other superclass' method_missing can handle it.&lt;br /&gt;
&lt;br /&gt;
*[http://www.prateekdayal.net/2007/10/16/rubys-responds_to-for-checking-if-a-method-exists/ obj.respond_to?] function returns 'true' if the obj responds to the given method. So if you want to know whether your class will respond to a function you can use respond_to? to know the answer. But if method_missing() is used, the output may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
*Below class A defines only method method_missing() and no other method. When a new object of class A tries to access a method say 'foo', the respond_to? will return the value 'false'. When you actually try to implement it using “a.foo”, the code will get executed, courtesy of method_missing(). Even though the respond_to? says that you cannot access 'foo' method using object of class A, if you have method_missing() defined, you can access the method.&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In method_missing&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)&lt;br /&gt;
 a.foo&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 false&lt;br /&gt;
 In method_missing&lt;br /&gt;
&lt;br /&gt;
*If within method_missing() we define an undefined method. &lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 @@i = 0&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In Method Missing #{@@i}&amp;quot;&lt;br /&gt;
 @@i += 1&lt;br /&gt;
 self.fun&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)	// just checking whether the receiver 'a' responds to the method 'foo'&lt;br /&gt;
				  &lt;br /&gt;
 a.foo &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 The expected result would be a 'stack level too deep' error. &lt;br /&gt;
&lt;br /&gt;
When the 'foo' method is called, after no method match the method_missing is run and this block has a method “self.fun” that is undefined. Here when the program execution encounters 'self.fun' it once again calls method_missing. This goes on in an endless loop till the stack memory is full.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
*http://www.rubyinside.com/ &lt;br /&gt;
*http://blog.jayfields.com/2008/02/ruby-replace-methodmissing-with-dynamic.html &lt;br /&gt;
*http://liquiddevelopment.blogspot.com/2006/04/twisting-and-shaping-dsls-using-ruby.html &lt;br /&gt;
*http://blog.rubybestpractices.com/posts/gregory/031-issue-2-method-lookup.html&lt;br /&gt;
*http://phrogz.net/RubyLibs/RubyMethodLookupFlow.pdf&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=64024</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w22 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=64024"/>
		<updated>2012-09-13T08:38:18Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* converting numbers from roman representation to integer representationhttp://www.rubyquiz.com/quiz22.html */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''method_missing in Ruby:'''  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Introduction&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_method_missing.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
A method of a class is called by creating an object of the class and passing the method name to the object as a message. The object then looks up into its [http://www.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html method lookup path] and tries to match the called method with the defined methods in the class. On success, the method is executed along with the parameters passed and the result is returned.&lt;br /&gt;
&lt;br /&gt;
If the object does not find a match in its method lookup, in normal circumstances the [http://www.ruby-doc.org/core-1.9.3/NoMethodError.html NoMethodError Exception] is raised .&lt;br /&gt;
&lt;br /&gt;
“method_missing” is defined as a method in the class and is invoked if a called method is not found.&lt;br /&gt;
&lt;br /&gt;
=='''Format for defining method_missing'''==&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; def method_missing(m,*args,&amp;amp;block)&lt;br /&gt;
&lt;br /&gt;
(i) '''m-&amp;gt;''' accepts the symbol/name of the undefined method (ii) '''*args-&amp;gt;''' accepts the array of arguments passed in the method call  (iii) '''&amp;amp;block-&amp;gt;'''accepts a block passed to the method&lt;br /&gt;
&lt;br /&gt;
=='''Different types of methods'''==&lt;br /&gt;
The object of a class receives a method name to be executed, the following steps are carried out for matching and executing the method:&lt;br /&gt;
&lt;br /&gt;
*First, the object looks in its own [http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html instance methods].&lt;br /&gt;
*Second, it looks in the list of instance methods that all objects of that class share.&lt;br /&gt;
*Third, in each of the included [http://www.tutorialspoint.com/ruby/ruby_modules.html modules] of that class, in reverse order of inclusion. &lt;br /&gt;
*Fourth, it looks in that class’s superclass. &lt;br /&gt;
*Fifth, in the superclass’s included modules, all the way up until it reaches the class Object. &lt;br /&gt;
*Sixth, if it still can’t find a method, the very last place it looks is in the [http://linux.die.net/lkmpg/x40.html Kernel module], included in the class Object. &lt;br /&gt;
*Finally, it calls method_missing (if defined in the class), else throws up the NOMethodError exception.&lt;br /&gt;
&lt;br /&gt;
This entire tracing that the object does is the method lookup path.&lt;br /&gt;
&lt;br /&gt;
=='''Examples'''==&lt;br /&gt;
===Calling defined and undefined methods===&lt;br /&gt;
&lt;br /&gt;
 class A		// creating a class 'A'&lt;br /&gt;
 def say		// defining a method 'say'&lt;br /&gt;
 puts &amp;quot; say Hi &amp;quot; // body of method say&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Creating the object of the class&lt;br /&gt;
 &lt;br /&gt;
  a=A.new	       // object of the class&lt;br /&gt;
  =&amp;gt; #&amp;lt;A:0x2a082e0&amp;gt;     //object id&lt;br /&gt;
&lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.say                  // defined method&lt;br /&gt;
 =&amp;gt; say Hi	       // returned result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.sayhi                // undefined method sayhi&lt;br /&gt;
 NoMethodError: undefined method `sayhi' for #&amp;lt;A:0x2a082e0&amp;gt;   // the NoMethodError is raised&lt;br /&gt;
&lt;br /&gt;
===method_missing implementation&amp;lt;ref&amp;gt;http://www.thirdbit.net/articles/2007/08/01/10-things-you-should-know-about-method_missing/&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def say&lt;br /&gt;
 puts &amp;quot; say hi &amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(m,*args,&amp;amp;block)	// defining method_missing&lt;br /&gt;
 puts &amp;quot; This method does not exist&amp;quot;	// body of method_missing&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Calling a method that is not defined&lt;br /&gt;
 &lt;br /&gt;
 a=A.new&lt;br /&gt;
 a.sayhi                                // calling the undefined method sayhi with no arguments&lt;br /&gt;
 =&amp;gt; This method does not exist		// this result returned when method_missing is executed&lt;br /&gt;
&lt;br /&gt;
When the object 'a' traces its method lookup path for a matching method as 'sayhi', upon failure it resorts to method_missing and the body of method_missing is executed. 'method_missing' is the last resort.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Sometimes when a class has many methods that do generally the same kinds of things, and the programmer is not sure in advance which methods the user will call since there are so many of them, and they are all so similar, implementing all of them by hand seems futile. In these situations method_missing makes a new method that was previously not defined and adds it to the class. The below 'Generic Handler' example implements this.&lt;br /&gt;
&lt;br /&gt;
===passing parameters to an undefined method call===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def add(a,b)&lt;br /&gt;
 a+b&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(name,*args,&amp;amp;block)    // the method_missing is defined and the *args parameter accepts all the parameters passed during 								                                 &lt;br /&gt;
                                             the method call   &lt;br /&gt;
 puts “You have typed the method name wrong and these were the parameters passed ; #{args[0]}, #{args[1]}”								&lt;br /&gt;
 end                         			&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The passed parameters are stored in the array 'args' and can be accessed like a normal array                &lt;br /&gt;
                                                   &lt;br /&gt;
 &lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.add(1,2)		        // calling the defined method add and passing the parameters (1,2)&lt;br /&gt;
 =&amp;gt; 3                           // result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.adds(4,2) 			// calling the undefined method adds and passing the parameter (4,2)&lt;br /&gt;
 =&amp;gt; You have typed the method name wrong and these were the parameters passed; 4, 2&lt;br /&gt;
&lt;br /&gt;
The user made a genuine mistake by typing 'adds', but this method is not defined. When the 'adds' method with parameters is called, the object 'a' tries to match the method in the method lookup path. Upon failure it invokes method_missing, the args are passed, stored in the array 'args' and the body of method_missing is executed.&lt;br /&gt;
&lt;br /&gt;
===converting numbers from roman representation to integer representation&amp;lt;ref&amp;gt;http://www.rubyquiz.com/quiz22.html&amp;lt;/ref&amp;gt;===&lt;br /&gt;
 class Roman&lt;br /&gt;
 DIGITS = {'I'=&amp;gt;1,'V'=&amp;gt;5,'X'=&amp;gt;10,'L'=&amp;gt;50,'C'=&amp;gt;100,'D'=&amp;gt;500,'M'=&amp;gt;1000,}&lt;br /&gt;
 def roman_to_integer(roman_string)&lt;br /&gt;
 last = nil&lt;br /&gt;
 roman_string.to_s.upcase.split(//).reverse.inject(0) do&lt;br /&gt;
 |memo, digit|&lt;br /&gt;
 if digit_value = DIGITS[digit]&lt;br /&gt;
 if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
 memo -= digit_value&lt;br /&gt;
 else&lt;br /&gt;
 memo += digit_value&lt;br /&gt;
 end&lt;br /&gt;
 last = digit_value&lt;br /&gt;
 end&lt;br /&gt;
 memo&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def method_missing(method)&lt;br /&gt;
 str=method.id2name&lt;br /&gt;
 roman_to_integer(str)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calling the undefined methods&lt;br /&gt;
&lt;br /&gt;
 r= Roman.new&lt;br /&gt;
 r.vii&lt;br /&gt;
 r.iClx&lt;br /&gt;
 r.xxix&lt;br /&gt;
 r.xxxi&lt;br /&gt;
 r.xxiv&lt;br /&gt;
 r.xxvi&lt;br /&gt;
 r.vx&lt;br /&gt;
&lt;br /&gt;
The Output&lt;br /&gt;
&lt;br /&gt;
 Numeric Value for vii is: 7&lt;br /&gt;
 Roman string is invalid&lt;br /&gt;
 Numeric Value for xxix is: 29&lt;br /&gt;
 Numeric Value for xxxi is: 31&lt;br /&gt;
 Numeric Value for xxiv is: 24&lt;br /&gt;
 Numeric Value for xxvi is: 26&lt;br /&gt;
 Roman string is invalid&lt;br /&gt;
&lt;br /&gt;
===method_missing to log method calls&amp;lt;ref&amp;gt;http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2007/wiki1b_2_22&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Another application that makes use of method_missing could be a simple logger used for debugging purposes. Many times, it may be required to log the trace of called methods and provide information such as: called method-name, arguments, return type. It can be tedious to repeat this part of code in every method. A simple solution to this problem can be obtained using method_missing as:&lt;br /&gt;
&lt;br /&gt;
  class SimpleCallLogger&lt;br /&gt;
  def initialize(o)&lt;br /&gt;
  @obj = o&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(methodname, *args)&lt;br /&gt;
  puts &amp;quot;called: #{methodname}(#{args})&amp;quot;&lt;br /&gt;
  a = @obj.send(methodname, *args)&lt;br /&gt;
  puts &amp;quot;\t-&amp;gt; returned: #{a}&amp;quot;&lt;br /&gt;
  return a&lt;br /&gt;
  end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
This program makes use of method_missing in a way that it wraps around called method to output the logging information on entry and on exit, it logs the return type. Further, method_missing intercepts the method call and forward it to internal object with ‘send’ method of ruby. Hence, this use of method_missing acts as wrapper.&lt;br /&gt;
&lt;br /&gt;
===Generic Handler===&lt;br /&gt;
 class NoBar&lt;br /&gt;
 def method_missing(methodname, *args)&lt;br /&gt;
 define_method(:bar) if &amp;quot;bar&amp;quot; == methodname.to_s&lt;br /&gt;
 define_method(:nobar) if &amp;quot;nobar&amp;quot; == methodname.to_s&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This is an example of using method_missing as a generic handler to handle when a calling method is not exist. You can use missing_method to dynamically create a method at a runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Advantages of method_missing'''==&lt;br /&gt;
&lt;br /&gt;
*In addition to specifying the error messages for the undefined methods, method_missing provides a more dynamic behavior in the programming environment.&lt;br /&gt;
*If we are unfamiliar with the usage of the objects we created, then using method_missing is a good technique.&lt;br /&gt;
*Handles problems at runtime.&lt;br /&gt;
*Define's a generic method_missing and handle's any undefined method, a big advantage over Java. In Java, when you call an undefined method, the program will not compile.&lt;br /&gt;
*method_missing falls under the general technique of [http://en.wikipedia.org/wiki/Metaprogramming meta-programming]. Employ meta-programming in missing_function to write an another function to handle the call.&lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages of method_missing'''==	&lt;br /&gt;
*Slower than conventional method lookup. Simple tests indicate that method dispatch with method_missing is at least two to three times as expensive in time as conventional dispatch.&lt;br /&gt;
&lt;br /&gt;
*Since the methods being called never actually exist—they are just intercepted at the last step of the method lookup process—they cannot be documented or introspected as conventional methods can.&lt;br /&gt;
&lt;br /&gt;
*[http://blog.jayfields.com/2008/02/ruby-dynamically-define-method.html Dynamic methods] must go through the method_missing method, the body of that method can become quite large if there are many different aspects of the code that needs to add methods dynamically.&lt;br /&gt;
&lt;br /&gt;
*method_missing restricts compatibility with future versions of an [http://en.wikipedia.org/wiki/Application_programming_interface API]. Introducing new methods in a future API version can break users' expectations.&lt;br /&gt;
&lt;br /&gt;
=='''Key Points'''==&lt;br /&gt;
*Ruby knows method_missing( ) exisits, because it's a private instance method of 'BasicObject' that every object inherits. The BasicObject#method_missing( ) responds by raising the NoMethodError. Overriding this method_missing( ) allows you to call methods that don't really exist. &lt;br /&gt;
&lt;br /&gt;
*If method_missing is only looking for certain method names, don't forget to call the [http://en.wikibooks.org/wiki/Java_Programming/Keywords/super super] keyword if you haven't found what you're looking for, so that the other superclass' method_missing can handle it.&lt;br /&gt;
&lt;br /&gt;
*[http://www.prateekdayal.net/2007/10/16/rubys-responds_to-for-checking-if-a-method-exists/ obj.respond_to?] function returns 'true' if the obj responds to the given method. So if you want to know whether your class will respond to a function you can use respond_to? to know the answer. But if method_missing() is used, the output may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
*Below class A defines only method method_missing() and no other method. When a new object of class A tries to access a method say 'foo', the respond_to? will return the value 'false'. When you actually try to implement it using “a.foo”, the code will get executed, courtesy of method_missing(). Even though the respond_to? says that you cannot access 'foo' method using object of class A, if you have method_missing() defined, you can access the method.&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In method_missing&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)&lt;br /&gt;
 a.foo&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 false&lt;br /&gt;
 In method_missing&lt;br /&gt;
&lt;br /&gt;
*If within method_missing() we define an undefined method. &lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 @@i = 0&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In Method Missing #{@@i}&amp;quot;&lt;br /&gt;
 @@i += 1&lt;br /&gt;
 self.fun&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)	// just checking whether the receiver 'a' responds to the method 'foo'&lt;br /&gt;
				  &lt;br /&gt;
 a.foo &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 The expected result would be a 'stack level too deep' error. &lt;br /&gt;
&lt;br /&gt;
When the 'foo' method is called, after no method match the method_missing is run and this block has a method “self.fun” that is undefined. Here when the program execution encounters 'self.fun' it once again calls method_missing. This goes on in an endless loop till the stack memory is full.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
*http://www.rubyinside.com/ &lt;br /&gt;
*http://blog.jayfields.com/2008/02/ruby-replace-methodmissing-with-dynamic.html &lt;br /&gt;
*http://liquiddevelopment.blogspot.com/2006/04/twisting-and-shaping-dsls-using-ruby.html &lt;br /&gt;
*http://blog.rubybestpractices.com/posts/gregory/031-issue-2-method-lookup.html&lt;br /&gt;
*http://phrogz.net/RubyLibs/RubyMethodLookupFlow.pdf&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=64023</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w22 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=64023"/>
		<updated>2012-09-13T08:37:43Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* converting numbers from roman representation to integer representationhttp://www.rubyquiz.com/quiz22.html */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''method_missing in Ruby:'''  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Introduction&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_method_missing.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
A method of a class is called by creating an object of the class and passing the method name to the object as a message. The object then looks up into its [http://www.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html method lookup path] and tries to match the called method with the defined methods in the class. On success, the method is executed along with the parameters passed and the result is returned.&lt;br /&gt;
&lt;br /&gt;
If the object does not find a match in its method lookup, in normal circumstances the [http://www.ruby-doc.org/core-1.9.3/NoMethodError.html NoMethodError Exception] is raised .&lt;br /&gt;
&lt;br /&gt;
“method_missing” is defined as a method in the class and is invoked if a called method is not found.&lt;br /&gt;
&lt;br /&gt;
=='''Format for defining method_missing'''==&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; def method_missing(m,*args,&amp;amp;block)&lt;br /&gt;
&lt;br /&gt;
(i) '''m-&amp;gt;''' accepts the symbol/name of the undefined method (ii) '''*args-&amp;gt;''' accepts the array of arguments passed in the method call  (iii) '''&amp;amp;block-&amp;gt;'''accepts a block passed to the method&lt;br /&gt;
&lt;br /&gt;
=='''Different types of methods'''==&lt;br /&gt;
The object of a class receives a method name to be executed, the following steps are carried out for matching and executing the method:&lt;br /&gt;
&lt;br /&gt;
*First, the object looks in its own [http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html instance methods].&lt;br /&gt;
*Second, it looks in the list of instance methods that all objects of that class share.&lt;br /&gt;
*Third, in each of the included [http://www.tutorialspoint.com/ruby/ruby_modules.html modules] of that class, in reverse order of inclusion. &lt;br /&gt;
*Fourth, it looks in that class’s superclass. &lt;br /&gt;
*Fifth, in the superclass’s included modules, all the way up until it reaches the class Object. &lt;br /&gt;
*Sixth, if it still can’t find a method, the very last place it looks is in the [http://linux.die.net/lkmpg/x40.html Kernel module], included in the class Object. &lt;br /&gt;
*Finally, it calls method_missing (if defined in the class), else throws up the NOMethodError exception.&lt;br /&gt;
&lt;br /&gt;
This entire tracing that the object does is the method lookup path.&lt;br /&gt;
&lt;br /&gt;
=='''Examples'''==&lt;br /&gt;
===Calling defined and undefined methods===&lt;br /&gt;
&lt;br /&gt;
 class A		// creating a class 'A'&lt;br /&gt;
 def say		// defining a method 'say'&lt;br /&gt;
 puts &amp;quot; say Hi &amp;quot; // body of method say&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Creating the object of the class&lt;br /&gt;
 &lt;br /&gt;
  a=A.new	       // object of the class&lt;br /&gt;
  =&amp;gt; #&amp;lt;A:0x2a082e0&amp;gt;     //object id&lt;br /&gt;
&lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.say                  // defined method&lt;br /&gt;
 =&amp;gt; say Hi	       // returned result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.sayhi                // undefined method sayhi&lt;br /&gt;
 NoMethodError: undefined method `sayhi' for #&amp;lt;A:0x2a082e0&amp;gt;   // the NoMethodError is raised&lt;br /&gt;
&lt;br /&gt;
===method_missing implementation&amp;lt;ref&amp;gt;http://www.thirdbit.net/articles/2007/08/01/10-things-you-should-know-about-method_missing/&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def say&lt;br /&gt;
 puts &amp;quot; say hi &amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(m,*args,&amp;amp;block)	// defining method_missing&lt;br /&gt;
 puts &amp;quot; This method does not exist&amp;quot;	// body of method_missing&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Calling a method that is not defined&lt;br /&gt;
 &lt;br /&gt;
 a=A.new&lt;br /&gt;
 a.sayhi                                // calling the undefined method sayhi with no arguments&lt;br /&gt;
 =&amp;gt; This method does not exist		// this result returned when method_missing is executed&lt;br /&gt;
&lt;br /&gt;
When the object 'a' traces its method lookup path for a matching method as 'sayhi', upon failure it resorts to method_missing and the body of method_missing is executed. 'method_missing' is the last resort.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Sometimes when a class has many methods that do generally the same kinds of things, and the programmer is not sure in advance which methods the user will call since there are so many of them, and they are all so similar, implementing all of them by hand seems futile. In these situations method_missing makes a new method that was previously not defined and adds it to the class. The below 'Generic Handler' example implements this.&lt;br /&gt;
&lt;br /&gt;
===passing parameters to an undefined method call===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def add(a,b)&lt;br /&gt;
 a+b&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(name,*args,&amp;amp;block)    // the method_missing is defined and the *args parameter accepts all the parameters passed during 								                                 &lt;br /&gt;
                                             the method call   &lt;br /&gt;
 puts “You have typed the method name wrong and these were the parameters passed ; #{args[0]}, #{args[1]}”								&lt;br /&gt;
 end                         			&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The passed parameters are stored in the array 'args' and can be accessed like a normal array                &lt;br /&gt;
                                                   &lt;br /&gt;
 &lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.add(1,2)		        // calling the defined method add and passing the parameters (1,2)&lt;br /&gt;
 =&amp;gt; 3                           // result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.adds(4,2) 			// calling the undefined method adds and passing the parameter (4,2)&lt;br /&gt;
 =&amp;gt; You have typed the method name wrong and these were the parameters passed; 4, 2&lt;br /&gt;
&lt;br /&gt;
The user made a genuine mistake by typing 'adds', but this method is not defined. When the 'adds' method with parameters is called, the object 'a' tries to match the method in the method lookup path. Upon failure it invokes method_missing, the args are passed, stored in the array 'args' and the body of method_missing is executed.&lt;br /&gt;
&lt;br /&gt;
===converting numbers from roman representation to integer representation&amp;lt;ref&amp;gt;http://www.rubyquiz.com/quiz22.html&amp;lt;/ref&amp;gt;===&lt;br /&gt;
  class Roman&lt;br /&gt;
&lt;br /&gt;
 DIGITS = {'I'=&amp;gt;1,'V'=&amp;gt;5,'X'=&amp;gt;10,'L'=&amp;gt;50,'C'=&amp;gt;100,'D'=&amp;gt;500,'M'=&amp;gt;1000,}&lt;br /&gt;
&lt;br /&gt;
 def roman_to_integer(roman_string)&lt;br /&gt;
 last = nil&lt;br /&gt;
&lt;br /&gt;
 roman_string.to_s.upcase.split(//).reverse.inject(0) do&lt;br /&gt;
 |memo, digit|&lt;br /&gt;
 if digit_value = DIGITS[digit]&lt;br /&gt;
 if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
 memo -= digit_value&lt;br /&gt;
 else&lt;br /&gt;
 memo += digit_value&lt;br /&gt;
 end&lt;br /&gt;
 last = digit_value&lt;br /&gt;
 end&lt;br /&gt;
 memo&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def method_missing(method)&lt;br /&gt;
 str=method.id2name&lt;br /&gt;
 roman_to_integer(str)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calling the undefined methods&lt;br /&gt;
&lt;br /&gt;
 r= Roman.new&lt;br /&gt;
 r.vii&lt;br /&gt;
 r.iClx&lt;br /&gt;
 r.xxix&lt;br /&gt;
 r.xxxi&lt;br /&gt;
 r.xxiv&lt;br /&gt;
 r.xxvi&lt;br /&gt;
 r.vx&lt;br /&gt;
&lt;br /&gt;
The Output&lt;br /&gt;
&lt;br /&gt;
 Numeric Value for vii is: 7&lt;br /&gt;
 Roman string is invalid&lt;br /&gt;
 Numeric Value for xxix is: 29&lt;br /&gt;
 Numeric Value for xxxi is: 31&lt;br /&gt;
 Numeric Value for xxiv is: 24&lt;br /&gt;
 Numeric Value for xxvi is: 26&lt;br /&gt;
 Roman string is invalid&lt;br /&gt;
&lt;br /&gt;
===method_missing to log method calls&amp;lt;ref&amp;gt;http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2007/wiki1b_2_22&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Another application that makes use of method_missing could be a simple logger used for debugging purposes. Many times, it may be required to log the trace of called methods and provide information such as: called method-name, arguments, return type. It can be tedious to repeat this part of code in every method. A simple solution to this problem can be obtained using method_missing as:&lt;br /&gt;
&lt;br /&gt;
  class SimpleCallLogger&lt;br /&gt;
  def initialize(o)&lt;br /&gt;
  @obj = o&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(methodname, *args)&lt;br /&gt;
  puts &amp;quot;called: #{methodname}(#{args})&amp;quot;&lt;br /&gt;
  a = @obj.send(methodname, *args)&lt;br /&gt;
  puts &amp;quot;\t-&amp;gt; returned: #{a}&amp;quot;&lt;br /&gt;
  return a&lt;br /&gt;
  end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
This program makes use of method_missing in a way that it wraps around called method to output the logging information on entry and on exit, it logs the return type. Further, method_missing intercepts the method call and forward it to internal object with ‘send’ method of ruby. Hence, this use of method_missing acts as wrapper.&lt;br /&gt;
&lt;br /&gt;
===Generic Handler===&lt;br /&gt;
 class NoBar&lt;br /&gt;
 def method_missing(methodname, *args)&lt;br /&gt;
 define_method(:bar) if &amp;quot;bar&amp;quot; == methodname.to_s&lt;br /&gt;
 define_method(:nobar) if &amp;quot;nobar&amp;quot; == methodname.to_s&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This is an example of using method_missing as a generic handler to handle when a calling method is not exist. You can use missing_method to dynamically create a method at a runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Advantages of method_missing'''==&lt;br /&gt;
&lt;br /&gt;
*In addition to specifying the error messages for the undefined methods, method_missing provides a more dynamic behavior in the programming environment.&lt;br /&gt;
*If we are unfamiliar with the usage of the objects we created, then using method_missing is a good technique.&lt;br /&gt;
*Handles problems at runtime.&lt;br /&gt;
*Define's a generic method_missing and handle's any undefined method, a big advantage over Java. In Java, when you call an undefined method, the program will not compile.&lt;br /&gt;
*method_missing falls under the general technique of [http://en.wikipedia.org/wiki/Metaprogramming meta-programming]. Employ meta-programming in missing_function to write an another function to handle the call.&lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages of method_missing'''==	&lt;br /&gt;
*Slower than conventional method lookup. Simple tests indicate that method dispatch with method_missing is at least two to three times as expensive in time as conventional dispatch.&lt;br /&gt;
&lt;br /&gt;
*Since the methods being called never actually exist—they are just intercepted at the last step of the method lookup process—they cannot be documented or introspected as conventional methods can.&lt;br /&gt;
&lt;br /&gt;
*[http://blog.jayfields.com/2008/02/ruby-dynamically-define-method.html Dynamic methods] must go through the method_missing method, the body of that method can become quite large if there are many different aspects of the code that needs to add methods dynamically.&lt;br /&gt;
&lt;br /&gt;
*method_missing restricts compatibility with future versions of an [http://en.wikipedia.org/wiki/Application_programming_interface API]. Introducing new methods in a future API version can break users' expectations.&lt;br /&gt;
&lt;br /&gt;
=='''Key Points'''==&lt;br /&gt;
*Ruby knows method_missing( ) exisits, because it's a private instance method of 'BasicObject' that every object inherits. The BasicObject#method_missing( ) responds by raising the NoMethodError. Overriding this method_missing( ) allows you to call methods that don't really exist. &lt;br /&gt;
&lt;br /&gt;
*If method_missing is only looking for certain method names, don't forget to call the [http://en.wikibooks.org/wiki/Java_Programming/Keywords/super super] keyword if you haven't found what you're looking for, so that the other superclass' method_missing can handle it.&lt;br /&gt;
&lt;br /&gt;
*[http://www.prateekdayal.net/2007/10/16/rubys-responds_to-for-checking-if-a-method-exists/ obj.respond_to?] function returns 'true' if the obj responds to the given method. So if you want to know whether your class will respond to a function you can use respond_to? to know the answer. But if method_missing() is used, the output may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
*Below class A defines only method method_missing() and no other method. When a new object of class A tries to access a method say 'foo', the respond_to? will return the value 'false'. When you actually try to implement it using “a.foo”, the code will get executed, courtesy of method_missing(). Even though the respond_to? says that you cannot access 'foo' method using object of class A, if you have method_missing() defined, you can access the method.&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In method_missing&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)&lt;br /&gt;
 a.foo&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 false&lt;br /&gt;
 In method_missing&lt;br /&gt;
&lt;br /&gt;
*If within method_missing() we define an undefined method. &lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 @@i = 0&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In Method Missing #{@@i}&amp;quot;&lt;br /&gt;
 @@i += 1&lt;br /&gt;
 self.fun&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)	// just checking whether the receiver 'a' responds to the method 'foo'&lt;br /&gt;
				  &lt;br /&gt;
 a.foo &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 The expected result would be a 'stack level too deep' error. &lt;br /&gt;
&lt;br /&gt;
When the 'foo' method is called, after no method match the method_missing is run and this block has a method “self.fun” that is undefined. Here when the program execution encounters 'self.fun' it once again calls method_missing. This goes on in an endless loop till the stack memory is full.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
*http://www.rubyinside.com/ &lt;br /&gt;
*http://blog.jayfields.com/2008/02/ruby-replace-methodmissing-with-dynamic.html &lt;br /&gt;
*http://liquiddevelopment.blogspot.com/2006/04/twisting-and-shaping-dsls-using-ruby.html &lt;br /&gt;
*http://blog.rubybestpractices.com/posts/gregory/031-issue-2-method-lookup.html&lt;br /&gt;
*http://phrogz.net/RubyLibs/RubyMethodLookupFlow.pdf&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=63658</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w22 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=63658"/>
		<updated>2012-09-12T02:45:07Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* converting numbers from roman representation to integer representationhttp://www.rubyquiz.com/quiz22.html */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''method_missing in Ruby:'''  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Introduction&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_method_missing.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
A method of a class is called by creating an object of the class and passing the method name to the object as a message. The object then looks up into its [http://www.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html method lookup path] and tries to match the called method with the defined methods in the class. On success, the method is executed along with the parameters passed and the result is returned.&lt;br /&gt;
&lt;br /&gt;
If the object does not find a match in its method lookup, in normal circumstances the [http://www.ruby-doc.org/core-1.9.3/NoMethodError.html NoMethodError Exception] is raised .&lt;br /&gt;
&lt;br /&gt;
“method_missing” is defined as a method in the class and is invoked if a called method is not found.&lt;br /&gt;
&lt;br /&gt;
=='''Format for defining method_missing'''==&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; def method_missing(m,*args,&amp;amp;block)&lt;br /&gt;
&lt;br /&gt;
(i) '''m-&amp;gt;''' accepts the symbol/name of the undefined method (ii) '''*args-&amp;gt;''' accepts the array of arguments passed in the method call  (iii) '''&amp;amp;block-&amp;gt;'''accepts a block passed to the method&lt;br /&gt;
&lt;br /&gt;
=='''Method Lookup Path'''==&lt;br /&gt;
The object of a class receives a method name to be executed, the following steps are carried out for matching and executing the method:&lt;br /&gt;
&lt;br /&gt;
*First, the object looks in its own [http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html instance methods].&lt;br /&gt;
*Second, it looks in the list of instance methods that all objects of that class share.&lt;br /&gt;
*Third, in each of the included [http://www.tutorialspoint.com/ruby/ruby_modules.html modules] of that class, in reverse order of inclusion. &lt;br /&gt;
*Fourth, it looks in that class’s superclass. &lt;br /&gt;
*Fifth, in the superclass’s included modules, all the way up until it reaches the class Object. &lt;br /&gt;
*Sixth, if it still can’t find a method, the very last place it looks is in the [http://linux.die.net/lkmpg/x40.html Kernel module], included in the class Object. &lt;br /&gt;
*Finally, it calls method_missing (if defined in the class), else throws up the NOMethodError exception.&lt;br /&gt;
&lt;br /&gt;
This entire tracing that the object does is the method lookup path.&lt;br /&gt;
&lt;br /&gt;
=='''Examples'''==&lt;br /&gt;
===Calling defined and undefined methods===&lt;br /&gt;
&lt;br /&gt;
 class A		// creating a class 'A'&lt;br /&gt;
 def say		// defining a method 'say'&lt;br /&gt;
 puts &amp;quot; say Hi &amp;quot; // body of method say&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Creating the object of the class&lt;br /&gt;
 &lt;br /&gt;
  a=A.new	       // object of the class&lt;br /&gt;
  =&amp;gt; #&amp;lt;A:0x2a082e0&amp;gt;     //object id&lt;br /&gt;
&lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.say                  // defined method&lt;br /&gt;
 =&amp;gt; say Hi	       // returned result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.sayhi                // undefined method sayhi&lt;br /&gt;
 NoMethodError: undefined method `sayhi' for #&amp;lt;A:0x2a082e0&amp;gt;   // the NoMethodError is raised&lt;br /&gt;
&lt;br /&gt;
===method_missing implementation&amp;lt;ref&amp;gt;http://www.thirdbit.net/articles/2007/08/01/10-things-you-should-know-about-method_missing/&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def say&lt;br /&gt;
 puts &amp;quot; say hi &amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(m,*args,&amp;amp;block)	// defining method_missing&lt;br /&gt;
 puts &amp;quot; This method does not exist&amp;quot;	// body of method_missing&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Calling a method that is not defined&lt;br /&gt;
 &lt;br /&gt;
 a=A.new&lt;br /&gt;
 a.sayhi                                // calling the undefined method sayhi with no arguments&lt;br /&gt;
 =&amp;gt; This method does not exist		// this result returned when method_missing is executed&lt;br /&gt;
&lt;br /&gt;
When the object 'a' traces its method lookup path for a matching method as 'sayhi', upon failure it resorts to method_missing and the body of method_missing is executed. 'method_missing' is the last resort.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Sometimes when a class has many methods that do generally the same kinds of things, and the programmer is not sure in advance which methods the user will call since there are so many of them, and they are all so similar, implementing all of them by hand seems futile. In these situations method_missing makes a new method that was previously not defined and adds it to the class. The below 'Generic Handler' example implements this.&lt;br /&gt;
&lt;br /&gt;
===passing parameters to an undefined method call===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def add(a,b)&lt;br /&gt;
 a+b&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(name,*args,&amp;amp;block)    // the method_missing is defined and the *args parameter accepts all the parameters passed during 								                                 &lt;br /&gt;
                                             the method call   &lt;br /&gt;
 puts “You have typed the method name wrong and these were the parameters passed ; #{args[0]}, #{args[1]}”								&lt;br /&gt;
 end                         			&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The passed parameters are stored in the array 'args' and can be accessed like a normal array                &lt;br /&gt;
                                                   &lt;br /&gt;
 &lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.add(1,2)		        // calling the defined method add and passing the parameters (1,2)&lt;br /&gt;
 =&amp;gt; 3                           // result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.adds(4,2) 			// calling the undefined method adds and passing the parameter (4,2)&lt;br /&gt;
 =&amp;gt; You have typed the method name wrong and these were the parameters passed; 4, 2&lt;br /&gt;
&lt;br /&gt;
The user made a genuine mistake by typing 'adds', but this method is not defined. When the 'adds' method with parameters is called, the object 'a' tries to match the method in the method lookup path. Upon failure it invokes method_missing, the args are passed, stored in the array 'args' and the body of method_missing is executed.&lt;br /&gt;
&lt;br /&gt;
===converting numbers from roman representation to integer representation&amp;lt;ref&amp;gt;http://www.rubyquiz.com/quiz22.html&amp;lt;/ref&amp;gt;===&lt;br /&gt;
 class Roman&lt;br /&gt;
 @@Roman_to_Numeric = {'i' =&amp;gt; 1, 'v' =&amp;gt; 5, 'x' =&amp;gt; 10, 'l' =&amp;gt; 50, 'c' =&amp;gt; 100, 'd' =&amp;gt; 500, 'm' =&amp;gt; 1000}   &lt;br /&gt;
 def method_missing(method_var,*args,&amp;amp;block)&lt;br /&gt;
 numeric_value = 0&lt;br /&gt;
 roman_string = method_var.to_s.downcase&lt;br /&gt;
 for i in 0...roman_string.length-1&lt;br /&gt;
 if (cond) == nil&lt;br /&gt;
 else&lt;br /&gt;
 puts &amp;quot;Roman string is invalid&amp;quot;&lt;br /&gt;
 return&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 while roman_string != &amp;quot;&amp;quot;&lt;br /&gt;
 if roman_string[roman_string.length - 1] == 'x' &amp;amp;&amp;amp; roman_string[roman_string.length - 2] == 'i'&lt;br /&gt;
 numeric_value += 9&lt;br /&gt;
 roman_string.chop!&lt;br /&gt;
 roman_string.chop!&lt;br /&gt;
 elsif&lt;br /&gt;
 roman_string[roman_string.length - 1] == 'v' &amp;amp;&amp;amp; roman_string[roman_string.length - 2] == 'i'&lt;br /&gt;
 numeric_value += 4&lt;br /&gt;
 roman_string.chop!&lt;br /&gt;
 roman_string.chop!&lt;br /&gt;
 else&lt;br /&gt;
 numeric_value += @@Roman_to_Numeric[roman_string[(roman_string.length)-1]]&lt;br /&gt;
 roman_string.chop!&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 puts &amp;quot;Numeric Value for #{method_var} is: #{numeric_value}&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
'''cond''' = '''['''@@Roman_to_Numeric[roman_string[i]]-@@Roman_to_Numeric[roman_string[i+1]] == 0 || @@Roman_to_Numeric[roman_string[i]]-@@Roman _ to_                               Numeric [ roman _ string [ i + 1 ] ]  ==  - 9 || @@Roman_to_Numeric[roman_string[i]]-@@Roman_to_Numeric[roman_string[i+1]] == -4    ||    @@Roman_to_Numeric[roman_string[i]]-@@Roman_to_Numeric[roman_string[i+1]] &amp;gt;= 4) &amp;amp;&amp;amp; (/.v.x/ =~ roman_string''']'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calling the undefined methods&lt;br /&gt;
&lt;br /&gt;
 r= Roman.new&lt;br /&gt;
 r.vii&lt;br /&gt;
 r.iClx&lt;br /&gt;
 r.xxix&lt;br /&gt;
 r.xxxi&lt;br /&gt;
 r.xxiv&lt;br /&gt;
 r.xxvi&lt;br /&gt;
 r.vx&lt;br /&gt;
&lt;br /&gt;
The Output&lt;br /&gt;
&lt;br /&gt;
 Numeric Value for vii is: 7&lt;br /&gt;
 Roman string is invalid&lt;br /&gt;
 Numeric Value for xxix is: 29&lt;br /&gt;
 Numeric Value for xxxi is: 31&lt;br /&gt;
 Numeric Value for xxiv is: 24&lt;br /&gt;
 Numeric Value for xxvi is: 26&lt;br /&gt;
 Roman string is invalid&lt;br /&gt;
&lt;br /&gt;
===method_missing to log method calls&amp;lt;ref&amp;gt;http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2007/wiki1b_2_22&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Another application that makes use of method_missing could be a simple logger used for debugging purposes. Many times, it may be required to log the trace of called methods and provide information such as: called method-name, arguments, return type. It can be tedious to repeat this part of code in every method. A simple solution to this problem can be obtained using method_missing as:&lt;br /&gt;
&lt;br /&gt;
  class SimpleCallLogger&lt;br /&gt;
  def initialize(o)&lt;br /&gt;
  @obj = o&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(methodname, *args)&lt;br /&gt;
  puts &amp;quot;called: #{methodname}(#{args})&amp;quot;&lt;br /&gt;
  a = @obj.send(methodname, *args)&lt;br /&gt;
  puts &amp;quot;\t-&amp;gt; returned: #{a}&amp;quot;&lt;br /&gt;
  return a&lt;br /&gt;
  end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
This program makes use of method_missing in a way that it wraps around called method to output the logging information on entry and on exit, it logs the return type. Further, method_missing intercepts the method call and forward it to internal object with ‘send’ method of ruby. Hence, this use of method_missing acts as wrapper.&lt;br /&gt;
&lt;br /&gt;
===Generic Handler===&lt;br /&gt;
 class NoBar&lt;br /&gt;
 def method_missing(methodname, *args)&lt;br /&gt;
 define_method(:bar) if &amp;quot;bar&amp;quot; == methodname.to_s&lt;br /&gt;
 define_method(:nobar) if &amp;quot;nobar&amp;quot; == methodname.to_s&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This is an example of using method_missing as a generic handler to handle when a calling method is not exist. You can use missing_method to dynamically create a method at a runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Advantages of method_missing'''==&lt;br /&gt;
&lt;br /&gt;
*In addition to specifying the error messages for the undefined methods, method_missing provides a more dynamic behavior in the programming environment.&lt;br /&gt;
*If we are unfamiliar with the usage of the objects we created, then using method_missing is a good technique.&lt;br /&gt;
*Handles problems at runtime.&lt;br /&gt;
*Define's a generic method_missing and handle's any undefined method, a big advantage over Java. In Java, when you call an undefined method, the program will not compile.&lt;br /&gt;
*method_missing falls under the general technique of [http://en.wikipedia.org/wiki/Metaprogramming meta-programming]. Employ meta-programming in missing_function to write an another function to handle the call.&lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages of method_missing'''==	&lt;br /&gt;
*Slower than conventional method lookup. Simple tests indicate that method dispatch with method_missing is at least two to three times as expensive in time as conventional dispatch.&lt;br /&gt;
&lt;br /&gt;
*Since the methods being called never actually exist—they are just intercepted at the last step of the method lookup process—they cannot be documented or introspected as conventional methods can.&lt;br /&gt;
&lt;br /&gt;
*[http://blog.jayfields.com/2008/02/ruby-dynamically-define-method.html Dynamic methods] must go through the method_missing method, the body of that method can become quite large if there are many different aspects of the code that needs to add methods dynamically.&lt;br /&gt;
&lt;br /&gt;
*method_missing restricts compatibility with future versions of an [http://en.wikipedia.org/wiki/Application_programming_interface API]. Introducing new methods in a future API version can break users' expectations.&lt;br /&gt;
&lt;br /&gt;
=='''Key Points'''==&lt;br /&gt;
*Ruby knows method_missing( ) exisits, because it's a private instance method of 'BasicObject' that every object inherits. The BasicObject#method_missing( ) responds by raising the NoMethodError. Overriding this method_missing( ) allows you to call methods that don't really exist. &lt;br /&gt;
&lt;br /&gt;
*If method_missing is only looking for certain method names, don't forget to call the [http://en.wikibooks.org/wiki/Java_Programming/Keywords/super super] keyword if you haven't found what you're looking for, so that the other superclass' method_missing can handle it.&lt;br /&gt;
&lt;br /&gt;
*[http://www.prateekdayal.net/2007/10/16/rubys-responds_to-for-checking-if-a-method-exists/ obj.respond_to?] function returns 'true' if the obj responds to the given method. So if you want to know whether your class will respond to a function you can use respond_to? to know the answer. But if method_missing() is used, the output may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
*Below class A defines only method method_missing() and no other method. When a new object of class A tries to access a method say 'foo', the respond_to? will return the value 'false'. When you actually try to implement it using “a.foo”, the code will get executed, courtesy of method_missing(). Even though the respond_to? says that you cannot access 'foo' method using object of class A, if you have method_missing() defined, you can access the method.&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In method_missing&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)&lt;br /&gt;
 a.foo&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 false&lt;br /&gt;
 In method_missing&lt;br /&gt;
&lt;br /&gt;
*If within method_missing() we define an undefined method. &lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 @@i = 0&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In Method Missing #{@@i}&amp;quot;&lt;br /&gt;
 @@i += 1&lt;br /&gt;
 self.fun&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)	// just checking whether the receiver 'a' responds to the method 'foo'&lt;br /&gt;
				  &lt;br /&gt;
 a.foo &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 The expected result would be a 'stack level too deep' error. &lt;br /&gt;
&lt;br /&gt;
When the 'foo' method is called, after no method match the method_missing is run and this block has a method “self.fun” that is undefined. Here when the program execution encounters 'self.fun' it once again calls method_missing. This goes on in an endless loop till the stack memory is full.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
*http://www.rubyinside.com/ &lt;br /&gt;
*http://blog.jayfields.com/2008/02/ruby-replace-methodmissing-with-dynamic.html &lt;br /&gt;
*http://liquiddevelopment.blogspot.com/2006/04/twisting-and-shaping-dsls-using-ruby.html &lt;br /&gt;
*http://blog.rubybestpractices.com/posts/gregory/031-issue-2-method-lookup.html&lt;br /&gt;
*http://phrogz.net/RubyLibs/RubyMethodLookupFlow.pdf&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=63657</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w22 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=63657"/>
		<updated>2012-09-12T02:40:49Z</updated>

		<summary type="html">&lt;p&gt;Asheikh: /* converting numbers from roman representation to integer representationhttp://www.rubyquiz.com/quiz22.html */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''method_missing in Ruby:'''  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Introduction&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_method_missing.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
A method of a class is called by creating an object of the class and passing the method name to the object as a message. The object then looks up into its [http://www.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html method lookup path] and tries to match the called method with the defined methods in the class. On success, the method is executed along with the parameters passed and the result is returned.&lt;br /&gt;
&lt;br /&gt;
If the object does not find a match in its method lookup, in normal circumstances the [http://www.ruby-doc.org/core-1.9.3/NoMethodError.html NoMethodError Exception] is raised .&lt;br /&gt;
&lt;br /&gt;
“method_missing” is defined as a method in the class and is invoked if a called method is not found.&lt;br /&gt;
&lt;br /&gt;
=='''Format for defining method_missing'''==&lt;br /&gt;
&lt;br /&gt;
 =&amp;gt; def method_missing(m,*args,&amp;amp;block)&lt;br /&gt;
&lt;br /&gt;
(i) '''m-&amp;gt;''' accepts the symbol/name of the undefined method (ii) '''*args-&amp;gt;''' accepts the array of arguments passed in the method call  (iii) '''&amp;amp;block-&amp;gt;'''accepts a block passed to the method&lt;br /&gt;
&lt;br /&gt;
=='''Method Lookup Path'''==&lt;br /&gt;
The object of a class receives a method name to be executed, the following steps are carried out for matching and executing the method:&lt;br /&gt;
&lt;br /&gt;
*First, the object looks in its own [http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html instance methods].&lt;br /&gt;
*Second, it looks in the list of instance methods that all objects of that class share.&lt;br /&gt;
*Third, in each of the included [http://www.tutorialspoint.com/ruby/ruby_modules.html modules] of that class, in reverse order of inclusion. &lt;br /&gt;
*Fourth, it looks in that class’s superclass. &lt;br /&gt;
*Fifth, in the superclass’s included modules, all the way up until it reaches the class Object. &lt;br /&gt;
*Sixth, if it still can’t find a method, the very last place it looks is in the [http://linux.die.net/lkmpg/x40.html Kernel module], included in the class Object. &lt;br /&gt;
*Finally, it calls method_missing (if defined in the class), else throws up the NOMethodError exception.&lt;br /&gt;
&lt;br /&gt;
This entire tracing that the object does is the method lookup path.&lt;br /&gt;
&lt;br /&gt;
=='''Examples'''==&lt;br /&gt;
===Calling defined and undefined methods===&lt;br /&gt;
&lt;br /&gt;
 class A		// creating a class 'A'&lt;br /&gt;
 def say		// defining a method 'say'&lt;br /&gt;
 puts &amp;quot; say Hi &amp;quot; // body of method say&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Creating the object of the class&lt;br /&gt;
 &lt;br /&gt;
  a=A.new	       // object of the class&lt;br /&gt;
  =&amp;gt; #&amp;lt;A:0x2a082e0&amp;gt;     //object id&lt;br /&gt;
&lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.say                  // defined method&lt;br /&gt;
 =&amp;gt; say Hi	       // returned result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.sayhi                // undefined method sayhi&lt;br /&gt;
 NoMethodError: undefined method `sayhi' for #&amp;lt;A:0x2a082e0&amp;gt;   // the NoMethodError is raised&lt;br /&gt;
&lt;br /&gt;
===method_missing implementation&amp;lt;ref&amp;gt;http://www.thirdbit.net/articles/2007/08/01/10-things-you-should-know-about-method_missing/&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def say&lt;br /&gt;
 puts &amp;quot; say hi &amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(m,*args,&amp;amp;block)	// defining method_missing&lt;br /&gt;
 puts &amp;quot; This method does not exist&amp;quot;	// body of method_missing&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Calling a method that is not defined&lt;br /&gt;
 &lt;br /&gt;
 a=A.new&lt;br /&gt;
 a.sayhi                                // calling the undefined method sayhi with no arguments&lt;br /&gt;
 =&amp;gt; This method does not exist		// this result returned when method_missing is executed&lt;br /&gt;
&lt;br /&gt;
When the object 'a' traces its method lookup path for a matching method as 'sayhi', upon failure it resorts to method_missing and the body of method_missing is executed. 'method_missing' is the last resort.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Sometimes when a class has many methods that do generally the same kinds of things, and the programmer is not sure in advance which methods the user will call since there are so many of them, and they are all so similar, implementing all of them by hand seems futile. In these situations method_missing makes a new method that was previously not defined and adds it to the class. The below 'Generic Handler' example implements this.&lt;br /&gt;
&lt;br /&gt;
===passing parameters to an undefined method call===&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def add(a,b)&lt;br /&gt;
 a+b&lt;br /&gt;
 end&lt;br /&gt;
 def method_missing(name,*args,&amp;amp;block)    // the method_missing is defined and the *args parameter accepts all the parameters passed during 								                                 &lt;br /&gt;
                                             the method call   &lt;br /&gt;
 puts “You have typed the method name wrong and these were the parameters passed ; #{args[0]}, #{args[1]}”								&lt;br /&gt;
 end                         			&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The passed parameters are stored in the array 'args' and can be accessed like a normal array                &lt;br /&gt;
                                                   &lt;br /&gt;
 &lt;br /&gt;
Calling the defined method&lt;br /&gt;
&lt;br /&gt;
 a.add(1,2)		        // calling the defined method add and passing the parameters (1,2)&lt;br /&gt;
 =&amp;gt; 3                           // result&lt;br /&gt;
&lt;br /&gt;
Calling the undefined method&lt;br /&gt;
 &lt;br /&gt;
 a.adds(4,2) 			// calling the undefined method adds and passing the parameter (4,2)&lt;br /&gt;
 =&amp;gt; You have typed the method name wrong and these were the parameters passed; 4, 2&lt;br /&gt;
&lt;br /&gt;
The user made a genuine mistake by typing 'adds', but this method is not defined. When the 'adds' method with parameters is called, the object 'a' tries to match the method in the method lookup path. Upon failure it invokes method_missing, the args are passed, stored in the array 'args' and the body of method_missing is executed.&lt;br /&gt;
&lt;br /&gt;
===converting numbers from roman representation to integer representation&amp;lt;ref&amp;gt;http://www.rubyquiz.com/quiz22.html&amp;lt;/ref&amp;gt;===&lt;br /&gt;
 class Roman&lt;br /&gt;
 @@Roman_to_Numeric = {'i' =&amp;gt; 1, 'v' =&amp;gt; 5, 'x' =&amp;gt; 10, 'l' =&amp;gt; 50, 'c' =&amp;gt; 100, 'd' =&amp;gt; 500, 'm' =&amp;gt; 1000}   &lt;br /&gt;
 def method_missing(method_var,*args,&amp;amp;block)&lt;br /&gt;
 # code to convert from roman representation to integer representation&lt;br /&gt;
 &lt;br /&gt;
 numeric_value = 0&lt;br /&gt;
 roman_string = method_var.to_s.downcase&lt;br /&gt;
 for i in 0...roman_string.length-1&lt;br /&gt;
 if (cond) == nil&lt;br /&gt;
 else&lt;br /&gt;
 puts &amp;quot;Roman string is invalid&amp;quot;&lt;br /&gt;
 return&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 while roman_string != &amp;quot;&amp;quot;&lt;br /&gt;
 if roman_string[roman_string.length - 1] == 'x' &amp;amp;&amp;amp; roman_string[roman_string.length - 2] == 'i'&lt;br /&gt;
 numeric_value += 9&lt;br /&gt;
 roman_string.chop!&lt;br /&gt;
 roman_string.chop!&lt;br /&gt;
 elsif&lt;br /&gt;
 roman_string[roman_string.length - 1] == 'v' &amp;amp;&amp;amp; roman_string[roman_string.length - 2] == 'i'&lt;br /&gt;
 numeric_value += 4&lt;br /&gt;
 roman_string.chop!&lt;br /&gt;
 roman_string.chop!&lt;br /&gt;
 else&lt;br /&gt;
 numeric_value += @@Roman_to_Numeric[roman_string[(roman_string.length)-1]]&lt;br /&gt;
 roman_string.chop!&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 puts &amp;quot;Numeric Value for #{method_var} is: #{numeric_value}&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
'''cond''' = '''['''@@Roman_to_Numeric[roman_string[i]]-@@Roman_to_Numeric[roman_string[i+1]] == 0 || @@Roman_to_Numeric[roman_string[i]]-@@Roman _ to_                               Numeric [ roman _ string [ i + 1 ] ]  ==  - 9 || @@Roman_to_Numeric[roman_string[i]]-@@Roman_to_Numeric[roman_string[i+1]] == -4    ||    @@Roman_to_Numeric[roman_string[i]]-@@Roman_to_Numeric[roman_string[i+1]] &amp;gt;= 4) &amp;amp;&amp;amp; (/.v.x/ =~ roman_string''']'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calling the undefined methods&lt;br /&gt;
&lt;br /&gt;
 r= Roman.new&lt;br /&gt;
 r.vii&lt;br /&gt;
 r.iClx&lt;br /&gt;
 r.xxix&lt;br /&gt;
 r.xxxi&lt;br /&gt;
 r.xxiv&lt;br /&gt;
 r.xxvi&lt;br /&gt;
 r.vx&lt;br /&gt;
&lt;br /&gt;
The Output&lt;br /&gt;
&lt;br /&gt;
 Numeric Value for vii is: 7&lt;br /&gt;
 Roman string is invalid&lt;br /&gt;
 Numeric Value for xxix is: 29&lt;br /&gt;
 Numeric Value for xxxi is: 31&lt;br /&gt;
 Numeric Value for xxiv is: 24&lt;br /&gt;
 Numeric Value for xxvi is: 26&lt;br /&gt;
 Roman string is invalid&lt;br /&gt;
&lt;br /&gt;
===method_missing to log method calls&amp;lt;ref&amp;gt;http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2007/wiki1b_2_22&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Another application that makes use of method_missing could be a simple logger used for debugging purposes. Many times, it may be required to log the trace of called methods and provide information such as: called method-name, arguments, return type. It can be tedious to repeat this part of code in every method. A simple solution to this problem can be obtained using method_missing as:&lt;br /&gt;
&lt;br /&gt;
  class SimpleCallLogger&lt;br /&gt;
  def initialize(o)&lt;br /&gt;
  @obj = o&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(methodname, *args)&lt;br /&gt;
  puts &amp;quot;called: #{methodname}(#{args})&amp;quot;&lt;br /&gt;
  a = @obj.send(methodname, *args)&lt;br /&gt;
  puts &amp;quot;\t-&amp;gt; returned: #{a}&amp;quot;&lt;br /&gt;
  return a&lt;br /&gt;
  end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
This program makes use of method_missing in a way that it wraps around called method to output the logging information on entry and on exit, it logs the return type. Further, method_missing intercepts the method call and forward it to internal object with ‘send’ method of ruby. Hence, this use of method_missing acts as wrapper.&lt;br /&gt;
&lt;br /&gt;
===Generic Handler===&lt;br /&gt;
 class NoBar&lt;br /&gt;
 def method_missing(methodname, *args)&lt;br /&gt;
 define_method(:bar) if &amp;quot;bar&amp;quot; == methodname.to_s&lt;br /&gt;
 define_method(:nobar) if &amp;quot;nobar&amp;quot; == methodname.to_s&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This is an example of using method_missing as a generic handler to handle when a calling method is not exist. You can use missing_method to dynamically create a method at a runtime.&lt;br /&gt;
&lt;br /&gt;
=='''Advantages of method_missing'''==&lt;br /&gt;
&lt;br /&gt;
*In addition to specifying the error messages for the undefined methods, method_missing provides a more dynamic behavior in the programming environment.&lt;br /&gt;
*If we are unfamiliar with the usage of the objects we created, then using method_missing is a good technique.&lt;br /&gt;
*Handles problems at runtime.&lt;br /&gt;
*Define's a generic method_missing and handle's any undefined method, a big advantage over Java. In Java, when you call an undefined method, the program will not compile.&lt;br /&gt;
*method_missing falls under the general technique of [http://en.wikipedia.org/wiki/Metaprogramming meta-programming]. Employ meta-programming in missing_function to write an another function to handle the call.&lt;br /&gt;
&lt;br /&gt;
=='''Disadvantages of method_missing'''==	&lt;br /&gt;
*Slower than conventional method lookup. Simple tests indicate that method dispatch with method_missing is at least two to three times as expensive in time as conventional dispatch.&lt;br /&gt;
&lt;br /&gt;
*Since the methods being called never actually exist—they are just intercepted at the last step of the method lookup process—they cannot be documented or introspected as conventional methods can.&lt;br /&gt;
&lt;br /&gt;
*[http://blog.jayfields.com/2008/02/ruby-dynamically-define-method.html Dynamic methods] must go through the method_missing method, the body of that method can become quite large if there are many different aspects of the code that needs to add methods dynamically.&lt;br /&gt;
&lt;br /&gt;
*method_missing restricts compatibility with future versions of an [http://en.wikipedia.org/wiki/Application_programming_interface API]. Introducing new methods in a future API version can break users' expectations.&lt;br /&gt;
&lt;br /&gt;
=='''Key Points'''==&lt;br /&gt;
*Ruby knows method_missing( ) exisits, because it's a private instance method of 'BasicObject' that every object inherits. The BasicObject#method_missing( ) responds by raising the NoMethodError. Overriding this method_missing( ) allows you to call methods that don't really exist. &lt;br /&gt;
&lt;br /&gt;
*If method_missing is only looking for certain method names, don't forget to call the [http://en.wikibooks.org/wiki/Java_Programming/Keywords/super super] keyword if you haven't found what you're looking for, so that the other superclass' method_missing can handle it.&lt;br /&gt;
&lt;br /&gt;
*[http://www.prateekdayal.net/2007/10/16/rubys-responds_to-for-checking-if-a-method-exists/ obj.respond_to?] function returns 'true' if the obj responds to the given method. So if you want to know whether your class will respond to a function you can use respond_to? to know the answer. But if method_missing() is used, the output may not be what you expect.&lt;br /&gt;
&lt;br /&gt;
*Below class A defines only method method_missing() and no other method. When a new object of class A tries to access a method say 'foo', the respond_to? will return the value 'false'. When you actually try to implement it using “a.foo”, the code will get executed, courtesy of method_missing(). Even though the respond_to? says that you cannot access 'foo' method using object of class A, if you have method_missing() defined, you can access the method.&lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In method_missing&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)&lt;br /&gt;
 a.foo&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 false&lt;br /&gt;
 In method_missing&lt;br /&gt;
&lt;br /&gt;
*If within method_missing() we define an undefined method. &lt;br /&gt;
&lt;br /&gt;
 class A&lt;br /&gt;
 @@i = 0&lt;br /&gt;
 def method_missing(method_id)&lt;br /&gt;
 puts &amp;quot;In Method Missing #{@@i}&amp;quot;&lt;br /&gt;
 @@i += 1&lt;br /&gt;
 self.fun&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 a = A.new&lt;br /&gt;
 puts a.respond_to?(:foo)	// just checking whether the receiver 'a' responds to the method 'foo'&lt;br /&gt;
				  &lt;br /&gt;
 a.foo &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 The expected result would be a 'stack level too deep' error. &lt;br /&gt;
&lt;br /&gt;
When the 'foo' method is called, after no method match the method_missing is run and this block has a method “self.fun” that is undefined. Here when the program execution encounters 'self.fun' it once again calls method_missing. This goes on in an endless loop till the stack memory is full.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Further Suggested Reading'''==&lt;br /&gt;
*http://www.rubyinside.com/ &lt;br /&gt;
*http://blog.jayfields.com/2008/02/ruby-replace-methodmissing-with-dynamic.html &lt;br /&gt;
*http://liquiddevelopment.blogspot.com/2006/04/twisting-and-shaping-dsls-using-ruby.html &lt;br /&gt;
*http://blog.rubybestpractices.com/posts/gregory/031-issue-2-method-lookup.html&lt;br /&gt;
*http://phrogz.net/RubyLibs/RubyMethodLookupFlow.pdf&lt;/div&gt;</summary>
		<author><name>Asheikh</name></author>
	</entry>
</feed>