<?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=Nloya</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=Nloya"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Nloya"/>
	<updated>2026-08-23T17:19:51Z</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/ch2b_1w70_nl&amp;diff=71006</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 1w70 nl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_1w70_nl&amp;diff=71006"/>
		<updated>2012-11-20T01:16:54Z</updated>

		<summary type="html">&lt;p&gt;Nloya: /* Conclusion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;b&amp;gt;SaaS - 4.2 - SMART User Stories&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt;==&lt;br /&gt;
User stories are the basis for defining the functionality of any given system. They are a short description of the system that capture what the system does and gives the expectation of how the system should behave.&lt;br /&gt;
When we say User Stories, we don’t define any particular criteria as to how a user story should be written. A user story can be “Customer should have a good UI experience” or “When a customer logs in he/she should be able to see all the technical details of the product he/she has selected, with the reviews, price displayed alongside and an option of ‘Add to Cart’ to go along with it.”&lt;br /&gt;
Both the user stories described above are correct but one leaves too much for one to assume and the other gives one specific information in terms of display and functionality. The problem with the first user story is it is not restricted to any particular guideline, its just a user story but has no scope and hence can be either very short or very long. The advantage with the second user story is that it has been written based on a given set of goals which can be acronymed as SMART and will be explained below.&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;SMART User Stories&amp;lt;/b&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
SMART is a mnemonic for&amp;lt;br&amp;gt;&lt;br /&gt;
*S - Specific&lt;br /&gt;
*M - Measurable&lt;br /&gt;
*A - Achievable&lt;br /&gt;
*R - Relevant&lt;br /&gt;
*T- Timeboxed&lt;br /&gt;
&lt;br /&gt;
===S -Specific/ M - Measurable===&lt;br /&gt;
The user story should be specific enough to capture the requirements of the user. The user can be the customer who requires the software or the end user who will be using the software. Many times the user stories are vague or ambiguous leading to a lot of loss in time and energy spent in development.&lt;br /&gt;
User stories can be made specific by using the terms 'Given, When and Then' which describe the user story. The term “Given” specifies the background scenarios. It specifies all the preconditions.&lt;br /&gt;
“When” specifies the input  to the system. “Then” specifies the desired result/s.&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
   Given I am at www.google.com&lt;br /&gt;
   When I click on the button Gmail&lt;br /&gt;
   Then I should be redirected to Gmail.&lt;br /&gt;
Each scenario should be testable i.e its progress should be measurable.  There should be  known good output for every input. Every project needs concrete criteria for measuring progress toward its completion. The reason behind this is that if the scenarios are not measurable, it is not possible to know whether a team is making progress toward successful completion. Measuring progress is supposed to help a team stay on track, reach its target dates, and experience the exhilaration of achievement that spurs it on to continued effort required to reach the ultimate goal.&lt;br /&gt;
&lt;br /&gt;
===A - Achievable / T - Timeboxed===&lt;br /&gt;
Goals should be set in such a way that it is achievable or at least a working model of it is achievable within a single iteration i.e. within a given time period. The reason for this is that Agile methodologies always aim for working models at the end of iteration, it doesn’t necessarily have to be a complete feature but a run-down version of it which is working partially and is able to provide a minimal set of functionality is also accepted.&lt;br /&gt;
If the feature is such that it may span over multiple iterations then it is a good idea to break it up into subset of stories such that each implemented subset provides a working model of the feature, however small it may be, so that constant progress is made to implement the feature and also a working code is provided at the end of each iteration.&lt;br /&gt;
&lt;br /&gt;
While its a good idea to divide a feature into sub-features and have user stories for each iteration, the question arises of how to decide on the number of user stories for each iteration and the number of iterations that may require for the complete feature to be implemented. This is usually accomplished using velocity which is an estimate of the kind of progress made in the past based on the difficulty of the user stories and the kind of progress that can be made by taking into consideration the difficulty of the user stories that are yet to be implemented.&lt;br /&gt;
&lt;br /&gt;
As features are broken down to sub-features and stories are written for the sub-feature, which is to be completed within the iteration, points should be assigned to each of the stories based on the difficulty level of the story and how fine grained approach for point-assignment does an assigner want. Say for example an assigner wants just a simple approach for point-assignment then he/she can assign from a range of 1-3 (where 1 being easy, 2 being medium and 3 being hard) and if a more fine grained approach is required then the range can be increased to 1-5 or 1-10. Whatever the approach is followed the important thing is to allocate points to each of the stories based on one’s estimate. At the end of each iteration, Velocity is calculated, which is nothing but the total number of points completed per iteration. As Velocity is not just the total of the stories but the total based on the difficulty level of the stories, it acts as an important guiding tool which can be leveraged by anyone to get to know details about the project as is shown below.&lt;br /&gt;
&lt;br /&gt;
Uses of Velocity:&lt;br /&gt;
&lt;br /&gt;
*Velocity can be used to plan future iterations&lt;br /&gt;
*It gives an estimate of how much time or iterations would be required to completely implement the feature&lt;br /&gt;
*It gives an idea of whether the team is on track as the velocity is expected to remain constant if all other variables are unchanged (other variables such as number of team members or replacement of an experienced team member with a new team member, etc.)&lt;br /&gt;
*It can provide an estimate if a change is requested by customers and based on the time required to implement the change and the importance level of the change the decision can be made whether to implement it or not.&lt;br /&gt;
&lt;br /&gt;
Following this approach allows a task to be timeboxed, i.e. limited to a specific duration. It provides a kind of expectation which makes the team-members aware that if something is not working out its time to seek help, split the task, change teams or do anything that will help in the completion of the task.&lt;br /&gt;
&lt;br /&gt;
At the initial phase, the task of assigning points to stories may seem a bit daunting and a bit like second guessing oneself but as the iterations pass on and based on the understanding of the feature and the experience one has in assigning points to user-stories, the estimation will always improve and at the end will be very close to the actual statistics. Also estimates can be changed if one feels an incorrect estimation was done but care should be taken that the variation is not too much.&lt;br /&gt;
&lt;br /&gt;
===R- business Relevant===&lt;br /&gt;
A user story should be of business value, i.e it should generate additional income or protect revenue. The software defined by the user story can increase the value of the product by generating interest among new users and thereby generating potential new customers.A software can also protect revenue by  streamlining processes to cut costs.&lt;br /&gt;
One way of determining the business relevance of a product is by asking the question “why” recursively. This is similar to a problem solving technique called  “5 Whys” where questions asked recursively for root cause analysis. The methodology can be extended here to recursively ask why developing a software is of business relevance to that company. It is assumed that after asking multiple times the reason will have some business relevance (for eg  “To increase in revenue for the company”) or there is no valid reason justifying the software project. &lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;Example&amp;lt;/b&amp;gt;==&lt;br /&gt;
Let us understand SMART User Stories by taking an example:&lt;br /&gt;
&lt;br /&gt;
   I want an application that shows me the best deals.&lt;br /&gt;
&lt;br /&gt;
There are all sorts of problems with the above user story. It doesn't fit any of the criterion we have set using our SMART User Stories approach. Let’s go over with each of the problems and try to improve our user story step-by-step.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;S-Specific / M-Measurable&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The above example is anything but specific nor it seems measurable. Well it does say that there needs to be an application that shows the best deals but it doesn't mention to display the best deals from which all places or websites. Also it doesn't mention about what it wants the best deals on. Also as it doesn't mention about the websites it is difficult it to measure the story.&lt;br /&gt;
&lt;br /&gt;
A much better user story would have been:&amp;lt;br&amp;gt;&lt;br /&gt;
   I want an application that shows the user the best deals on a particular product, which is entered by the user before beginning &amp;lt;br&amp;gt; the search, from the websites that preselected by the user.&lt;br /&gt;
&lt;br /&gt;
This says specifically on what product the user wants the search on and from which all websites. This is a very specific goal as there is no scope of assumption here. Of course the search results will be based on the specific words the user enters, but that is true for any website. The more specific you are in your search the more fine grained your search will be. Also because of the modified story, now it is easy to measure the story, as we can go through each website and compare prices and check whether the application did indeed return the best deals from various websites.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;A-Achievable&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Appropriate timelines and deadlines should be set for implementing and testing the application. Suppose the client wants the above application for the Thanksgiving sale and he comes and asks for it during midweek of November, then creating the above story at that time wouldn’t be useful or advisable as the time period is too short for the goal to achieve.&lt;br /&gt;
&lt;br /&gt;
Assuming there is sufficient time for the application to be created and there are say 4 iterations possible. But the above story may not be practical for one iteration, one might need to break it down further to make it workable for 1 iteration as the target is to have a workable code at the end of each iteration. So the story for the particular iteration can be modified as:&lt;br /&gt;
&lt;br /&gt;
   Provide an interface for the user to provide the name of the product and the websites he/she wants to have a search in.&lt;br /&gt;
&lt;br /&gt;
This would be achievable for the first iteration. For the second iteration more functionality may be added:&lt;br /&gt;
&lt;br /&gt;
   Look for the price of the product in all of the websites given by the user and fetch all the results.&lt;br /&gt;
&lt;br /&gt;
This can be further modified in iteration 3 to give the best deal, based on price factor. This can be further modified to modify the result if any free goodies are being provided by any particular website. In this way the goal can be made achievable.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;T-Timeboxed&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
All of the above 4 iterations that we planned should have the deadlines appropriately. If we suppose till one particular date if the team-member responsible for developing one particular functionality is not able to reach the target goal, it might be a good idea for him/her to ask to someone else or for some senior member to help out or to swap teams itself so that someone who has knowledge can work on that and can complete it without affecting the deadlines and making sure that the product is still workable at the end of that particular iteration. This should be followed for all the iterations. This will also allow sufficient time for testing which is a very important part of the application development.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;R-Relevant&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The story should be relevant so that the desired benefit can be obtained and maximized. Why would the client need it&lt;br /&gt;
*Probably because there are many websites which offer different deals and to get a single website which searches all the websites on behalf of the user or at least a subset of the websites would make it much easier for the user&lt;br /&gt;
*That will also lead to increase in the clicks the website gets&lt;br /&gt;
*Which will subsequently lead to increase in ads&lt;br /&gt;
*Which will lead to increase in revenue for the company&lt;br /&gt;
&lt;br /&gt;
Now the above goals are relevant for the application that user wants but it may not be relevant for the Terms and Conditions page or the login page that application may have.&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;Advantages/Disadvantages of SMART User stories&amp;lt;/b&amp;gt;==&lt;br /&gt;
===Advantages of SMART User stories===&lt;br /&gt;
Lets consider the advantages of SMART User stories by considering each letter of the mnemonic.&lt;br /&gt;
*Making a user story &amp;lt;i&amp;gt;specific&amp;lt;/i&amp;gt; makes the objectives of the project clear and prevent confusion amongst teams&lt;br /&gt;
*Having a well defined input/output relation makes the project &amp;lt;i&amp;gt;measurable&amp;lt;/i&amp;gt;/&amp;lt;i&amp;gt;testable&amp;lt;/i&amp;gt; for bugs and defects.&lt;br /&gt;
*Having a specific user story helps breaking the project down to &amp;lt;i&amp;gt;achievable&amp;lt;/i&amp;gt; goals. These goals can be accomplished in single or multiple iterations.&lt;br /&gt;
*Asking whether a project is business &amp;lt;i&amp;gt;relevant&amp;lt;/i&amp;gt; helps in identifying the maximum potential of the project.&lt;br /&gt;
*A &amp;lt;i&amp;gt;timeboxed&amp;lt;/i&amp;gt; project helps in monitoring the progress of the project. It is also possible to estimate the velocity of the project using timeboxing.&lt;br /&gt;
&lt;br /&gt;
===Disadvantages/Limitations of SMART User Stories===&lt;br /&gt;
&lt;br /&gt;
*Some people prefer other kind of mnemonics such as INVEST rather than SMART as they feel that the thing that SMART stands for is not the same for all people. S may stand for Specific for some, Significant for some, Stretching for others, similarly M may be Measurable or Meaningful, likewise each of the alphabet of SMART has different meaning for different people.&lt;br /&gt;
*It is important that points assignment to user stories is done by someone experienced enough to understand the features that customers require as well as the complexity and technical details required to implement it successfully otherwise the velocity will be far from what is expected.&lt;br /&gt;
==&amp;lt;b&amp;gt;Conclusion&amp;lt;/b&amp;gt;==&lt;br /&gt;
SMART User stories are a great way of defining goals as they have parameters on which to base the decision but for some they are not too specific, primarily because each of the letter of the acronym holds different meaning for different people.&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
[http://www.youtube.com/watch?v=XzV0dytYQq0 SaaS 4.2: SMART User stories]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://uxdesign.smashingmagazine.com/2011/09/13/the-s-m-a-r-t-user-experience-strategy/ SMART User experience strategy]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://xp123.com/articles/invest-in-good-stories-and-smart-tasks/ INVEST in good stories and SMART Tasks]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.chiefsimplicityofficer.com/2010/04/user-stories-its-smart-to-invest/ User stories: Its SMART to INVEST]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;See Also&amp;lt;/b&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/User_story Information on user stories]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://gigaom.com/2008/05/05/how-to-create-smart-tasks/ Information on SMART tasks]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.uncommon-knowledge.co.uk/goal_setting/smart_4.html Information on SMART goals]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/5_Whys Link for 5 Whys]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Nloya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_1w70_nl&amp;diff=71000</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 1w70 nl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_1w70_nl&amp;diff=71000"/>
		<updated>2012-11-20T01:12:42Z</updated>

		<summary type="html">&lt;p&gt;Nloya: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;b&amp;gt;SaaS - 4.2 - SMART User Stories&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt;==&lt;br /&gt;
User stories are the basis for defining the functionality of any given system. They are a short description of the system that capture what the system does and gives the expectation of how the system should behave.&lt;br /&gt;
When we say User Stories, we don’t define any particular criteria as to how a user story should be written. A user story can be “Customer should have a good UI experience” or “When a customer logs in he/she should be able to see all the technical details of the product he/she has selected, with the reviews, price displayed alongside and an option of ‘Add to Cart’ to go along with it.”&lt;br /&gt;
Both the user stories described above are correct but one leaves too much for one to assume and the other gives one specific information in terms of display and functionality. The problem with the first user story is it is not restricted to any particular guideline, its just a user story but has no scope and hence can be either very short or very long. The advantage with the second user story is that it has been written based on a given set of goals which can be acronymed as SMART and will be explained below.&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;SMART User Stories&amp;lt;/b&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
SMART is a mnemonic for&amp;lt;br&amp;gt;&lt;br /&gt;
*S - Specific&lt;br /&gt;
*M - Measurable&lt;br /&gt;
*A - Achievable&lt;br /&gt;
*R - Relevant&lt;br /&gt;
*T- Timeboxed&lt;br /&gt;
&lt;br /&gt;
===S -Specific/ M - Measurable===&lt;br /&gt;
The user story should be specific enough to capture the requirements of the user. The user can be the customer who requires the software or the end user who will be using the software. Many times the user stories are vague or ambiguous leading to a lot of loss in time and energy spent in development.&lt;br /&gt;
User stories can be made specific by using the terms 'Given, When and Then' which describe the user story. The term “Given” specifies the background scenarios. It specifies all the preconditions.&lt;br /&gt;
“When” specifies the input  to the system. “Then” specifies the desired result/s.&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
   Given I am at www.google.com&lt;br /&gt;
   When I click on the button Gmail&lt;br /&gt;
   Then I should be redirected to Gmail.&lt;br /&gt;
Each scenario should be testable i.e its progress should be measurable.  There should be  known good output for every input. Every project needs concrete criteria for measuring progress toward its completion. The reason behind this is that if the scenarios are not measurable, it is not possible to know whether a team is making progress toward successful completion. Measuring progress is supposed to help a team stay on track, reach its target dates, and experience the exhilaration of achievement that spurs it on to continued effort required to reach the ultimate goal.&lt;br /&gt;
&lt;br /&gt;
===A - Achievable / T - Timeboxed===&lt;br /&gt;
Goals should be set in such a way that it is achievable or at least a working model of it is achievable within a single iteration i.e. within a given time period. The reason for this is that Agile methodologies always aim for working models at the end of iteration, it doesn’t necessarily have to be a complete feature but a run-down version of it which is working partially and is able to provide a minimal set of functionality is also accepted.&lt;br /&gt;
If the feature is such that it may span over multiple iterations then it is a good idea to break it up into subset of stories such that each implemented subset provides a working model of the feature, however small it may be, so that constant progress is made to implement the feature and also a working code is provided at the end of each iteration.&lt;br /&gt;
&lt;br /&gt;
While its a good idea to divide a feature into sub-features and have user stories for each iteration, the question arises of how to decide on the number of user stories for each iteration and the number of iterations that may require for the complete feature to be implemented. This is usually accomplished using velocity which is an estimate of the kind of progress made in the past based on the difficulty of the user stories and the kind of progress that can be made by taking into consideration the difficulty of the user stories that are yet to be implemented.&lt;br /&gt;
&lt;br /&gt;
As features are broken down to sub-features and stories are written for the sub-feature, which is to be completed within the iteration, points should be assigned to each of the stories based on the difficulty level of the story and how fine grained approach for point-assignment does an assigner want. Say for example an assigner wants just a simple approach for point-assignment then he/she can assign from a range of 1-3 (where 1 being easy, 2 being medium and 3 being hard) and if a more fine grained approach is required then the range can be increased to 1-5 or 1-10. Whatever the approach is followed the important thing is to allocate points to each of the stories based on one’s estimate. At the end of each iteration, Velocity is calculated, which is nothing but the total number of points completed per iteration. As Velocity is not just the total of the stories but the total based on the difficulty level of the stories, it acts as an important guiding tool which can be leveraged by anyone to get to know details about the project as is shown below.&lt;br /&gt;
&lt;br /&gt;
Uses of Velocity:&lt;br /&gt;
&lt;br /&gt;
*Velocity can be used to plan future iterations&lt;br /&gt;
*It gives an estimate of how much time or iterations would be required to completely implement the feature&lt;br /&gt;
*It gives an idea of whether the team is on track as the velocity is expected to remain constant if all other variables are unchanged (other variables such as number of team members or replacement of an experienced team member with a new team member, etc.)&lt;br /&gt;
*It can provide an estimate if a change is requested by customers and based on the time required to implement the change and the importance level of the change the decision can be made whether to implement it or not.&lt;br /&gt;
&lt;br /&gt;
Following this approach allows a task to be timeboxed, i.e. limited to a specific duration. It provides a kind of expectation which makes the team-members aware that if something is not working out its time to seek help, split the task, change teams or do anything that will help in the completion of the task.&lt;br /&gt;
&lt;br /&gt;
At the initial phase, the task of assigning points to stories may seem a bit daunting and a bit like second guessing oneself but as the iterations pass on and based on the understanding of the feature and the experience one has in assigning points to user-stories, the estimation will always improve and at the end will be very close to the actual statistics. Also estimates can be changed if one feels an incorrect estimation was done but care should be taken that the variation is not too much.&lt;br /&gt;
&lt;br /&gt;
===R- business Relevant===&lt;br /&gt;
A user story should be of business value, i.e it should generate additional income or protect revenue. The software defined by the user story can increase the value of the product by generating interest among new users and thereby generating potential new customers.A software can also protect revenue by  streamlining processes to cut costs.&lt;br /&gt;
One way of determining the business relevance of a product is by asking the question “why” recursively. This is similar to a problem solving technique called  “5 Whys” where questions asked recursively for root cause analysis. The methodology can be extended here to recursively ask why developing a software is of business relevance to that company. It is assumed that after asking multiple times the reason will have some business relevance (for eg  “To increase in revenue for the company”) or there is no valid reason justifying the software project. &lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;Example&amp;lt;/b&amp;gt;==&lt;br /&gt;
Let us understand SMART User Stories by taking an example:&lt;br /&gt;
&lt;br /&gt;
   I want an application that shows me the best deals.&lt;br /&gt;
&lt;br /&gt;
There are all sorts of problems with the above user story. It doesn't fit any of the criterion we have set using our SMART User Stories approach. Let’s go over with each of the problems and try to improve our user story step-by-step.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;S-Specific / M-Measurable&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The above example is anything but specific nor it seems measurable. Well it does say that there needs to be an application that shows the best deals but it doesn't mention to display the best deals from which all places or websites. Also it doesn't mention about what it wants the best deals on. Also as it doesn't mention about the websites it is difficult it to measure the story.&lt;br /&gt;
&lt;br /&gt;
A much better user story would have been:&amp;lt;br&amp;gt;&lt;br /&gt;
   I want an application that shows the user the best deals on a particular product, which is entered by the user before beginning &amp;lt;br&amp;gt; the search, from the websites that preselected by the user.&lt;br /&gt;
&lt;br /&gt;
This says specifically on what product the user wants the search on and from which all websites. This is a very specific goal as there is no scope of assumption here. Of course the search results will be based on the specific words the user enters, but that is true for any website. The more specific you are in your search the more fine grained your search will be. Also because of the modified story, now it is easy to measure the story, as we can go through each website and compare prices and check whether the application did indeed return the best deals from various websites.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;A-Achievable&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Appropriate timelines and deadlines should be set for implementing and testing the application. Suppose the client wants the above application for the Thanksgiving sale and he comes and asks for it during midweek of November, then creating the above story at that time wouldn’t be useful or advisable as the time period is too short for the goal to achieve.&lt;br /&gt;
&lt;br /&gt;
Assuming there is sufficient time for the application to be created and there are say 4 iterations possible. But the above story may not be practical for one iteration, one might need to break it down further to make it workable for 1 iteration as the target is to have a workable code at the end of each iteration. So the story for the particular iteration can be modified as:&lt;br /&gt;
&lt;br /&gt;
   Provide an interface for the user to provide the name of the product and the websites he/she wants to have a search in.&lt;br /&gt;
&lt;br /&gt;
This would be achievable for the first iteration. For the second iteration more functionality may be added:&lt;br /&gt;
&lt;br /&gt;
   Look for the price of the product in all of the websites given by the user and fetch all the results.&lt;br /&gt;
&lt;br /&gt;
This can be further modified in iteration 3 to give the best deal, based on price factor. This can be further modified to modify the result if any free goodies are being provided by any particular website. In this way the goal can be made achievable.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;T-Timeboxed&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
All of the above 4 iterations that we planned should have the deadlines appropriately. If we suppose till one particular date if the team-member responsible for developing one particular functionality is not able to reach the target goal, it might be a good idea for him/her to ask to someone else or for some senior member to help out or to swap teams itself so that someone who has knowledge can work on that and can complete it without affecting the deadlines and making sure that the product is still workable at the end of that particular iteration. This should be followed for all the iterations. This will also allow sufficient time for testing which is a very important part of the application development.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;R-Relevant&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The story should be relevant so that the desired benefit can be obtained and maximized. Why would the client need it&lt;br /&gt;
*Probably because there are many websites which offer different deals and to get a single website which searches all the websites on behalf of the user or at least a subset of the websites would make it much easier for the user&lt;br /&gt;
*That will also lead to increase in the clicks the website gets&lt;br /&gt;
*Which will subsequently lead to increase in ads&lt;br /&gt;
*Which will lead to increase in revenue for the company&lt;br /&gt;
&lt;br /&gt;
Now the above goals are relevant for the application that user wants but it may not be relevant for the Terms and Conditions page or the login page that application may have.&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;Advantages/Disadvantages of SMART User stories&amp;lt;/b&amp;gt;==&lt;br /&gt;
===Advantages of SMART User stories===&lt;br /&gt;
Lets consider the advantages of SMART User stories by considering each letter of the mnemonic.&lt;br /&gt;
*Making a user story &amp;lt;i&amp;gt;specific&amp;lt;/i&amp;gt; makes the objectives of the project clear and prevent confusion amongst teams&lt;br /&gt;
*Having a well defined input/output relation makes the project &amp;lt;i&amp;gt;measurable&amp;lt;/i&amp;gt;/&amp;lt;i&amp;gt;testable&amp;lt;/i&amp;gt; for bugs and defects.&lt;br /&gt;
*Having a specific user story helps breaking the project down to &amp;lt;i&amp;gt;achievable&amp;lt;/i&amp;gt; goals. These goals can be accomplished in single or multiple iterations.&lt;br /&gt;
*Asking whether a project is business &amp;lt;i&amp;gt;relevant&amp;lt;/i&amp;gt; helps in identifying the maximum potential of the project.&lt;br /&gt;
*A &amp;lt;i&amp;gt;timeboxed&amp;lt;/i&amp;gt; project helps in monitoring the progress of the project. It is also possible to estimate the velocity of the project using timeboxing.&lt;br /&gt;
&lt;br /&gt;
===Disadvantages/Limitations of SMART User Stories===&lt;br /&gt;
&lt;br /&gt;
*Some people prefer other kind of mnemonics such as INVEST rather than SMART as they feel that the thing that SMART stands for is not the same for all people. S may stand for Specific for some, Significant for some, Stretching for others, similarly M may be Measurable or Meaningful, likewise each of the alphabet of SMART has different meaning for different people.&lt;br /&gt;
*It is important that points assignment to user stories is done by someone experienced enough to understand the features that customers require as well as the complexity and technical details required to implement it successfully otherwise the velocity will be far from what is expected.&lt;br /&gt;
==&amp;lt;b&amp;gt;Conclusion&amp;lt;/b&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
[http://www.youtube.com/watch?v=XzV0dytYQq0 SaaS 4.2: SMART User stories]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://uxdesign.smashingmagazine.com/2011/09/13/the-s-m-a-r-t-user-experience-strategy/ SMART User experience strategy]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://xp123.com/articles/invest-in-good-stories-and-smart-tasks/ INVEST in good stories and SMART Tasks]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.chiefsimplicityofficer.com/2010/04/user-stories-its-smart-to-invest/ User stories: Its SMART to INVEST]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;See Also&amp;lt;/b&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/User_story Information on user stories]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://gigaom.com/2008/05/05/how-to-create-smart-tasks/ Information on SMART tasks]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.uncommon-knowledge.co.uk/goal_setting/smart_4.html Information on SMART goals]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/5_Whys Link for 5 Whys]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Nloya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_1w70_nl&amp;diff=70999</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 1w70 nl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_1w70_nl&amp;diff=70999"/>
		<updated>2012-11-20T01:11:06Z</updated>

		<summary type="html">&lt;p&gt;Nloya: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;b&amp;gt;SaaS - 4.2 - SMART User Stories&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt;==&lt;br /&gt;
User stories are the basis for defining the functionality of any given system. They are a short description of the system that capture what the system does and gives the expectation of how the system should behave.&lt;br /&gt;
When we say User Stories, we don’t define any particular criteria as to how a user story should be written. A user story can be “Customer should have a good UI experience” or “When a customer logs in he/she should be able to see all the technical details of the product he/she has selected, with the reviews, price displayed alongside and an option of ‘Add to Cart’ to go along with it.”&lt;br /&gt;
Both the user stories described above are correct but one leaves too much for one to assume and the other gives one specific information in terms of display and functionality. The problem with the first user story is it is not restricted to any particular guideline, its just a user story but has no scope and hence can be either very short or very long. The advantage with the second user story is that it has been written based on a given set of goals which can be acronymed as SMART and will be explained below.&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;SMART User Stories&amp;lt;/b&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
SMART is a mnemonic for&amp;lt;br&amp;gt;&lt;br /&gt;
*S - Specific&lt;br /&gt;
*M - Measurable&lt;br /&gt;
*A - Achievable&lt;br /&gt;
*R - Relevant&lt;br /&gt;
*T- Timeboxed&lt;br /&gt;
&lt;br /&gt;
===S -Specific/ M - Measurable===&lt;br /&gt;
The user story should be specific enough to capture the requirements of the user. The user can be the customer who requires the software or the end user who will be using the software. Many times the user stories are vague or ambiguous leading to a lot of loss in time and energy spent in development.&lt;br /&gt;
User stories can be made specific by using the terms 'Given, When and Then' which describe the user story. The term “Given” specifies the background scenarios. It specifies all the preconditions.&lt;br /&gt;
“When” specifies the input  to the system. “Then” specifies the desired result/s.&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
   Given I am at www.google.com&lt;br /&gt;
   When I click on the button Gmail&lt;br /&gt;
   Then I should be redirected to Gmail.&lt;br /&gt;
Each scenario should be testable i.e its progress should be measurable.  There should be  known good output for every input. Every project needs concrete criteria for measuring progress toward its completion. The reason behind this is that if the scenarios are not measurable, it is not possible to know whether a team is making progress toward successful completion. Measuring progress is supposed to help a team stay on track, reach its target dates, and experience the exhilaration of achievement that spurs it on to continued effort required to reach the ultimate goal.&lt;br /&gt;
&lt;br /&gt;
===A - Achievable / T - Timeboxed===&lt;br /&gt;
Goals should be set in such a way that it is achievable or at least a working model of it is achievable within a single iteration i.e. within a given time period. The reason for this is that Agile methodologies always aim for working models at the end of iteration, it doesn’t necessarily have to be a complete feature but a run-down version of it which is working partially and is able to provide a minimal set of functionality is also accepted.&lt;br /&gt;
If the feature is such that it may span over multiple iterations then it is a good idea to break it up into subset of stories such that each implemented subset provides a working model of the feature, however small it may be, so that constant progress is made to implement the feature and also a working code is provided at the end of each iteration.&lt;br /&gt;
&lt;br /&gt;
While its a good idea to divide a feature into sub-features and have user stories for each iteration, the question arises of how to decide on the number of user stories for each iteration and the number of iterations that may require for the complete feature to be implemented. This is usually accomplished using velocity which is an estimate of the kind of progress made in the past based on the difficulty of the user stories and the kind of progress that can be made by taking into consideration the difficulty of the user stories that are yet to be implemented.&lt;br /&gt;
&lt;br /&gt;
As features are broken down to sub-features and stories are written for the sub-feature, which is to be completed within the iteration, points should be assigned to each of the stories based on the difficulty level of the story and how fine grained approach for point-assignment does an assigner want. Say for example an assigner wants just a simple approach for point-assignment then he/she can assign from a range of 1-3 (where 1 being easy, 2 being medium and 3 being hard) and if a more fine grained approach is required then the range can be increased to 1-5 or 1-10. Whatever the approach is followed the important thing is to allocate points to each of the stories based on one’s estimate. At the end of each iteration, Velocity is calculated, which is nothing but the total number of points completed per iteration. As Velocity is not just the total of the stories but the total based on the difficulty level of the stories, it acts as an important guiding tool which can be leveraged by anyone to get to know details about the project as is shown below.&lt;br /&gt;
&lt;br /&gt;
Uses of Velocity:&lt;br /&gt;
&lt;br /&gt;
*Velocity can be used to plan future iterations&lt;br /&gt;
*It gives an estimate of how much time or iterations would be required to completely implement the feature&lt;br /&gt;
*It gives an idea of whether the team is on track as the velocity is expected to remain constant if all other variables are unchanged (other variables such as number of team members or replacement of an experienced team member with a new team member, etc.)&lt;br /&gt;
*It can provide an estimate if a change is requested by customers and based on the time required to implement the change and the importance level of the change the decision can be made whether to implement it or not.&lt;br /&gt;
&lt;br /&gt;
Following this approach allows a task to be timeboxed, i.e. limited to a specific duration. It provides a kind of expectation which makes the team-members aware that if something is not working out its time to seek help, split the task, change teams or do anything that will help in the completion of the task.&lt;br /&gt;
&lt;br /&gt;
At the initial phase, the task of assigning points to stories may seem a bit daunting and a bit like second guessing oneself but as the iterations pass on and based on the understanding of the feature and the experience one has in assigning points to user-stories, the estimation will always improve and at the end will be very close to the actual statistics. Also estimates can be changed if one feels an incorrect estimation was done but care should be taken that the variation is not too much.&lt;br /&gt;
&lt;br /&gt;
===R- business Relevant===&lt;br /&gt;
A user story should be of business value, i.e it should generate additional income or protect revenue. The software defined by the user story can increase the value of the product by generating interest among new users and thereby generating potential new customers.A software can also protect revenue by  streamlining processes to cut costs.&lt;br /&gt;
One way of determining the business relevance of a product is by asking the question “why” recursively. This is similar to a problem solving technique called  “5 Whys” where questions asked recursively for root cause analysis. The methodology can be extended here to recursively ask why developing a software is of business relevance to that company. It is assumed that after asking multiple times the reason will have some business relevance (for eg  “To increase in revenue for the company”) or there is no valid reason justifying the software project. &lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;Example&amp;lt;/b&amp;gt;==&lt;br /&gt;
Let us understand SMART User Stories by taking an example:&lt;br /&gt;
&lt;br /&gt;
   I want an application that shows me the best deals.&lt;br /&gt;
&lt;br /&gt;
There are all sorts of problems with the above user story. It doesn't fit any of the criterion we have set using our SMART User Stories approach. Let’s go over with each of the problems and try to improve our user story step-by-step.&lt;br /&gt;
&lt;br /&gt;
S-Specific / M-Measurable:&amp;lt;br&amp;gt;&lt;br /&gt;
The above example is anything but specific nor it seems measurable. Well it does say that there needs to be an application that shows the best deals but it doesn't mention to display the best deals from which all places or websites. Also it doesn't mention about what it wants the best deals on. Also as it doesn't mention about the websites it is difficult it to measure the story.&lt;br /&gt;
&lt;br /&gt;
A much better user story would have been:&amp;lt;br&amp;gt;&lt;br /&gt;
   I want an application that shows the user the best deals on a particular product, which is entered by the user before beginning &amp;lt;br&amp;gt; the search, from the websites that preselected by the user.&lt;br /&gt;
&lt;br /&gt;
This says specifically on what product the user wants the search on and from which all websites. This is a very specific goal as there is no scope of assumption here. Of course the search results will be based on the specific words the user enters, but that is true for any website. The more specific you are in your search the more fine grained your search will be. Also because of the modified story, now it is easy to measure the story, as we can go through each website and compare prices and check whether the application did indeed return the best deals from various websites.&lt;br /&gt;
&lt;br /&gt;
A-Achievable:&amp;lt;br&amp;gt;&lt;br /&gt;
Appropriate timelines and deadlines should be set for implementing and testing the application. Suppose the client wants the above application for the Thanksgiving sale and he comes and asks for it during midweek of November, then creating the above story at that time wouldn’t be useful or advisable as the time period is too short for the goal to achieve.&lt;br /&gt;
&lt;br /&gt;
Assuming there is sufficient time for the application to be created and there are say 4 iterations possible. But the above story may not be practical for one iteration, one might need to break it down further to make it workable for 1 iteration as the target is to have a workable code at the end of each iteration. So the story for the particular iteration can be modified as:&lt;br /&gt;
&lt;br /&gt;
   Provide an interface for the user to provide the name of the product and the websites he/she wants to have a search in.&lt;br /&gt;
&lt;br /&gt;
This would be achievable for the first iteration. For the second iteration more functionality may be added:&lt;br /&gt;
&lt;br /&gt;
   Look for the price of the product in all of the websites given by the user and fetch all the results.&lt;br /&gt;
&lt;br /&gt;
This can be further modified in iteration 3 to give the best deal, based on price factor. This can be further modified to modify the result if any free goodies are being provided by any particular website. In this way the goal can be made achievable.&lt;br /&gt;
&lt;br /&gt;
T-Timeboxed&amp;lt;br&amp;gt;&lt;br /&gt;
All of the above 4 iterations that we planned should have the deadlines appropriately. If we suppose till one particular date if the team-member responsible for developing one particular functionality is not able to reach the target goal, it might be a good idea for him/her to ask to someone else or for some senior member to help out or to swap teams itself so that someone who has knowledge can work on that and can complete it without affecting the deadlines and making sure that the product is still workable at the end of that particular iteration. This should be followed for all the iterations. This will also allow sufficient time for testing which is a very important part of the application development.&lt;br /&gt;
&lt;br /&gt;
R-Relevant&amp;lt;br&amp;gt;&lt;br /&gt;
The story should be relevant so that the desired benefit can be obtained and maximized. Why would the client need it&lt;br /&gt;
*Probably because there are many websites which offer different deals and to get a single website which searches all the websites on behalf of the user or at least a subset of the websites would make it much easier for the user&lt;br /&gt;
*That will also lead to increase in the clicks the website gets&lt;br /&gt;
*Which will subsequently lead to increase in ads&lt;br /&gt;
*Which will lead to increase in revenue for the company&lt;br /&gt;
&lt;br /&gt;
Now the above goals are relevant for the application that user wants but it may not be relevant for the Terms and Conditions page or the login page that application may have.&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;Advantages/Disadvantages of SMART User stories&amp;lt;/b&amp;gt;==&lt;br /&gt;
===Advantages of SMART User stories===&lt;br /&gt;
Lets consider the advantages of SMART User stories by considering each letter of the mnemonic.&lt;br /&gt;
*Making a user story &amp;lt;i&amp;gt;specific&amp;lt;/i&amp;gt; makes the objectives of the project clear and prevent confusion amongst teams&lt;br /&gt;
*Having a well defined input/output relation makes the project &amp;lt;i&amp;gt;measurable&amp;lt;/i&amp;gt;/&amp;lt;i&amp;gt;testable&amp;lt;/i&amp;gt; for bugs and defects.&lt;br /&gt;
*Having a specific user story helps breaking the project down to &amp;lt;i&amp;gt;achievable&amp;lt;/i&amp;gt; goals. These goals can be accomplished in single or multiple iterations.&lt;br /&gt;
*Asking whether a project is business &amp;lt;i&amp;gt;relevant&amp;lt;/i&amp;gt; helps in identifying the maximum potential of the project.&lt;br /&gt;
*A &amp;lt;i&amp;gt;timeboxed&amp;lt;/i&amp;gt; project helps in monitoring the progress of the project. It is also possible to estimate the velocity of the project using timeboxing.&lt;br /&gt;
&lt;br /&gt;
===Disadvantages/Limitations of SMART User Stories===&lt;br /&gt;
&lt;br /&gt;
*Some people prefer other kind of mnemonics such as INVEST rather than SMART as they feel that the thing that SMART stands for is not the same for all people. S may stand for Specific for some, Significant for some, Stretching for others, similarly M may be Measurable or Meaningful, likewise each of the alphabet of SMART has different meaning for different people.&lt;br /&gt;
*It is important that points assignment to user stories is done by someone experienced enough to understand the features that customers require as well as the complexity and technical details required to implement it successfully otherwise the velocity will be far from what is expected.&lt;br /&gt;
==&amp;lt;b&amp;gt;Conclusion&amp;lt;/b&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
[http://www.youtube.com/watch?v=XzV0dytYQq0 SaaS 4.2: SMART User stories]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://uxdesign.smashingmagazine.com/2011/09/13/the-s-m-a-r-t-user-experience-strategy/ SMART User experience strategy]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://xp123.com/articles/invest-in-good-stories-and-smart-tasks/ INVEST in good stories and SMART Tasks]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.chiefsimplicityofficer.com/2010/04/user-stories-its-smart-to-invest/ User stories: Its SMART to INVEST]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;See Also&amp;lt;/b&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/User_story Information on user stories]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://gigaom.com/2008/05/05/how-to-create-smart-tasks/ Information on SMART tasks]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.uncommon-knowledge.co.uk/goal_setting/smart_4.html Information on SMART goals]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/5_Whys Link for 5 Whys]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Nloya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_1w70_nl&amp;diff=70997</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 1w70 nl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_1w70_nl&amp;diff=70997"/>
		<updated>2012-11-20T01:10:04Z</updated>

		<summary type="html">&lt;p&gt;Nloya: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;b&amp;gt;SaaS - 4.2 - SMART User Stories&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt;==&lt;br /&gt;
User stories are the basis for defining the functionality of any given system. They are a short description of the system that capture what the system does and gives the expectation of how the system should behave.&lt;br /&gt;
When we say User Stories, we don’t define any particular criteria as to how a user story should be written. A user story can be “Customer should have a good UI experience” or “When a customer logs in he/she should be able to see all the technical details of the product he/she has selected, with the reviews, price displayed alongside and an option of ‘Add to Cart’ to go along with it.”&lt;br /&gt;
Both the user stories described above are correct but one leaves too much for one to assume and the other gives one specific information in terms of display and functionality. The problem with the first user story is it is not restricted to any particular guideline, its just a user story but has no scope and hence can be either very short or very long. The advantage with the second user story is that it has been written based on a given set of goals which can be acronymed as SMART and will be explained below.&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;SMART User Stories&amp;lt;/b&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
SMART is a mnemonic for&amp;lt;br&amp;gt;&lt;br /&gt;
*S - Specific&lt;br /&gt;
*M - Measurable&lt;br /&gt;
*A - Achievable&lt;br /&gt;
*R - Relevant&lt;br /&gt;
*T- Timeboxed&lt;br /&gt;
&lt;br /&gt;
===S -Specific/ M - Measurable===&lt;br /&gt;
The user story should be specific enough to capture the requirements of the user. The user can be the customer who requires the software or the end user who will be using the software. Many times the user stories are vague or ambiguous leading to a lot of loss in time and energy spent in development.&lt;br /&gt;
User stories can be made specific by using the terms 'Given, When and Then' which describe the user story. The term “Given” specifies the background scenarios. It specifies all the preconditions.&lt;br /&gt;
“When” specifies the input  to the system. “Then” specifies the desired result/s.&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
   Given I am at www.google.com&lt;br /&gt;
   When I click on the button Gmail&lt;br /&gt;
   Then I should be redirected to Gmail.&lt;br /&gt;
Each scenario should be testable i.e its progress should be measurable.  There should be  known good output for every input. Every project needs concrete criteria for measuring progress toward its completion. The reason behind this is that if the scenarios are not measurable, it is not possible to know whether a team is making progress toward successful completion. Measuring progress is supposed to help a team stay on track, reach its target dates, and experience the exhilaration of achievement that spurs it on to continued effort required to reach the ultimate goal.&lt;br /&gt;
&lt;br /&gt;
===A - Achievable / T - Timeboxed===&lt;br /&gt;
Goals should be set in such a way that it is achievable or at least a working model of it is achievable within a single iteration i.e. within a given time period. The reason for this is that Agile methodologies always aim for working models at the end of iteration, it doesn’t necessarily have to be a complete feature but a run-down version of it which is working partially and is able to provide a minimal set of functionality is also accepted.&lt;br /&gt;
If the feature is such that it may span over multiple iterations then it is a good idea to break it up into subset of stories such that each implemented subset provides a working model of the feature, however small it may be, so that constant progress is made to implement the feature and also a working code is provided at the end of each iteration.&lt;br /&gt;
&lt;br /&gt;
While its a good idea to divide a feature into sub-features and have user stories for each iteration, the question arises of how to decide on the number of user stories for each iteration and the number of iterations that may require for the complete feature to be implemented. This is usually accomplished using velocity which is an estimate of the kind of progress made in the past based on the difficulty of the user stories and the kind of progress that can be made by taking into consideration the difficulty of the user stories that are yet to be implemented.&lt;br /&gt;
&lt;br /&gt;
As features are broken down to sub-features and stories are written for the sub-feature, which is to be completed within the iteration, points should be assigned to each of the stories based on the difficulty level of the story and how fine grained approach for point-assignment does an assigner want. Say for example an assigner wants just a simple approach for point-assignment then he/she can assign from a range of 1-3 (where 1 being easy, 2 being medium and 3 being hard) and if a more fine grained approach is required then the range can be increased to 1-5 or 1-10. Whatever the approach is followed the important thing is to allocate points to each of the stories based on one’s estimate. At the end of each iteration, Velocity is calculated, which is nothing but the total number of points completed per iteration. As Velocity is not just the total of the stories but the total based on the difficulty level of the stories, it acts as an important guiding tool which can be leveraged by anyone to get to know details about the project as is shown below.&lt;br /&gt;
&lt;br /&gt;
Uses of Velocity:&lt;br /&gt;
&lt;br /&gt;
*Velocity can be used to plan future iterations&lt;br /&gt;
*It gives an estimate of how much time or iterations would be required to completely implement the feature&lt;br /&gt;
*It gives an idea of whether the team is on track as the velocity is expected to remain constant if all other variables are unchanged (other variables such as number of team members or replacement of an experienced team member with a new team member, etc.)&lt;br /&gt;
*It can provide an estimate if a change is requested by customers and based on the time required to implement the change and the importance level of the change the decision can be made whether to implement it or not.&lt;br /&gt;
&lt;br /&gt;
Following this approach allows a task to be timeboxed, i.e. limited to a specific duration. It provides a kind of expectation which makes the team-members aware that if something is not working out its time to seek help, split the task, change teams or do anything that will help in the completion of the task.&lt;br /&gt;
&lt;br /&gt;
At the initial phase, the task of assigning points to stories may seem a bit daunting and a bit like second guessing oneself but as the iterations pass on and based on the understanding of the feature and the experience one has in assigning points to user-stories, the estimation will always improve and at the end will be very close to the actual statistics. Also estimates can be changed if one feels an incorrect estimation was done but care should be taken that the variation is not too much.&lt;br /&gt;
&lt;br /&gt;
===R- business Relevant===&lt;br /&gt;
A user story should be of business value, i.e it should generate additional income or protect revenue. The software defined by the user story can increase the value of the product by generating interest among new users and thereby generating potential new customers.A software can also protect revenue by  streamlining processes to cut costs.&lt;br /&gt;
One way of determining the business relevance of a product is by asking the question “why” recursively. This is similar to a problem solving technique called  “5 Whys” where questions asked recursively for root cause analysis. The methodology can be extended here to recursively ask why developing a software is of business relevance to that company. It is assumed that after asking multiple times the reason will have some business relevance (for eg  “To increase in revenue for the company”) or there is no valid reason justifying the software project. &lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;Example&amp;lt;/b&amp;gt;==&lt;br /&gt;
Let us understand SMART User Stories by taking an example:&lt;br /&gt;
&lt;br /&gt;
   I want an application that shows me the best deals.&lt;br /&gt;
&lt;br /&gt;
There are all sorts of problems with the above user story. It doesn't fit any of the criterion we have set using our SMART User Stories approach. Let’s go over with each of the problems and try to improve our user story step-by-step.&lt;br /&gt;
&lt;br /&gt;
S-Specific / M-Measurable:&amp;lt;br&amp;gt;&lt;br /&gt;
The above example is anything but specific nor it seems measurable. Well it does say that there needs to be an application that shows the best deals but it doesn't mention to display the best deals from which all places or websites. Also it doesn't mention about what it wants the best deals on. Also as it doesn't mention about the websites it is difficult it to measure the story.&lt;br /&gt;
&lt;br /&gt;
A much better user story would have been:&amp;lt;br&amp;gt;&lt;br /&gt;
   I want an application that shows the user the best deals on a particular product, which is entered by the user before &amp;lt;br&amp;gt; beginning the search, from the websites that preselected by the user.&lt;br /&gt;
&lt;br /&gt;
This says specifically on what product the user wants the search on and from which all websites. This is a very specific goal as there is no scope of assumption here. Of course the search results will be based on the specific words the user enters, but that is true for any website. The more specific you are in your search the more fine grained your search will be. Also because of the modified story, now it is easy to measure the story, as we can go through each website and compare prices and check whether the application did indeed return the best deals from various websites.&lt;br /&gt;
&lt;br /&gt;
A-Achievable:&amp;lt;br&amp;gt;&lt;br /&gt;
Appropriate timelines and deadlines should be set for implementing and testing the application. Suppose the client wants the above application for the Thanksgiving sale and he comes and asks for it during midweek of November, then creating the above story at that time wouldn’t be useful or advisable as the time period is too short for the goal to achieve.&lt;br /&gt;
&lt;br /&gt;
Assuming there is sufficient time for the application to be created and there are say 4 iterations possible. But the above story may not be practical for one iteration, one might need to break it down further to make it workable for 1 iteration as the target is to have a workable code at the end of each iteration. So the story for the particular iteration can be modified as:&lt;br /&gt;
&lt;br /&gt;
   Provide an interface for the user to provide the name of the product and the websites he/she wants to have a search in.&lt;br /&gt;
&lt;br /&gt;
This would be achievable for the first iteration. For the second iteration more functionality may be added:&lt;br /&gt;
&lt;br /&gt;
   Look for the price of the product in all of the websites given by the user and fetch all the results.&lt;br /&gt;
&lt;br /&gt;
This can be further modified in iteration 3 to give the best deal, based on price factor. This can be further modified to modify the result if any free goodies are being provided by any particular website. In this way the goal can be made achievable.&lt;br /&gt;
&lt;br /&gt;
T-Timeboxed&amp;lt;br&amp;gt;&lt;br /&gt;
All of the above 4 iterations that we planned should have the deadlines appropriately. If we suppose till one particular date if the team-member responsible for developing one particular functionality is not able to reach the target goal, it might be a good idea for him/her to ask to someone else or for some senior member to help out or to swap teams itself so that someone who has knowledge can work on that and can complete it without affecting the deadlines and making sure that the product is still workable at the end of that particular iteration. This should be followed for all the iterations. This will also allow sufficient time for testing which is a very important part of the application development.&lt;br /&gt;
&lt;br /&gt;
R-Relevant&amp;lt;br&amp;gt;&lt;br /&gt;
The story should be relevant so that the desired benefit can be obtained and maximized. Why would the client need it&lt;br /&gt;
*Probably because there are many websites which offer different deals and to get a single website which searches all the websites on behalf of the user or at least a subset of the websites would make it much easier for the user&lt;br /&gt;
*That will also lead to increase in the clicks the website gets&lt;br /&gt;
*Which will subsequently lead to increase in ads&lt;br /&gt;
*Which will lead to increase in revenue for the company&lt;br /&gt;
&lt;br /&gt;
Now the above goals are relevant for the application that user wants but it may not be relevant for the Terms and Conditions page or the login page that application may have.&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;Advantages/Disadvantages of SMART User stories&amp;lt;/b&amp;gt;==&lt;br /&gt;
===Advantages of SMART User stories===&lt;br /&gt;
Lets consider the advantages of SMART User stories by considering each letter of the mnemonic.&lt;br /&gt;
*Making a user story &amp;lt;i&amp;gt;specific&amp;lt;/i&amp;gt; makes the objectives of the project clear and prevent confusion amongst teams&lt;br /&gt;
*Having a well defined input/output relation makes the project &amp;lt;i&amp;gt;measurable&amp;lt;/i&amp;gt;/&amp;lt;i&amp;gt;testable&amp;lt;/i&amp;gt; for bugs and defects.&lt;br /&gt;
*Having a specific user story helps breaking the project down to &amp;lt;i&amp;gt;achievable&amp;lt;/i&amp;gt; goals. These goals can be accomplished in single or multiple iterations.&lt;br /&gt;
*Asking whether a project is business &amp;lt;i&amp;gt;relevant&amp;lt;/i&amp;gt; helps in identifying the maximum potential of the project.&lt;br /&gt;
*A &amp;lt;i&amp;gt;timeboxed&amp;lt;/i&amp;gt; project helps in monitoring the progress of the project. It is also possible to estimate the velocity of the project using timeboxing.&lt;br /&gt;
&lt;br /&gt;
===Disadvantages/Limitations of SMART User Stories===&lt;br /&gt;
&lt;br /&gt;
*Some people prefer other kind of mnemonics such as INVEST rather than SMART as they feel that the thing that SMART stands for is not the same for all people. S may stand for Specific for some, Significant for some, Stretching for others, similarly M may be Measurable or Meaningful, likewise each of the alphabet of SMART has different meaning for different people.&lt;br /&gt;
*It is important that points assignment to user stories is done by someone experienced enough to understand the features that customers require as well as the complexity and technical details required to implement it successfully otherwise the velocity will be far from what is expected.&lt;br /&gt;
==&amp;lt;b&amp;gt;Conclusion&amp;lt;/b&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
[http://www.youtube.com/watch?v=XzV0dytYQq0 SaaS 4.2: SMART User stories]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://uxdesign.smashingmagazine.com/2011/09/13/the-s-m-a-r-t-user-experience-strategy/ SMART User experience strategy]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://xp123.com/articles/invest-in-good-stories-and-smart-tasks/ INVEST in good stories and SMART Tasks]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.chiefsimplicityofficer.com/2010/04/user-stories-its-smart-to-invest/ User stories: Its SMART to INVEST]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;See Also&amp;lt;/b&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/User_story Information on user stories]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://gigaom.com/2008/05/05/how-to-create-smart-tasks/ Information on SMART tasks]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.uncommon-knowledge.co.uk/goal_setting/smart_4.html Information on SMART goals]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/5_Whys Link for 5 Whys]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Nloya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_1w70_nl&amp;diff=70996</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 1w70 nl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_1w70_nl&amp;diff=70996"/>
		<updated>2012-11-20T01:09:39Z</updated>

		<summary type="html">&lt;p&gt;Nloya: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;b&amp;gt;SaaS - 4.2 - SMART User Stories&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt;==&lt;br /&gt;
User stories are the basis for defining the functionality of any given system. They are a short description of the system that capture what the system does and gives the expectation of how the system should behave.&lt;br /&gt;
When we say User Stories, we don’t define any particular criteria as to how a user story should be written. A user story can be “Customer should have a good UI experience” or “When a customer logs in he/she should be able to see all the technical details of the product he/she has selected, with the reviews, price displayed alongside and an option of ‘Add to Cart’ to go along with it.”&lt;br /&gt;
Both the user stories described above are correct but one leaves too much for one to assume and the other gives one specific information in terms of display and functionality. The problem with the first user story is it is not restricted to any particular guideline, its just a user story but has no scope and hence can be either very short or very long. The advantage with the second user story is that it has been written based on a given set of goals which can be acronymed as SMART and will be explained below.&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;SMART User Stories&amp;lt;/b&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
SMART is a mnemonic for&amp;lt;br&amp;gt;&lt;br /&gt;
*S - Specific&lt;br /&gt;
*M - Measurable&lt;br /&gt;
*A - Achievable&lt;br /&gt;
*R - Relevant&lt;br /&gt;
*T- Timeboxed&lt;br /&gt;
&lt;br /&gt;
===S -Specific/ M - Measurable===&lt;br /&gt;
The user story should be specific enough to capture the requirements of the user. The user can be the customer who requires the software or the end user who will be using the software. Many times the user stories are vague or ambiguous leading to a lot of loss in time and energy spent in development.&lt;br /&gt;
User stories can be made specific by using the terms 'Given, When and Then' which describe the user story. The term “Given” specifies the background scenarios. It specifies all the preconditions.&lt;br /&gt;
“When” specifies the input  to the system. “Then” specifies the desired result/s.&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
   Given I am at www.google.com&lt;br /&gt;
   When I click on the button Gmail&lt;br /&gt;
   Then I should be redirected to Gmail.&lt;br /&gt;
Each scenario should be testable i.e its progress should be measurable.  There should be  known good output for every input. Every project needs concrete criteria for measuring progress toward its completion. The reason behind this is that if the scenarios are not measurable, it is not possible to know whether a team is making progress toward successful completion. Measuring progress is supposed to help a team stay on track, reach its target dates, and experience the exhilaration of achievement that spurs it on to continued effort required to reach the ultimate goal.&lt;br /&gt;
&lt;br /&gt;
===A - Achievable / T - Timeboxed===&lt;br /&gt;
Goals should be set in such a way that it is achievable or at least a working model of it is achievable within a single iteration i.e. within a given time period. The reason for this is that Agile methodologies always aim for working models at the end of iteration, it doesn’t necessarily have to be a complete feature but a run-down version of it which is working partially and is able to provide a minimal set of functionality is also accepted.&lt;br /&gt;
If the feature is such that it may span over multiple iterations then it is a good idea to break it up into subset of stories such that each implemented subset provides a working model of the feature, however small it may be, so that constant progress is made to implement the feature and also a working code is provided at the end of each iteration.&lt;br /&gt;
&lt;br /&gt;
While its a good idea to divide a feature into sub-features and have user stories for each iteration, the question arises of how to decide on the number of user stories for each iteration and the number of iterations that may require for the complete feature to be implemented. This is usually accomplished using velocity which is an estimate of the kind of progress made in the past based on the difficulty of the user stories and the kind of progress that can be made by taking into consideration the difficulty of the user stories that are yet to be implemented.&lt;br /&gt;
&lt;br /&gt;
As features are broken down to sub-features and stories are written for the sub-feature, which is to be completed within the iteration, points should be assigned to each of the stories based on the difficulty level of the story and how fine grained approach for point-assignment does an assigner want. Say for example an assigner wants just a simple approach for point-assignment then he/she can assign from a range of 1-3 (where 1 being easy, 2 being medium and 3 being hard) and if a more fine grained approach is required then the range can be increased to 1-5 or 1-10. Whatever the approach is followed the important thing is to allocate points to each of the stories based on one’s estimate. At the end of each iteration, Velocity is calculated, which is nothing but the total number of points completed per iteration. As Velocity is not just the total of the stories but the total based on the difficulty level of the stories, it acts as an important guiding tool which can be leveraged by anyone to get to know details about the project as is shown below.&lt;br /&gt;
&lt;br /&gt;
Uses of Velocity:&lt;br /&gt;
&lt;br /&gt;
*Velocity can be used to plan future iterations&lt;br /&gt;
*It gives an estimate of how much time or iterations would be required to completely implement the feature&lt;br /&gt;
*It gives an idea of whether the team is on track as the velocity is expected to remain constant if all other variables are unchanged (other variables such as number of team members or replacement of an experienced team member with a new team member, etc.)&lt;br /&gt;
*It can provide an estimate if a change is requested by customers and based on the time required to implement the change and the importance level of the change the decision can be made whether to implement it or not.&lt;br /&gt;
&lt;br /&gt;
Following this approach allows a task to be timeboxed, i.e. limited to a specific duration. It provides a kind of expectation which makes the team-members aware that if something is not working out its time to seek help, split the task, change teams or do anything that will help in the completion of the task.&lt;br /&gt;
&lt;br /&gt;
At the initial phase, the task of assigning points to stories may seem a bit daunting and a bit like second guessing oneself but as the iterations pass on and based on the understanding of the feature and the experience one has in assigning points to user-stories, the estimation will always improve and at the end will be very close to the actual statistics. Also estimates can be changed if one feels an incorrect estimation was done but care should be taken that the variation is not too much.&lt;br /&gt;
&lt;br /&gt;
===R- business Relevant===&lt;br /&gt;
A user story should be of business value, i.e it should generate additional income or protect revenue. The software defined by the user story can increase the value of the product by generating interest among new users and thereby generating potential new customers.A software can also protect revenue by  streamlining processes to cut costs.&lt;br /&gt;
One way of determining the business relevance of a product is by asking the question “why” recursively. This is similar to a problem solving technique called  “5 Whys” where questions asked recursively for root cause analysis. The methodology can be extended here to recursively ask why developing a software is of business relevance to that company. It is assumed that after asking multiple times the reason will have some business relevance (for eg  “To increase in revenue for the company”) or there is no valid reason justifying the software project. &lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;Example&amp;lt;/b&amp;gt;==&lt;br /&gt;
Let us understand SMART User Stories by taking an example:&lt;br /&gt;
&lt;br /&gt;
   I want an application that shows me the best deals.&lt;br /&gt;
&lt;br /&gt;
There are all sorts of problems with the above user story. It doesn't fit any of the criterion we have set using our SMART User Stories approach. Let’s go over with each of the problems and try to improve our user story step-by-step.&lt;br /&gt;
&lt;br /&gt;
S-Specific / M-Measurable:&amp;lt;br&amp;gt;&lt;br /&gt;
The above example is anything but specific nor it seems measurable. Well it does say that there needs to be an application that shows the best deals but it doesn't mention to display the best deals from which all places or websites. Also it doesn't mention about what it wants the best deals on. Also as it doesn't mention about the websites it is difficult it to measure the story.&lt;br /&gt;
&lt;br /&gt;
A much better user story would have been:&amp;lt;br&amp;gt;&lt;br /&gt;
   I want an application that shows the user the best deals on a particular product, which is entered by the user before beginning the search, &amp;lt;br&amp;gt; from the websites that preselected by the user.&lt;br /&gt;
&lt;br /&gt;
This says specifically on what product the user wants the search on and from which all websites. This is a very specific goal as there is no scope of assumption here. Of course the search results will be based on the specific words the user enters, but that is true for any website. The more specific you are in your search the more fine grained your search will be. Also because of the modified story, now it is easy to measure the story, as we can go through each website and compare prices and check whether the application did indeed return the best deals from various websites.&lt;br /&gt;
&lt;br /&gt;
A-Achievable:&amp;lt;br&amp;gt;&lt;br /&gt;
Appropriate timelines and deadlines should be set for implementing and testing the application. Suppose the client wants the above application for the Thanksgiving sale and he comes and asks for it during midweek of November, then creating the above story at that time wouldn’t be useful or advisable as the time period is too short for the goal to achieve.&lt;br /&gt;
&lt;br /&gt;
Assuming there is sufficient time for the application to be created and there are say 4 iterations possible. But the above story may not be practical for one iteration, one might need to break it down further to make it workable for 1 iteration as the target is to have a workable code at the end of each iteration. So the story for the particular iteration can be modified as:&lt;br /&gt;
&lt;br /&gt;
   Provide an interface for the user to provide the name of the product and the websites he/she wants to have a search in.&lt;br /&gt;
&lt;br /&gt;
This would be achievable for the first iteration. For the second iteration more functionality may be added:&lt;br /&gt;
&lt;br /&gt;
   Look for the price of the product in all of the websites given by the user and fetch all the results.&lt;br /&gt;
&lt;br /&gt;
This can be further modified in iteration 3 to give the best deal, based on price factor. This can be further modified to modify the result if any free goodies are being provided by any particular website. In this way the goal can be made achievable.&lt;br /&gt;
&lt;br /&gt;
T-Timeboxed&amp;lt;br&amp;gt;&lt;br /&gt;
All of the above 4 iterations that we planned should have the deadlines appropriately. If we suppose till one particular date if the team-member responsible for developing one particular functionality is not able to reach the target goal, it might be a good idea for him/her to ask to someone else or for some senior member to help out or to swap teams itself so that someone who has knowledge can work on that and can complete it without affecting the deadlines and making sure that the product is still workable at the end of that particular iteration. This should be followed for all the iterations. This will also allow sufficient time for testing which is a very important part of the application development.&lt;br /&gt;
&lt;br /&gt;
R-Relevant&amp;lt;br&amp;gt;&lt;br /&gt;
The story should be relevant so that the desired benefit can be obtained and maximized. Why would the client need it&lt;br /&gt;
*Probably because there are many websites which offer different deals and to get a single website which searches all the websites on behalf of the user or at least a subset of the websites would make it much easier for the user&lt;br /&gt;
*That will also lead to increase in the clicks the website gets&lt;br /&gt;
*Which will subsequently lead to increase in ads&lt;br /&gt;
*Which will lead to increase in revenue for the company&lt;br /&gt;
&lt;br /&gt;
Now the above goals are relevant for the application that user wants but it may not be relevant for the Terms and Conditions page or the login page that application may have.&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;Advantages/Disadvantages of SMART User stories&amp;lt;/b&amp;gt;==&lt;br /&gt;
===Advantages of SMART User stories===&lt;br /&gt;
Lets consider the advantages of SMART User stories by considering each letter of the mnemonic.&lt;br /&gt;
*Making a user story &amp;lt;i&amp;gt;specific&amp;lt;/i&amp;gt; makes the objectives of the project clear and prevent confusion amongst teams&lt;br /&gt;
*Having a well defined input/output relation makes the project &amp;lt;i&amp;gt;measurable&amp;lt;/i&amp;gt;/&amp;lt;i&amp;gt;testable&amp;lt;/i&amp;gt; for bugs and defects.&lt;br /&gt;
*Having a specific user story helps breaking the project down to &amp;lt;i&amp;gt;achievable&amp;lt;/i&amp;gt; goals. These goals can be accomplished in single or multiple iterations.&lt;br /&gt;
*Asking whether a project is business &amp;lt;i&amp;gt;relevant&amp;lt;/i&amp;gt; helps in identifying the maximum potential of the project.&lt;br /&gt;
*A &amp;lt;i&amp;gt;timeboxed&amp;lt;/i&amp;gt; project helps in monitoring the progress of the project. It is also possible to estimate the velocity of the project using timeboxing.&lt;br /&gt;
&lt;br /&gt;
===Disadvantages/Limitations of SMART User Stories===&lt;br /&gt;
&lt;br /&gt;
*Some people prefer other kind of mnemonics such as INVEST rather than SMART as they feel that the thing that SMART stands for is not the same for all people. S may stand for Specific for some, Significant for some, Stretching for others, similarly M may be Measurable or Meaningful, likewise each of the alphabet of SMART has different meaning for different people.&lt;br /&gt;
*It is important that points assignment to user stories is done by someone experienced enough to understand the features that customers require as well as the complexity and technical details required to implement it successfully otherwise the velocity will be far from what is expected.&lt;br /&gt;
==&amp;lt;b&amp;gt;Conclusion&amp;lt;/b&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
[http://www.youtube.com/watch?v=XzV0dytYQq0 SaaS 4.2: SMART User stories]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://uxdesign.smashingmagazine.com/2011/09/13/the-s-m-a-r-t-user-experience-strategy/ SMART User experience strategy]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://xp123.com/articles/invest-in-good-stories-and-smart-tasks/ INVEST in good stories and SMART Tasks]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.chiefsimplicityofficer.com/2010/04/user-stories-its-smart-to-invest/ User stories: Its SMART to INVEST]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;See Also&amp;lt;/b&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/User_story Information on user stories]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://gigaom.com/2008/05/05/how-to-create-smart-tasks/ Information on SMART tasks]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.uncommon-knowledge.co.uk/goal_setting/smart_4.html Information on SMART goals]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/5_Whys Link for 5 Whys]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Nloya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_1w70_nl&amp;diff=70994</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 1w70 nl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_1w70_nl&amp;diff=70994"/>
		<updated>2012-11-20T01:08:43Z</updated>

		<summary type="html">&lt;p&gt;Nloya: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;b&amp;gt;SaaS - 4.2 - SMART User Stories&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt;==&lt;br /&gt;
User stories are the basis for defining the functionality of any given system. They are a short description of the system that capture what the system does and gives the expectation of how the system should behave.&lt;br /&gt;
When we say User Stories, we don’t define any particular criteria as to how a user story should be written. A user story can be “Customer should have a good UI experience” or “When a customer logs in he/she should be able to see all the technical details of the product he/she has selected, with the reviews, price displayed alongside and an option of ‘Add to Cart’ to go along with it.”&lt;br /&gt;
Both the user stories described above are correct but one leaves too much for one to assume and the other gives one specific information in terms of display and functionality. The problem with the first user story is it is not restricted to any particular guideline, its just a user story but has no scope and hence can be either very short or very long. The advantage with the second user story is that it has been written based on a given set of goals which can be acronymed as SMART and will be explained below.&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;SMART User Stories&amp;lt;/b&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
SMART is a mnemonic for&amp;lt;br&amp;gt;&lt;br /&gt;
*S - Specific&lt;br /&gt;
*M - Measurable&lt;br /&gt;
*A - Achievable&lt;br /&gt;
*R - Relevant&lt;br /&gt;
*T- Timeboxed&lt;br /&gt;
&lt;br /&gt;
===S -Specific/ M - Measurable===&lt;br /&gt;
The user story should be specific enough to capture the requirements of the user. The user can be the customer who requires the software or the end user who will be using the software. Many times the user stories are vague or ambiguous leading to a lot of loss in time and energy spent in development.&lt;br /&gt;
User stories can be made specific by using the terms 'Given, When and Then' which describe the user story. The term “Given” specifies the background scenarios. It specifies all the preconditions.&lt;br /&gt;
“When” specifies the input  to the system. “Then” specifies the desired result/s.&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
   Given I am at www.google.com&lt;br /&gt;
   When I click on the button Gmail&lt;br /&gt;
   Then I should be redirected to Gmail.&lt;br /&gt;
Each scenario should be testable i.e its progress should be measurable.  There should be  known good output for every input. Every project needs concrete criteria for measuring progress toward its completion. The reason behind this is that if the scenarios are not measurable, it is not possible to know whether a team is making progress toward successful completion. Measuring progress is supposed to help a team stay on track, reach its target dates, and experience the exhilaration of achievement that spurs it on to continued effort required to reach the ultimate goal.&lt;br /&gt;
&lt;br /&gt;
===A - Achievable / T - Timeboxed===&lt;br /&gt;
Goals should be set in such a way that it is achievable or at least a working model of it is achievable within a single iteration i.e. within a given time period. The reason for this is that Agile methodologies always aim for working models at the end of iteration, it doesn’t necessarily have to be a complete feature but a run-down version of it which is working partially and is able to provide a minimal set of functionality is also accepted.&lt;br /&gt;
If the feature is such that it may span over multiple iterations then it is a good idea to break it up into subset of stories such that each implemented subset provides a working model of the feature, however small it may be, so that constant progress is made to implement the feature and also a working code is provided at the end of each iteration.&lt;br /&gt;
&lt;br /&gt;
While its a good idea to divide a feature into sub-features and have user stories for each iteration, the question arises of how to decide on the number of user stories for each iteration and the number of iterations that may require for the complete feature to be implemented. This is usually accomplished using velocity which is an estimate of the kind of progress made in the past based on the difficulty of the user stories and the kind of progress that can be made by taking into consideration the difficulty of the user stories that are yet to be implemented.&lt;br /&gt;
&lt;br /&gt;
As features are broken down to sub-features and stories are written for the sub-feature, which is to be completed within the iteration, points should be assigned to each of the stories based on the difficulty level of the story and how fine grained approach for point-assignment does an assigner want. Say for example an assigner wants just a simple approach for point-assignment then he/she can assign from a range of 1-3 (where 1 being easy, 2 being medium and 3 being hard) and if a more fine grained approach is required then the range can be increased to 1-5 or 1-10. Whatever the approach is followed the important thing is to allocate points to each of the stories based on one’s estimate. At the end of each iteration, Velocity is calculated, which is nothing but the total number of points completed per iteration. As Velocity is not just the total of the stories but the total based on the difficulty level of the stories, it acts as an important guiding tool which can be leveraged by anyone to get to know details about the project as is shown below.&lt;br /&gt;
&lt;br /&gt;
Uses of Velocity:&lt;br /&gt;
&lt;br /&gt;
*Velocity can be used to plan future iterations&lt;br /&gt;
*It gives an estimate of how much time or iterations would be required to completely implement the feature&lt;br /&gt;
*It gives an idea of whether the team is on track as the velocity is expected to remain constant if all other variables are unchanged (other variables such as number of team members or replacement of an experienced team member with a new team member, etc.)&lt;br /&gt;
*It can provide an estimate if a change is requested by customers and based on the time required to implement the change and the importance level of the change the decision can be made whether to implement it or not.&lt;br /&gt;
&lt;br /&gt;
Following this approach allows a task to be timeboxed, i.e. limited to a specific duration. It provides a kind of expectation which makes the team-members aware that if something is not working out its time to seek help, split the task, change teams or do anything that will help in the completion of the task.&lt;br /&gt;
&lt;br /&gt;
At the initial phase, the task of assigning points to stories may seem a bit daunting and a bit like second guessing oneself but as the iterations pass on and based on the understanding of the feature and the experience one has in assigning points to user-stories, the estimation will always improve and at the end will be very close to the actual statistics. Also estimates can be changed if one feels an incorrect estimation was done but care should be taken that the variation is not too much.&lt;br /&gt;
&lt;br /&gt;
===R- business Relevant===&lt;br /&gt;
A user story should be of business value, i.e it should generate additional income or protect revenue. The software defined by the user story can increase the value of the product by generating interest among new users and thereby generating potential new customers.A software can also protect revenue by  streamlining processes to cut costs.&lt;br /&gt;
One way of determining the business relevance of a product is by asking the question “why” recursively. This is similar to a problem solving technique called  “5 Whys” where questions asked recursively for root cause analysis. The methodology can be extended here to recursively ask why developing a software is of business relevance to that company. It is assumed that after asking multiple times the reason will have some business relevance (for eg  “To increase in revenue for the company”) or there is no valid reason justifying the software project. &lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;Example&amp;lt;/b&amp;gt;==&lt;br /&gt;
Let us understand SMART User Stories by taking an example:&lt;br /&gt;
&lt;br /&gt;
   I want an application that shows me the best deals.&lt;br /&gt;
&lt;br /&gt;
There are all sorts of problems with the above user story. It doesn't fit any of the criterion we have set using our SMART User Stories approach. Let’s go over with each of the problems and try to improve our user story step-by-step.&lt;br /&gt;
&lt;br /&gt;
S-Specific / M-Measurable:&amp;lt;br&amp;gt;&lt;br /&gt;
The above example is anything but specific nor it seems measurable. Well it does say that there needs to be an application that shows the best deals but it doesn't mention to display the best deals from which all places or websites. Also it doesn't mention about what it wants the best deals on. Also as it doesn't mention about the websites it is difficult it to measure the story.&lt;br /&gt;
&lt;br /&gt;
A much better user story would have been:&amp;lt;br&amp;gt;&lt;br /&gt;
   I want an application that shows the user the best deals on a particular product, which is entered by the user before beginning the search, from &amp;lt;br&amp;gt; the websites that preselected by the user.&lt;br /&gt;
&lt;br /&gt;
This says specifically on what product the user wants the search on and from which all websites. This is a very specific goal as there is no scope of assumption here. Of course the search results will be based on the specific words the user enters, but that is true for any website. The more specific you are in your search the more fine grained your search will be. Also because of the modified story, now it is easy to measure the story, as we can go through each website and compare prices and check whether the application did indeed return the best deals from various websites.&lt;br /&gt;
&lt;br /&gt;
A-Achievable:&amp;lt;br&amp;gt;&lt;br /&gt;
Appropriate timelines and deadlines should be set for implementing and testing the application. Suppose the client wants the above application for the Thanksgiving sale and he comes and asks for it during midweek of November, then creating the above story at that time wouldn’t be useful or advisable as the time period is too short for the goal to achieve.&lt;br /&gt;
&lt;br /&gt;
Assuming there is sufficient time for the application to be created and there are say 4 iterations possible. But the above story may not be practical for one iteration, one might need to break it down further to make it workable for 1 iteration as the target is to have a workable code at the end of each iteration. So the story for the particular iteration can be modified as:&lt;br /&gt;
&lt;br /&gt;
   Provide an interface for the user to provide the name of the product and the websites he/she wants to have a search in.&lt;br /&gt;
&lt;br /&gt;
This would be achievable for the first iteration. For the second iteration more functionality may be added:&lt;br /&gt;
&lt;br /&gt;
   Look for the price of the product in all of the websites given by the user and fetch all the results.&lt;br /&gt;
&lt;br /&gt;
This can be further modified in iteration 3 to give the best deal, based on price factor. This can be further modified to modify the result if any free goodies are being provided by any particular website. In this way the goal can be made achievable.&lt;br /&gt;
&lt;br /&gt;
T-Timeboxed&amp;lt;br&amp;gt;&lt;br /&gt;
All of the above 4 iterations that we planned should have the deadlines appropriately. If we suppose till one particular date if the team-member responsible for developing one particular functionality is not able to reach the target goal, it might be a good idea for him/her to ask to someone else or for some senior member to help out or to swap teams itself so that someone who has knowledge can work on that and can complete it without affecting the deadlines and making sure that the product is still workable at the end of that particular iteration. This should be followed for all the iterations. This will also allow sufficient time for testing which is a very important part of the application development.&lt;br /&gt;
&lt;br /&gt;
R-Relevant&amp;lt;br&amp;gt;&lt;br /&gt;
The story should be relevant so that the desired benefit can be obtained and maximized. Why would the client need it&lt;br /&gt;
*Probably because there are many websites which offer different deals and to get a single website which searches all the websites on behalf of the user or at least a subset of the websites would make it much easier for the user&lt;br /&gt;
*That will also lead to increase in the clicks the website gets&lt;br /&gt;
*Which will subsequently lead to increase in ads&lt;br /&gt;
*Which will lead to increase in revenue for the company&lt;br /&gt;
&lt;br /&gt;
Now the above goals are relevant for the application that user wants but it may not be relevant for the Terms and Conditions page or the login page that application may have.&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;Advantages/Disadvantages of SMART User stories&amp;lt;/b&amp;gt;==&lt;br /&gt;
===Advantages of SMART User stories===&lt;br /&gt;
Lets consider the advantages of SMART User stories by considering each letter of the mnemonic.&lt;br /&gt;
*Making a user story &amp;lt;i&amp;gt;specific&amp;lt;/i&amp;gt; makes the objectives of the project clear and prevent confusion amongst teams&lt;br /&gt;
*Having a well defined input/output relation makes the project &amp;lt;i&amp;gt;measurable&amp;lt;/i&amp;gt;/&amp;lt;i&amp;gt;testable&amp;lt;/i&amp;gt; for bugs and defects.&lt;br /&gt;
*Having a specific user story helps breaking the project down to &amp;lt;i&amp;gt;achievable&amp;lt;/i&amp;gt; goals. These goals can be accomplished in single or multiple iterations.&lt;br /&gt;
*Asking whether a project is business &amp;lt;i&amp;gt;relevant&amp;lt;/i&amp;gt; helps in identifying the maximum potential of the project.&lt;br /&gt;
*A &amp;lt;i&amp;gt;timeboxed&amp;lt;/i&amp;gt; project helps in monitoring the progress of the project. It is also possible to estimate the velocity of the project using timeboxing.&lt;br /&gt;
&lt;br /&gt;
===Disadvantages/Limitations of SMART User Stories===&lt;br /&gt;
&lt;br /&gt;
*Some people prefer other kind of mnemonics such as INVEST rather than SMART as they feel that the thing that SMART stands for is not the same for all people. S may stand for Specific for some, Significant for some, Stretching for others, similarly M may be Measurable or Meaningful, likewise each of the alphabet of SMART has different meaning for different people.&lt;br /&gt;
*It is important that points assignment to user stories is done by someone experienced enough to understand the features that customers require as well as the complexity and technical details required to implement it successfully otherwise the velocity will be far from what is expected.&lt;br /&gt;
==&amp;lt;b&amp;gt;Conclusion&amp;lt;/b&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
[http://www.youtube.com/watch?v=XzV0dytYQq0 SaaS 4.2: SMART User stories]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://uxdesign.smashingmagazine.com/2011/09/13/the-s-m-a-r-t-user-experience-strategy/ SMART User experience strategy]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://xp123.com/articles/invest-in-good-stories-and-smart-tasks/ INVEST in good stories and SMART Tasks]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.chiefsimplicityofficer.com/2010/04/user-stories-its-smart-to-invest/ User stories: Its SMART to INVEST]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;See Also&amp;lt;/b&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/User_story Information on user stories]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://gigaom.com/2008/05/05/how-to-create-smart-tasks/ Information on SMART tasks]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.uncommon-knowledge.co.uk/goal_setting/smart_4.html Information on SMART goals]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/5_Whys Link for 5 Whys]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Nloya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_1w70_nl&amp;diff=70991</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 1w70 nl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_1w70_nl&amp;diff=70991"/>
		<updated>2012-11-20T01:06:39Z</updated>

		<summary type="html">&lt;p&gt;Nloya: /* Advantages of SMART User stories */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;b&amp;gt;SaaS - 4.2 - SMART User Stories&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt;==&lt;br /&gt;
User stories are the basis for defining the functionality of any given system. They are a short description of the system that capture what the system does and gives the expectation of how the system should behave.&lt;br /&gt;
When we say User Stories, we don’t define any particular criteria as to how a user story should be written. A user story can be “Customer should have a good UI experience” or “When a customer logs in he/she should be able to see all the technical details of the product he/she has selected, with the reviews, price displayed alongside and an option of ‘Add to Cart’ to go along with it.”&lt;br /&gt;
Both the user stories described above are correct but one leaves too much for one to assume and the other gives one specific information in terms of display and functionality. The problem with the first user story is it is not restricted to any particular guideline, its just a user story but has no scope and hence can be either very short or very long. The advantage with the second user story is that it has been written based on a given set of goals which can be acronymed as SMART and will be explained below.&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;SMART User Stories&amp;lt;/b&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
SMART is a mnemonic for&amp;lt;br&amp;gt;&lt;br /&gt;
*S - Specific&lt;br /&gt;
*M - Measurable&lt;br /&gt;
*A - Achievable&lt;br /&gt;
*R - Relevant&lt;br /&gt;
*T- Timeboxed&lt;br /&gt;
&lt;br /&gt;
===S -Specific/ M - Measurable===&lt;br /&gt;
The user story should be specific enough to capture the requirements of the user. The user can be the customer who requires the software or the end user who will be using the software. Many times the user stories are vague or ambiguous leading to a lot of loss in time and energy spent in development.&lt;br /&gt;
User stories can be made specific by using the terms 'Given, When and Then' which describe the user story. The term “Given” specifies the background scenarios. It specifies all the preconditions.&lt;br /&gt;
“When” specifies the input  to the system. “Then” specifies the desired result/s.&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
   Given I am at www.google.com&lt;br /&gt;
   When I click on the button Gmail&lt;br /&gt;
   Then I should be redirected to Gmail.&lt;br /&gt;
Each scenario should be testable i.e its progress should be measurable.  There should be  known good output for every input. Every project needs concrete criteria for measuring progress toward its completion. The reason behind this is that if the scenarios are not measurable, it is not possible to know whether a team is making progress toward successful completion. Measuring progress is supposed to help a team stay on track, reach its target dates, and experience the exhilaration of achievement that spurs it on to continued effort required to reach the ultimate goal.&lt;br /&gt;
&lt;br /&gt;
===A - Achievable / T - Timeboxed===&lt;br /&gt;
Goals should be set in such a way that it is achievable or at least a working model of it is achievable within a single iteration i.e. it is achievable within a time period. The reason for this is that Agile methodologies always aim for working models at the end of iteration, it doesn’t necessarily have to be a complete feature but a run-down version of it which is working partially and is able to provide a minimal set of functionality is also accepted.&lt;br /&gt;
If the feature is such that it may span over multiple iterations then it is a good idea to break it up into subset of stories such that each implemented subset provides a working model of the feature, however small it may be, so that constant progress is made to implement the feature and also a working code is provided at the end of each iteration.&lt;br /&gt;
&lt;br /&gt;
While its a good idea to divide a feature into sub-features and have user stories for each iteration, the question arises of how to decide on the number of user stories for each iteration and the number of iterations that may require for the complete feature to be implemented. This is usually accomplished using velocity which is an estimate of the kind of progress made in the past based on the difficulty of the user stories and the kind of progress that can be made by taking into consideration the difficulty of the user stories that are yet to be implemented.&lt;br /&gt;
&lt;br /&gt;
As features are broken down to sub-features and stories are written for the sub-feature, which is to be completed within the iteration, points should be assigned to each of the stories based on the difficulty level of the story and how fine grained approach for point-assignment does an assigner want. Say for example an assigner wants just a simple approach for point-assignment then he/she can assign from a range of 1-3 (where 1 being easy, 2 being medium and 3 being hard) and if a more fine grained approach is required then the range can be increased to 1-5 or 1-10. Whatever the approach is followed the important thing is to allocate points to each of the stories based on one’s estimate. At the end of each iteration, Velocity is calculated, which is nothing but the total number of points completed per iteration. As Velocity is not just the total of the stories but the total based on the difficulty level of the stories, it acts as an important guiding tool which can be leveraged by anyone to get to know details about the project as is shown below.&lt;br /&gt;
&lt;br /&gt;
Uses of Velocity:&lt;br /&gt;
&lt;br /&gt;
*Velocity can be used to plan future iterations&lt;br /&gt;
*It gives an estimate of how much time or iterations would be required to completely implement the feature&lt;br /&gt;
*It gives an idea of whether the team is on track as the velocity is expected to remain constant if all other variables are unchanged (other variables such as number of team members or replacement of an experienced team member with a new team member, etc.)&lt;br /&gt;
*It can provide an estimate if a change is requested by customers and based on the time required to implement the change and the importance level of the change the decision can be made whether to implement it or not.&lt;br /&gt;
&lt;br /&gt;
Following this approach allows a task to be timeboxed, i.e. limited to a specific duration. It provides a kind of expectation which makes the team-members aware that if something is not working out its time to seek help, split the task, change teams or do anything that will help in the completion of the task.&lt;br /&gt;
&lt;br /&gt;
At the initial phase, the task of assigning points to stories may seem a bit daunting and a bit like second guessing oneself but as the iterations pass on and based on the understanding of the feature and the experience one has in assigning points to user-stories, the estimation will always improve and at the end will be very close to the actual statistics. Also estimates can be changed if one feels an incorrect estimation was done but care should be taken that the variation is not too much.&lt;br /&gt;
&lt;br /&gt;
===R- business Relevant===&lt;br /&gt;
A user story should be of business value, i.e it should generate additional income or protect revenue. The software defined by the user story can increase the value of the product by generating interest among new users and thereby generating potential new customers.A software can also protect revenue by  streamlining processes to cut costs.&lt;br /&gt;
One way of determining the business relevance of a product is by asking the question “why” recursively. This is similar to a problem solving technique called  “5 Whys” where questions asked recursively for root cause analysis. The methodology can be extended here to recursively ask why developing a software is of business relevance to that company. It is assumed that after asking multiple times the reason will have some business relevance (for eg  “To increase in revenue for the company”) or there is no valid reason justifying the software project. &lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;Example&amp;lt;/b&amp;gt;==&lt;br /&gt;
Let us understand SMART User Stories by taking an example:&lt;br /&gt;
&lt;br /&gt;
   I want an application that shows me the best deals.&lt;br /&gt;
&lt;br /&gt;
There are all sorts of problems with the above user story. It doesn't fit any of the criterion we have set using our SMART User Stories approach. Let’s go over with each of the problems and try to improve our user story step-by-step.&lt;br /&gt;
&lt;br /&gt;
S-Specific / M-Measurable:&amp;lt;br&amp;gt;&lt;br /&gt;
The above example is anything but specific nor it seems measurable. Well it does say that there needs to be an application that shows the best deals but it doesn't mention to display the best deals from which all places or websites. Also it doesn't mention about what it wants the best deals on. Also as it doesn't mention about the websites it is difficult it to measure the story.&lt;br /&gt;
&lt;br /&gt;
A much better user story would have been:&amp;lt;br&amp;gt;&lt;br /&gt;
   I want an application that shows me the best deals on a particular product, which is entered by me before beginning the search, from the &amp;lt;br&amp;gt;  websites that I preselect.&lt;br /&gt;
&lt;br /&gt;
This says specifically on what product the user wants the search on and from which all websites. This is a very specific goal as there is no scope of assumption here. Of course the search results will be based on the specific words the user enters, but that is true for any website. The more specific you are in your search the more fine grained your search will be. Also because of the modified story, now it is easy to measure the story, as we can go through each website and compare prices and check whether the application did indeed return the best deals from various websites.&lt;br /&gt;
&lt;br /&gt;
A-Achievable:&amp;lt;br&amp;gt;&lt;br /&gt;
Appropriate timelines and deadlines should be set for implementing and testing the application. Suppose the client wants the above application for the Thanksgiving sale and he comes and asks for it during midweek of November, then creating the above story at that time wouldn’t be useful or advisable as the time period is too short for the goal to achieve.&lt;br /&gt;
&lt;br /&gt;
Assuming there is sufficient time for the application to be created and there are say 4 iterations possible. But the above story may not be practical for one iteration, one might need to break it down further to make it workable for 1 iteration as the target is to have a workable code at the end of each iteration. So the story for the particular iteration can be modified as:&lt;br /&gt;
&lt;br /&gt;
   Provide an interface for the user to provide the name of the product and the websites he/she wants to have a search in.&lt;br /&gt;
&lt;br /&gt;
This would be achievable for the first iteration. For the second iteration more functionality may be added:&lt;br /&gt;
&lt;br /&gt;
   Look for the price of the product in all of the websites given by the user and fetch all the results.&lt;br /&gt;
&lt;br /&gt;
This can be further modified in iteration 3 to give the best deal, based on price factor. This can be further modified to modify the result if any free goodies are being provided by any particular website. In this way the goal can be made achievable.&lt;br /&gt;
&lt;br /&gt;
T-Timeboxed&amp;lt;br&amp;gt;&lt;br /&gt;
All of the above 4 iterations that we planned should have the deadlines appropriately. If we suppose till one particular date if the team-member responsible for developing one particular functionality is not able to reach the target goal, it might be a good idea for him/her to ask to someone else or for some senior member to help out or to swap teams itself so that someone who has knowledge can work on that and can complete it without affecting the deadlines and making sure that the product is still workable at the end of that particular iteration. This should be followed for all the iterations. This will also allow sufficient time for testing which is a very important part of the application development.&lt;br /&gt;
&lt;br /&gt;
R-Relevant&amp;lt;br&amp;gt;&lt;br /&gt;
The story should be relevant so that the desired benefit can be obtained and maximized. Why would the client need it&lt;br /&gt;
*Probably because there are many websites which offer different deals and to get a single website which searches all the websites on behalf of the user or at least a subset of the websites would make it much easier for the user&lt;br /&gt;
*That will also lead to increase in the clicks the website gets&lt;br /&gt;
*Which will subsequently lead to increase in ads&lt;br /&gt;
*Which will lead to increase in revenue for the company&lt;br /&gt;
&lt;br /&gt;
Now the above goals are relevant for the application that user wants but it may not be relevant for the Terms and Conditions page or the login page that application may have.&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;Advantages/Disadvantages of SMART User stories&amp;lt;/b&amp;gt;==&lt;br /&gt;
===Advantages of SMART User stories===&lt;br /&gt;
Lets consider the advantages of SMART User stories by considering each letter of the mnemonic.&lt;br /&gt;
*Making a user story &amp;lt;i&amp;gt;specific&amp;lt;/i&amp;gt; makes the objectives of the project clear and prevent confusion amongst teams&lt;br /&gt;
*Having a well defined input/output relation makes the project &amp;lt;i&amp;gt;measurable&amp;lt;/i&amp;gt;/&amp;lt;i&amp;gt;testable&amp;lt;/i&amp;gt; for bugs and defects.&lt;br /&gt;
*Having a specific user story helps breaking the project down to &amp;lt;i&amp;gt;achievable&amp;lt;/i&amp;gt; goals. These goals can be accomplished in single or multiple iterations.&lt;br /&gt;
*Asking whether a project is business &amp;lt;i&amp;gt;relevant&amp;lt;/i&amp;gt; helps in identifying the maximum potential of the project.&lt;br /&gt;
*A &amp;lt;i&amp;gt;timeboxed&amp;lt;/i&amp;gt; project helps in monitoring the progress of the project. It is also possible to estimate the velocity of the project using timeboxing.&lt;br /&gt;
&lt;br /&gt;
===Disadvantages/Limitations of SMART User Stories===&lt;br /&gt;
&lt;br /&gt;
*Some people prefer other kind of mnemonics such as INVEST rather than SMART as they feel that the thing that SMART stands for is not the same for all people. S may stand for Specific for some, Significant for some, Stretching for others, similarly M may be Measurable or Meaningful, likewise each of the alphabet of SMART has different meaning for different people.&lt;br /&gt;
*It is important that points assignment to user stories is done by someone experienced enough to understand the features that customers require as well as the complexity and technical details required to implement it successfully otherwise the velocity will be far from what is expected.&lt;br /&gt;
==&amp;lt;b&amp;gt;Conclusion&amp;lt;/b&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
[http://www.youtube.com/watch?v=XzV0dytYQq0 SaaS 4.2: SMART User stories]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://uxdesign.smashingmagazine.com/2011/09/13/the-s-m-a-r-t-user-experience-strategy/ SMART User experience strategy]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://xp123.com/articles/invest-in-good-stories-and-smart-tasks/ INVEST in good stories and SMART Tasks]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.chiefsimplicityofficer.com/2010/04/user-stories-its-smart-to-invest/ User stories: Its SMART to INVEST]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;See Also&amp;lt;/b&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/User_story Information on user stories]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://gigaom.com/2008/05/05/how-to-create-smart-tasks/ Information on SMART tasks]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.uncommon-knowledge.co.uk/goal_setting/smart_4.html Information on SMART goals]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/5_Whys Link for 5 Whys]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Nloya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_1w70_nl&amp;diff=70988</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 1w70 nl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_1w70_nl&amp;diff=70988"/>
		<updated>2012-11-20T01:05:55Z</updated>

		<summary type="html">&lt;p&gt;Nloya: /* Advantages of SMART User stories */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;b&amp;gt;SaaS - 4.2 - SMART User Stories&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt;==&lt;br /&gt;
User stories are the basis for defining the functionality of any given system. They are a short description of the system that capture what the system does and gives the expectation of how the system should behave.&lt;br /&gt;
When we say User Stories, we don’t define any particular criteria as to how a user story should be written. A user story can be “Customer should have a good UI experience” or “When a customer logs in he/she should be able to see all the technical details of the product he/she has selected, with the reviews, price displayed alongside and an option of ‘Add to Cart’ to go along with it.”&lt;br /&gt;
Both the user stories described above are correct but one leaves too much for one to assume and the other gives one specific information in terms of display and functionality. The problem with the first user story is it is not restricted to any particular guideline, its just a user story but has no scope and hence can be either very short or very long. The advantage with the second user story is that it has been written based on a given set of goals which can be acronymed as SMART and will be explained below.&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;SMART User Stories&amp;lt;/b&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
SMART is a mnemonic for&amp;lt;br&amp;gt;&lt;br /&gt;
*S - Specific&lt;br /&gt;
*M - Measurable&lt;br /&gt;
*A - Achievable&lt;br /&gt;
*R - Relevant&lt;br /&gt;
*T- Timeboxed&lt;br /&gt;
&lt;br /&gt;
===S -Specific/ M - Measurable===&lt;br /&gt;
The user story should be specific enough to capture the requirements of the user. The user can be the customer who requires the software or the end user who will be using the software. Many times the user stories are vague or ambiguous leading to a lot of loss in time and energy spent in development.&lt;br /&gt;
User stories can be made specific by using the terms 'Given, When and Then' which describe the user story. The term “Given” specifies the background scenarios. It specifies all the preconditions.&lt;br /&gt;
“When” specifies the input  to the system. “Then” specifies the desired result/s.&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
   Given I am at www.google.com&lt;br /&gt;
   When I click on the button Gmail&lt;br /&gt;
   Then I should be redirected to Gmail.&lt;br /&gt;
Each scenario should be testable i.e its progress should be measurable.  There should be  known good output for every input. Every project needs concrete criteria for measuring progress toward its completion. The reason behind this is that if the scenarios are not measurable, it is not possible to know whether a team is making progress toward successful completion. Measuring progress is supposed to help a team stay on track, reach its target dates, and experience the exhilaration of achievement that spurs it on to continued effort required to reach the ultimate goal.&lt;br /&gt;
&lt;br /&gt;
===A - Achievable / T - Timeboxed===&lt;br /&gt;
Goals should be set in such a way that it is achievable or at least a working model of it is achievable within a single iteration i.e. it is achievable within a time period. The reason for this is that Agile methodologies always aim for working models at the end of iteration, it doesn’t necessarily have to be a complete feature but a run-down version of it which is working partially and is able to provide a minimal set of functionality is also accepted.&lt;br /&gt;
If the feature is such that it may span over multiple iterations then it is a good idea to break it up into subset of stories such that each implemented subset provides a working model of the feature, however small it may be, so that constant progress is made to implement the feature and also a working code is provided at the end of each iteration.&lt;br /&gt;
&lt;br /&gt;
While its a good idea to divide a feature into sub-features and have user stories for each iteration, the question arises of how to decide on the number of user stories for each iteration and the number of iterations that may require for the complete feature to be implemented. This is usually accomplished using velocity which is an estimate of the kind of progress made in the past based on the difficulty of the user stories and the kind of progress that can be made by taking into consideration the difficulty of the user stories that are yet to be implemented.&lt;br /&gt;
&lt;br /&gt;
As features are broken down to sub-features and stories are written for the sub-feature, which is to be completed within the iteration, points should be assigned to each of the stories based on the difficulty level of the story and how fine grained approach for point-assignment does an assigner want. Say for example an assigner wants just a simple approach for point-assignment then he/she can assign from a range of 1-3 (where 1 being easy, 2 being medium and 3 being hard) and if a more fine grained approach is required then the range can be increased to 1-5 or 1-10. Whatever the approach is followed the important thing is to allocate points to each of the stories based on one’s estimate. At the end of each iteration, Velocity is calculated, which is nothing but the total number of points completed per iteration. As Velocity is not just the total of the stories but the total based on the difficulty level of the stories, it acts as an important guiding tool which can be leveraged by anyone to get to know details about the project as is shown below.&lt;br /&gt;
&lt;br /&gt;
Uses of Velocity:&lt;br /&gt;
&lt;br /&gt;
*Velocity can be used to plan future iterations&lt;br /&gt;
*It gives an estimate of how much time or iterations would be required to completely implement the feature&lt;br /&gt;
*It gives an idea of whether the team is on track as the velocity is expected to remain constant if all other variables are unchanged (other variables such as number of team members or replacement of an experienced team member with a new team member, etc.)&lt;br /&gt;
*It can provide an estimate if a change is requested by customers and based on the time required to implement the change and the importance level of the change the decision can be made whether to implement it or not.&lt;br /&gt;
&lt;br /&gt;
Following this approach allows a task to be timeboxed, i.e. limited to a specific duration. It provides a kind of expectation which makes the team-members aware that if something is not working out its time to seek help, split the task, change teams or do anything that will help in the completion of the task.&lt;br /&gt;
&lt;br /&gt;
At the initial phase, the task of assigning points to stories may seem a bit daunting and a bit like second guessing oneself but as the iterations pass on and based on the understanding of the feature and the experience one has in assigning points to user-stories, the estimation will always improve and at the end will be very close to the actual statistics. Also estimates can be changed if one feels an incorrect estimation was done but care should be taken that the variation is not too much.&lt;br /&gt;
&lt;br /&gt;
===R- business Relevant===&lt;br /&gt;
A user story should be of business value, i.e it should generate additional income or protect revenue. The software defined by the user story can increase the value of the product by generating interest among new users and thereby generating potential new customers.A software can also protect revenue by  streamlining processes to cut costs.&lt;br /&gt;
One way of determining the business relevance of a product is by asking the question “why” recursively. This is similar to a problem solving technique called  “5 Whys” where questions asked recursively for root cause analysis. The methodology can be extended here to recursively ask why developing a software is of business relevance to that company. It is assumed that after asking multiple times the reason will have some business relevance (for eg  “To increase in revenue for the company”) or there is no valid reason justifying the software project. &lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;Example&amp;lt;/b&amp;gt;==&lt;br /&gt;
Let us understand SMART User Stories by taking an example:&lt;br /&gt;
&lt;br /&gt;
   I want an application that shows me the best deals.&lt;br /&gt;
&lt;br /&gt;
There are all sorts of problems with the above user story. It doesn't fit any of the criterion we have set using our SMART User Stories approach. Let’s go over with each of the problems and try to improve our user story step-by-step.&lt;br /&gt;
&lt;br /&gt;
S-Specific / M-Measurable:&amp;lt;br&amp;gt;&lt;br /&gt;
The above example is anything but specific nor it seems measurable. Well it does say that there needs to be an application that shows the best deals but it doesn't mention to display the best deals from which all places or websites. Also it doesn't mention about what it wants the best deals on. Also as it doesn't mention about the websites it is difficult it to measure the story.&lt;br /&gt;
&lt;br /&gt;
A much better user story would have been:&amp;lt;br&amp;gt;&lt;br /&gt;
   I want an application that shows me the best deals on a particular product, which is entered by me before beginning the search, from the &amp;lt;br&amp;gt;  websites that I preselect.&lt;br /&gt;
&lt;br /&gt;
This says specifically on what product the user wants the search on and from which all websites. This is a very specific goal as there is no scope of assumption here. Of course the search results will be based on the specific words the user enters, but that is true for any website. The more specific you are in your search the more fine grained your search will be. Also because of the modified story, now it is easy to measure the story, as we can go through each website and compare prices and check whether the application did indeed return the best deals from various websites.&lt;br /&gt;
&lt;br /&gt;
A-Achievable:&amp;lt;br&amp;gt;&lt;br /&gt;
Appropriate timelines and deadlines should be set for implementing and testing the application. Suppose the client wants the above application for the Thanksgiving sale and he comes and asks for it during midweek of November, then creating the above story at that time wouldn’t be useful or advisable as the time period is too short for the goal to achieve.&lt;br /&gt;
&lt;br /&gt;
Assuming there is sufficient time for the application to be created and there are say 4 iterations possible. But the above story may not be practical for one iteration, one might need to break it down further to make it workable for 1 iteration as the target is to have a workable code at the end of each iteration. So the story for the particular iteration can be modified as:&lt;br /&gt;
&lt;br /&gt;
   Provide an interface for the user to provide the name of the product and the websites he/she wants to have a search in.&lt;br /&gt;
&lt;br /&gt;
This would be achievable for the first iteration. For the second iteration more functionality may be added:&lt;br /&gt;
&lt;br /&gt;
   Look for the price of the product in all of the websites given by the user and fetch all the results.&lt;br /&gt;
&lt;br /&gt;
This can be further modified in iteration 3 to give the best deal, based on price factor. This can be further modified to modify the result if any free goodies are being provided by any particular website. In this way the goal can be made achievable.&lt;br /&gt;
&lt;br /&gt;
T-Timeboxed&amp;lt;br&amp;gt;&lt;br /&gt;
All of the above 4 iterations that we planned should have the deadlines appropriately. If we suppose till one particular date if the team-member responsible for developing one particular functionality is not able to reach the target goal, it might be a good idea for him/her to ask to someone else or for some senior member to help out or to swap teams itself so that someone who has knowledge can work on that and can complete it without affecting the deadlines and making sure that the product is still workable at the end of that particular iteration. This should be followed for all the iterations. This will also allow sufficient time for testing which is a very important part of the application development.&lt;br /&gt;
&lt;br /&gt;
R-Relevant&amp;lt;br&amp;gt;&lt;br /&gt;
The story should be relevant so that the desired benefit can be obtained and maximized. Why would the client need it&lt;br /&gt;
*Probably because there are many websites which offer different deals and to get a single website which searches all the websites on behalf of the user or at least a subset of the websites would make it much easier for the user&lt;br /&gt;
*That will also lead to increase in the clicks the website gets&lt;br /&gt;
*Which will subsequently lead to increase in ads&lt;br /&gt;
*Which will lead to increase in revenue for the company&lt;br /&gt;
&lt;br /&gt;
Now the above goals are relevant for the application that user wants but it may not be relevant for the Terms and Conditions page or the login page that application may have.&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;Advantages/Disadvantages of SMART User stories&amp;lt;/b&amp;gt;==&lt;br /&gt;
===Advantages of SMART User stories===&lt;br /&gt;
Lets consider the advantages of SMART User stories by considering each letter of the mnemonic.&lt;br /&gt;
*Making a user story &amp;lt;i&amp;gt;specific&amp;lt;/i&amp;gt; makes the objectives of the project clear and prevent confusion amongst teams&lt;br /&gt;
*Having a well defined input/output relation makes the project &amp;lt;i&amp;gt;measurable&amp;lt;/i&amp;gt;/&amp;lt;i&amp;gt;testable&amp;lt;/i&amp;gt; for bugs and defects.&lt;br /&gt;
*Having a specific user story helps breaking the project down to &amp;lt;i&amp;gt;achievable&amp;lt;/i&amp;gt; goals These goals can be accomplished in single or multiple iterations.&lt;br /&gt;
*Asking whether a project is business &amp;lt;i&amp;gt;relevant&amp;lt;/i&amp;gt; helps in identifying the maximum potential of the project.&lt;br /&gt;
*A &amp;lt;i&amp;gt;timeboxed&amp;lt;/i&amp;gt; project helps in monitoring the progress of the project. It is also possible to estimate the velocity of the project using timeboxing.&lt;br /&gt;
&lt;br /&gt;
===Disadvantages/Limitations of SMART User Stories===&lt;br /&gt;
&lt;br /&gt;
*Some people prefer other kind of mnemonics such as INVEST rather than SMART as they feel that the thing that SMART stands for is not the same for all people. S may stand for Specific for some, Significant for some, Stretching for others, similarly M may be Measurable or Meaningful, likewise each of the alphabet of SMART has different meaning for different people.&lt;br /&gt;
*It is important that points assignment to user stories is done by someone experienced enough to understand the features that customers require as well as the complexity and technical details required to implement it successfully otherwise the velocity will be far from what is expected.&lt;br /&gt;
==&amp;lt;b&amp;gt;Conclusion&amp;lt;/b&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
[http://www.youtube.com/watch?v=XzV0dytYQq0 SaaS 4.2: SMART User stories]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://uxdesign.smashingmagazine.com/2011/09/13/the-s-m-a-r-t-user-experience-strategy/ SMART User experience strategy]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://xp123.com/articles/invest-in-good-stories-and-smart-tasks/ INVEST in good stories and SMART Tasks]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.chiefsimplicityofficer.com/2010/04/user-stories-its-smart-to-invest/ User stories: Its SMART to INVEST]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;See Also&amp;lt;/b&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/User_story Information on user stories]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://gigaom.com/2008/05/05/how-to-create-smart-tasks/ Information on SMART tasks]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.uncommon-knowledge.co.uk/goal_setting/smart_4.html Information on SMART goals]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/5_Whys Link for 5 Whys]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Nloya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_1w70_nl&amp;diff=70986</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 1w70 nl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_1w70_nl&amp;diff=70986"/>
		<updated>2012-11-20T01:05:00Z</updated>

		<summary type="html">&lt;p&gt;Nloya: /* Advantages of SMART User stories */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;b&amp;gt;SaaS - 4.2 - SMART User Stories&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt;==&lt;br /&gt;
User stories are the basis for defining the functionality of any given system. They are a short description of the system that capture what the system does and gives the expectation of how the system should behave.&lt;br /&gt;
When we say User Stories, we don’t define any particular criteria as to how a user story should be written. A user story can be “Customer should have a good UI experience” or “When a customer logs in he/she should be able to see all the technical details of the product he/she has selected, with the reviews, price displayed alongside and an option of ‘Add to Cart’ to go along with it.”&lt;br /&gt;
Both the user stories described above are correct but one leaves too much for one to assume and the other gives one specific information in terms of display and functionality. The problem with the first user story is it is not restricted to any particular guideline, its just a user story but has no scope and hence can be either very short or very long. The advantage with the second user story is that it has been written based on a given set of goals which can be acronymed as SMART and will be explained below.&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;SMART User Stories&amp;lt;/b&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
SMART is a mnemonic for&amp;lt;br&amp;gt;&lt;br /&gt;
*S - Specific&lt;br /&gt;
*M - Measurable&lt;br /&gt;
*A - Achievable&lt;br /&gt;
*R - Relevant&lt;br /&gt;
*T- Timeboxed&lt;br /&gt;
&lt;br /&gt;
===S -Specific/ M - Measurable===&lt;br /&gt;
The user story should be specific enough to capture the requirements of the user. The user can be the customer who requires the software or the end user who will be using the software. Many times the user stories are vague or ambiguous leading to a lot of loss in time and energy spent in development.&lt;br /&gt;
User stories can be made specific by using the terms 'Given, When and Then' which describe the user story. The term “Given” specifies the background scenarios. It specifies all the preconditions.&lt;br /&gt;
“When” specifies the input  to the system. “Then” specifies the desired result/s.&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
   Given I am at www.google.com&lt;br /&gt;
   When I click on the button Gmail&lt;br /&gt;
   Then I should be redirected to Gmail.&lt;br /&gt;
Each scenario should be testable i.e its progress should be measurable.  There should be  known good output for every input. Every project needs concrete criteria for measuring progress toward its completion. The reason behind this is that if the scenarios are not measurable, it is not possible to know whether a team is making progress toward successful completion. Measuring progress is supposed to help a team stay on track, reach its target dates, and experience the exhilaration of achievement that spurs it on to continued effort required to reach the ultimate goal.&lt;br /&gt;
&lt;br /&gt;
===A - Achievable / T - Timeboxed===&lt;br /&gt;
Goals should be set in such a way that it is achievable or at least a working model of it is achievable within a single iteration i.e. it is achievable within a time period. The reason for this is that Agile methodologies always aim for working models at the end of iteration, it doesn’t necessarily have to be a complete feature but a run-down version of it which is working partially and is able to provide a minimal set of functionality is also accepted.&lt;br /&gt;
If the feature is such that it may span over multiple iterations then it is a good idea to break it up into subset of stories such that each implemented subset provides a working model of the feature, however small it may be, so that constant progress is made to implement the feature and also a working code is provided at the end of each iteration.&lt;br /&gt;
&lt;br /&gt;
While its a good idea to divide a feature into sub-features and have user stories for each iteration, the question arises of how to decide on the number of user stories for each iteration and the number of iterations that may require for the complete feature to be implemented. This is usually accomplished using velocity which is an estimate of the kind of progress made in the past based on the difficulty of the user stories and the kind of progress that can be made by taking into consideration the difficulty of the user stories that are yet to be implemented.&lt;br /&gt;
&lt;br /&gt;
As features are broken down to sub-features and stories are written for the sub-feature, which is to be completed within the iteration, points should be assigned to each of the stories based on the difficulty level of the story and how fine grained approach for point-assignment does an assigner want. Say for example an assigner wants just a simple approach for point-assignment then he/she can assign from a range of 1-3 (where 1 being easy, 2 being medium and 3 being hard) and if a more fine grained approach is required then the range can be increased to 1-5 or 1-10. Whatever the approach is followed the important thing is to allocate points to each of the stories based on one’s estimate. At the end of each iteration, Velocity is calculated, which is nothing but the total number of points completed per iteration. As Velocity is not just the total of the stories but the total based on the difficulty level of the stories, it acts as an important guiding tool which can be leveraged by anyone to get to know details about the project as is shown below.&lt;br /&gt;
&lt;br /&gt;
Uses of Velocity:&lt;br /&gt;
&lt;br /&gt;
*Velocity can be used to plan future iterations&lt;br /&gt;
*It gives an estimate of how much time or iterations would be required to completely implement the feature&lt;br /&gt;
*It gives an idea of whether the team is on track as the velocity is expected to remain constant if all other variables are unchanged (other variables such as number of team members or replacement of an experienced team member with a new team member, etc.)&lt;br /&gt;
*It can provide an estimate if a change is requested by customers and based on the time required to implement the change and the importance level of the change the decision can be made whether to implement it or not.&lt;br /&gt;
&lt;br /&gt;
Following this approach allows a task to be timeboxed, i.e. limited to a specific duration. It provides a kind of expectation which makes the team-members aware that if something is not working out its time to seek help, split the task, change teams or do anything that will help in the completion of the task.&lt;br /&gt;
&lt;br /&gt;
At the initial phase, the task of assigning points to stories may seem a bit daunting and a bit like second guessing oneself but as the iterations pass on and based on the understanding of the feature and the experience one has in assigning points to user-stories, the estimation will always improve and at the end will be very close to the actual statistics. Also estimates can be changed if one feels an incorrect estimation was done but care should be taken that the variation is not too much.&lt;br /&gt;
&lt;br /&gt;
===R- business Relevant===&lt;br /&gt;
A user story should be of business value, i.e it should generate additional income or protect revenue. The software defined by the user story can increase the value of the product by generating interest among new users and thereby generating potential new customers.A software can also protect revenue by  streamlining processes to cut costs.&lt;br /&gt;
One way of determining the business relevance of a product is by asking the question “why” recursively. This is similar to a problem solving technique called  “5 Whys” where questions asked recursively for root cause analysis. The methodology can be extended here to recursively ask why developing a software is of business relevance to that company. It is assumed that after asking multiple times the reason will have some business relevance (for eg  “To increase in revenue for the company”) or there is no valid reason justifying the software project. &lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;Example&amp;lt;/b&amp;gt;==&lt;br /&gt;
Let us understand SMART User Stories by taking an example:&lt;br /&gt;
&lt;br /&gt;
   I want an application that shows me the best deals.&lt;br /&gt;
&lt;br /&gt;
There are all sorts of problems with the above user story. It doesn't fit any of the criterion we have set using our SMART User Stories approach. Let’s go over with each of the problems and try to improve our user story step-by-step.&lt;br /&gt;
&lt;br /&gt;
S-Specific / M-Measurable:&amp;lt;br&amp;gt;&lt;br /&gt;
The above example is anything but specific nor it seems measurable. Well it does say that there needs to be an application that shows the best deals but it doesn't mention to display the best deals from which all places or websites. Also it doesn't mention about what it wants the best deals on. Also as it doesn't mention about the websites it is difficult it to measure the story.&lt;br /&gt;
&lt;br /&gt;
A much better user story would have been:&amp;lt;br&amp;gt;&lt;br /&gt;
   I want an application that shows me the best deals on a particular product, which is entered by me before beginning the search, from the &amp;lt;br&amp;gt;  websites that I preselect.&lt;br /&gt;
&lt;br /&gt;
This says specifically on what product the user wants the search on and from which all websites. This is a very specific goal as there is no scope of assumption here. Of course the search results will be based on the specific words the user enters, but that is true for any website. The more specific you are in your search the more fine grained your search will be. Also because of the modified story, now it is easy to measure the story, as we can go through each website and compare prices and check whether the application did indeed return the best deals from various websites.&lt;br /&gt;
&lt;br /&gt;
A-Achievable:&amp;lt;br&amp;gt;&lt;br /&gt;
Appropriate timelines and deadlines should be set for implementing and testing the application. Suppose the client wants the above application for the Thanksgiving sale and he comes and asks for it during midweek of November, then creating the above story at that time wouldn’t be useful or advisable as the time period is too short for the goal to achieve.&lt;br /&gt;
&lt;br /&gt;
Assuming there is sufficient time for the application to be created and there are say 4 iterations possible. But the above story may not be practical for one iteration, one might need to break it down further to make it workable for 1 iteration as the target is to have a workable code at the end of each iteration. So the story for the particular iteration can be modified as:&lt;br /&gt;
&lt;br /&gt;
   Provide an interface for the user to provide the name of the product and the websites he/she wants to have a search in.&lt;br /&gt;
&lt;br /&gt;
This would be achievable for the first iteration. For the second iteration more functionality may be added:&lt;br /&gt;
&lt;br /&gt;
   Look for the price of the product in all of the websites given by the user and fetch all the results.&lt;br /&gt;
&lt;br /&gt;
This can be further modified in iteration 3 to give the best deal, based on price factor. This can be further modified to modify the result if any free goodies are being provided by any particular website. In this way the goal can be made achievable.&lt;br /&gt;
&lt;br /&gt;
T-Timeboxed&amp;lt;br&amp;gt;&lt;br /&gt;
All of the above 4 iterations that we planned should have the deadlines appropriately. If we suppose till one particular date if the team-member responsible for developing one particular functionality is not able to reach the target goal, it might be a good idea for him/her to ask to someone else or for some senior member to help out or to swap teams itself so that someone who has knowledge can work on that and can complete it without affecting the deadlines and making sure that the product is still workable at the end of that particular iteration. This should be followed for all the iterations. This will also allow sufficient time for testing which is a very important part of the application development.&lt;br /&gt;
&lt;br /&gt;
R-Relevant&amp;lt;br&amp;gt;&lt;br /&gt;
The story should be relevant so that the desired benefit can be obtained and maximized. Why would the client need it&lt;br /&gt;
*Probably because there are many websites which offer different deals and to get a single website which searches all the websites on behalf of the user or at least a subset of the websites would make it much easier for the user&lt;br /&gt;
*That will also lead to increase in the clicks the website gets&lt;br /&gt;
*Which will subsequently lead to increase in ads&lt;br /&gt;
*Which will lead to increase in revenue for the company&lt;br /&gt;
&lt;br /&gt;
Now the above goals are relevant for the application that user wants but it may not be relevant for the Terms and Conditions page or the login page that application may have.&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;Advantages/Disadvantages of SMART User stories&amp;lt;/b&amp;gt;==&lt;br /&gt;
===Advantages of SMART User stories===&lt;br /&gt;
Lets consider the advantages of SMART User stories by considering each letter of the mnemonic.&lt;br /&gt;
*Making a user story &amp;lt;i&amp;gt;specific&amp;lt;/i&amp;gt; makes the objectives of the project clear and prevent confusion amongst teams&lt;br /&gt;
*Having a well defined input /output relation makes the project &amp;lt;i&amp;gt;measurable&amp;lt;/i&amp;gt;/&amp;lt;i&amp;gt;testable&amp;lt;/i&amp;gt; for bugs and defects.&lt;br /&gt;
*Having a specific user story helps breaking the project down to &amp;lt;i&amp;gt;achievable&amp;lt;/i&amp;gt; goals These goals can be accomplished in single or multiple iterations.&lt;br /&gt;
*Asking whether a project is business &amp;lt;i&amp;gt;relevant&amp;lt;/i&amp;gt; helps in identifying the maximum potential of the project.&lt;br /&gt;
*A &amp;lt;i&amp;gt;timeboxed&amp;lt;/i&amp;gt; project helps in monitoring the progress of the project. It is also possible to estimate the velocity of the project using timeboxing.&lt;br /&gt;
&lt;br /&gt;
===Disadvantages/Limitations of SMART User Stories===&lt;br /&gt;
&lt;br /&gt;
*Some people prefer other kind of mnemonics such as INVEST rather than SMART as they feel that the thing that SMART stands for is not the same for all people. S may stand for Specific for some, Significant for some, Stretching for others, similarly M may be Measurable or Meaningful, likewise each of the alphabet of SMART has different meaning for different people.&lt;br /&gt;
*It is important that points assignment to user stories is done by someone experienced enough to understand the features that customers require as well as the complexity and technical details required to implement it successfully otherwise the velocity will be far from what is expected.&lt;br /&gt;
==&amp;lt;b&amp;gt;Conclusion&amp;lt;/b&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
[http://www.youtube.com/watch?v=XzV0dytYQq0 SaaS 4.2: SMART User stories]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://uxdesign.smashingmagazine.com/2011/09/13/the-s-m-a-r-t-user-experience-strategy/ SMART User experience strategy]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://xp123.com/articles/invest-in-good-stories-and-smart-tasks/ INVEST in good stories and SMART Tasks]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.chiefsimplicityofficer.com/2010/04/user-stories-its-smart-to-invest/ User stories: Its SMART to INVEST]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;See Also&amp;lt;/b&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/User_story Information on user stories]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://gigaom.com/2008/05/05/how-to-create-smart-tasks/ Information on SMART tasks]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.uncommon-knowledge.co.uk/goal_setting/smart_4.html Information on SMART goals]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/5_Whys Link for 5 Whys]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Nloya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_1w70_nl&amp;diff=70984</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 1w70 nl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_1w70_nl&amp;diff=70984"/>
		<updated>2012-11-20T01:04:14Z</updated>

		<summary type="html">&lt;p&gt;Nloya: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;b&amp;gt;SaaS - 4.2 - SMART User Stories&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt;==&lt;br /&gt;
User stories are the basis for defining the functionality of any given system. They are a short description of the system that capture what the system does and gives the expectation of how the system should behave.&lt;br /&gt;
When we say User Stories, we don’t define any particular criteria as to how a user story should be written. A user story can be “Customer should have a good UI experience” or “When a customer logs in he/she should be able to see all the technical details of the product he/she has selected, with the reviews, price displayed alongside and an option of ‘Add to Cart’ to go along with it.”&lt;br /&gt;
Both the user stories described above are correct but one leaves too much for one to assume and the other gives one specific information in terms of display and functionality. The problem with the first user story is it is not restricted to any particular guideline, its just a user story but has no scope and hence can be either very short or very long. The advantage with the second user story is that it has been written based on a given set of goals which can be acronymed as SMART and will be explained below.&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;SMART User Stories&amp;lt;/b&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
SMART is a mnemonic for&amp;lt;br&amp;gt;&lt;br /&gt;
*S - Specific&lt;br /&gt;
*M - Measurable&lt;br /&gt;
*A - Achievable&lt;br /&gt;
*R - Relevant&lt;br /&gt;
*T- Timeboxed&lt;br /&gt;
&lt;br /&gt;
===S -Specific/ M - Measurable===&lt;br /&gt;
The user story should be specific enough to capture the requirements of the user. The user can be the customer who requires the software or the end user who will be using the software. Many times the user stories are vague or ambiguous leading to a lot of loss in time and energy spent in development.&lt;br /&gt;
User stories can be made specific by using the terms 'Given, When and Then' which describe the user story. The term “Given” specifies the background scenarios. It specifies all the preconditions.&lt;br /&gt;
“When” specifies the input  to the system. “Then” specifies the desired result/s.&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
   Given I am at www.google.com&lt;br /&gt;
   When I click on the button Gmail&lt;br /&gt;
   Then I should be redirected to Gmail.&lt;br /&gt;
Each scenario should be testable i.e its progress should be measurable.  There should be  known good output for every input. Every project needs concrete criteria for measuring progress toward its completion. The reason behind this is that if the scenarios are not measurable, it is not possible to know whether a team is making progress toward successful completion. Measuring progress is supposed to help a team stay on track, reach its target dates, and experience the exhilaration of achievement that spurs it on to continued effort required to reach the ultimate goal.&lt;br /&gt;
&lt;br /&gt;
===A - Achievable / T - Timeboxed===&lt;br /&gt;
Goals should be set in such a way that it is achievable or at least a working model of it is achievable within a single iteration i.e. it is achievable within a time period. The reason for this is that Agile methodologies always aim for working models at the end of iteration, it doesn’t necessarily have to be a complete feature but a run-down version of it which is working partially and is able to provide a minimal set of functionality is also accepted.&lt;br /&gt;
If the feature is such that it may span over multiple iterations then it is a good idea to break it up into subset of stories such that each implemented subset provides a working model of the feature, however small it may be, so that constant progress is made to implement the feature and also a working code is provided at the end of each iteration.&lt;br /&gt;
&lt;br /&gt;
While its a good idea to divide a feature into sub-features and have user stories for each iteration, the question arises of how to decide on the number of user stories for each iteration and the number of iterations that may require for the complete feature to be implemented. This is usually accomplished using velocity which is an estimate of the kind of progress made in the past based on the difficulty of the user stories and the kind of progress that can be made by taking into consideration the difficulty of the user stories that are yet to be implemented.&lt;br /&gt;
&lt;br /&gt;
As features are broken down to sub-features and stories are written for the sub-feature, which is to be completed within the iteration, points should be assigned to each of the stories based on the difficulty level of the story and how fine grained approach for point-assignment does an assigner want. Say for example an assigner wants just a simple approach for point-assignment then he/she can assign from a range of 1-3 (where 1 being easy, 2 being medium and 3 being hard) and if a more fine grained approach is required then the range can be increased to 1-5 or 1-10. Whatever the approach is followed the important thing is to allocate points to each of the stories based on one’s estimate. At the end of each iteration, Velocity is calculated, which is nothing but the total number of points completed per iteration. As Velocity is not just the total of the stories but the total based on the difficulty level of the stories, it acts as an important guiding tool which can be leveraged by anyone to get to know details about the project as is shown below.&lt;br /&gt;
&lt;br /&gt;
Uses of Velocity:&lt;br /&gt;
&lt;br /&gt;
*Velocity can be used to plan future iterations&lt;br /&gt;
*It gives an estimate of how much time or iterations would be required to completely implement the feature&lt;br /&gt;
*It gives an idea of whether the team is on track as the velocity is expected to remain constant if all other variables are unchanged (other variables such as number of team members or replacement of an experienced team member with a new team member, etc.)&lt;br /&gt;
*It can provide an estimate if a change is requested by customers and based on the time required to implement the change and the importance level of the change the decision can be made whether to implement it or not.&lt;br /&gt;
&lt;br /&gt;
Following this approach allows a task to be timeboxed, i.e. limited to a specific duration. It provides a kind of expectation which makes the team-members aware that if something is not working out its time to seek help, split the task, change teams or do anything that will help in the completion of the task.&lt;br /&gt;
&lt;br /&gt;
At the initial phase, the task of assigning points to stories may seem a bit daunting and a bit like second guessing oneself but as the iterations pass on and based on the understanding of the feature and the experience one has in assigning points to user-stories, the estimation will always improve and at the end will be very close to the actual statistics. Also estimates can be changed if one feels an incorrect estimation was done but care should be taken that the variation is not too much.&lt;br /&gt;
&lt;br /&gt;
===R- business Relevant===&lt;br /&gt;
A user story should be of business value, i.e it should generate additional income or protect revenue. The software defined by the user story can increase the value of the product by generating interest among new users and thereby generating potential new customers.A software can also protect revenue by  streamlining processes to cut costs.&lt;br /&gt;
One way of determining the business relevance of a product is by asking the question “why” recursively. This is similar to a problem solving technique called  “5 Whys” where questions asked recursively for root cause analysis. The methodology can be extended here to recursively ask why developing a software is of business relevance to that company. It is assumed that after asking multiple times the reason will have some business relevance (for eg  “To increase in revenue for the company”) or there is no valid reason justifying the software project. &lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;Example&amp;lt;/b&amp;gt;==&lt;br /&gt;
Let us understand SMART User Stories by taking an example:&lt;br /&gt;
&lt;br /&gt;
   I want an application that shows me the best deals.&lt;br /&gt;
&lt;br /&gt;
There are all sorts of problems with the above user story. It doesn't fit any of the criterion we have set using our SMART User Stories approach. Let’s go over with each of the problems and try to improve our user story step-by-step.&lt;br /&gt;
&lt;br /&gt;
S-Specific / M-Measurable:&amp;lt;br&amp;gt;&lt;br /&gt;
The above example is anything but specific nor it seems measurable. Well it does say that there needs to be an application that shows the best deals but it doesn't mention to display the best deals from which all places or websites. Also it doesn't mention about what it wants the best deals on. Also as it doesn't mention about the websites it is difficult it to measure the story.&lt;br /&gt;
&lt;br /&gt;
A much better user story would have been:&amp;lt;br&amp;gt;&lt;br /&gt;
   I want an application that shows me the best deals on a particular product, which is entered by me before beginning the search, from the &amp;lt;br&amp;gt;  websites that I preselect.&lt;br /&gt;
&lt;br /&gt;
This says specifically on what product the user wants the search on and from which all websites. This is a very specific goal as there is no scope of assumption here. Of course the search results will be based on the specific words the user enters, but that is true for any website. The more specific you are in your search the more fine grained your search will be. Also because of the modified story, now it is easy to measure the story, as we can go through each website and compare prices and check whether the application did indeed return the best deals from various websites.&lt;br /&gt;
&lt;br /&gt;
A-Achievable:&amp;lt;br&amp;gt;&lt;br /&gt;
Appropriate timelines and deadlines should be set for implementing and testing the application. Suppose the client wants the above application for the Thanksgiving sale and he comes and asks for it during midweek of November, then creating the above story at that time wouldn’t be useful or advisable as the time period is too short for the goal to achieve.&lt;br /&gt;
&lt;br /&gt;
Assuming there is sufficient time for the application to be created and there are say 4 iterations possible. But the above story may not be practical for one iteration, one might need to break it down further to make it workable for 1 iteration as the target is to have a workable code at the end of each iteration. So the story for the particular iteration can be modified as:&lt;br /&gt;
&lt;br /&gt;
   Provide an interface for the user to provide the name of the product and the websites he/she wants to have a search in.&lt;br /&gt;
&lt;br /&gt;
This would be achievable for the first iteration. For the second iteration more functionality may be added:&lt;br /&gt;
&lt;br /&gt;
   Look for the price of the product in all of the websites given by the user and fetch all the results.&lt;br /&gt;
&lt;br /&gt;
This can be further modified in iteration 3 to give the best deal, based on price factor. This can be further modified to modify the result if any free goodies are being provided by any particular website. In this way the goal can be made achievable.&lt;br /&gt;
&lt;br /&gt;
T-Timeboxed&amp;lt;br&amp;gt;&lt;br /&gt;
All of the above 4 iterations that we planned should have the deadlines appropriately. If we suppose till one particular date if the team-member responsible for developing one particular functionality is not able to reach the target goal, it might be a good idea for him/her to ask to someone else or for some senior member to help out or to swap teams itself so that someone who has knowledge can work on that and can complete it without affecting the deadlines and making sure that the product is still workable at the end of that particular iteration. This should be followed for all the iterations. This will also allow sufficient time for testing which is a very important part of the application development.&lt;br /&gt;
&lt;br /&gt;
R-Relevant&amp;lt;br&amp;gt;&lt;br /&gt;
The story should be relevant so that the desired benefit can be obtained and maximized. Why would the client need it&lt;br /&gt;
*Probably because there are many websites which offer different deals and to get a single website which searches all the websites on behalf of the user or at least a subset of the websites would make it much easier for the user&lt;br /&gt;
*That will also lead to increase in the clicks the website gets&lt;br /&gt;
*Which will subsequently lead to increase in ads&lt;br /&gt;
*Which will lead to increase in revenue for the company&lt;br /&gt;
&lt;br /&gt;
Now the above goals are relevant for the application that user wants but it may not be relevant for the Terms and Conditions page or the login page that application may have.&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;Advantages/Disadvantages of SMART User stories&amp;lt;/b&amp;gt;==&lt;br /&gt;
===Advantages of SMART User stories===&lt;br /&gt;
Lets consider the advantages of SMART User stories by considering each letter of the mnemonic.&lt;br /&gt;
*Making a user story &amp;lt;i&amp;gt;specific&amp;lt;/i&amp;gt; makes the objectives of the project clear and prevent confusion amongst teams&lt;br /&gt;
*Having a well defined input /output relation makes the project &amp;lt;i&amp;gt;measurable&amp;lt;/i&amp;gt;/ testable for bugs and defects.&lt;br /&gt;
*Having a specific user story helps breaking the project down to &amp;lt;i&amp;gt;achievable&amp;lt;/i&amp;gt; goals These goals can be accomplished in single or multiple iterations.&lt;br /&gt;
*Asking whether a project is business &amp;lt;i&amp;gt;relevant&amp;lt;/i&amp;gt; helps in identifying the maximum potential of the project.&lt;br /&gt;
*A &amp;lt;i&amp;gt;timeboxed&amp;lt;/i&amp;gt; project helps in monitoring the progress of the project. It is also possible to estimate the velocity of the project using timeboxing.&lt;br /&gt;
===Disadvantages/Limitations of SMART User Stories===&lt;br /&gt;
&lt;br /&gt;
*Some people prefer other kind of mnemonics such as INVEST rather than SMART as they feel that the thing that SMART stands for is not the same for all people. S may stand for Specific for some, Significant for some, Stretching for others, similarly M may be Measurable or Meaningful, likewise each of the alphabet of SMART has different meaning for different people.&lt;br /&gt;
*It is important that points assignment to user stories is done by someone experienced enough to understand the features that customers require as well as the complexity and technical details required to implement it successfully otherwise the velocity will be far from what is expected.&lt;br /&gt;
==&amp;lt;b&amp;gt;Conclusion&amp;lt;/b&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
[http://www.youtube.com/watch?v=XzV0dytYQq0 SaaS 4.2: SMART User stories]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://uxdesign.smashingmagazine.com/2011/09/13/the-s-m-a-r-t-user-experience-strategy/ SMART User experience strategy]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://xp123.com/articles/invest-in-good-stories-and-smart-tasks/ INVEST in good stories and SMART Tasks]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.chiefsimplicityofficer.com/2010/04/user-stories-its-smart-to-invest/ User stories: Its SMART to INVEST]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;See Also&amp;lt;/b&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/User_story Information on user stories]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://gigaom.com/2008/05/05/how-to-create-smart-tasks/ Information on SMART tasks]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.uncommon-knowledge.co.uk/goal_setting/smart_4.html Information on SMART goals]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/5_Whys Link for 5 Whys]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Nloya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_1w70_nl&amp;diff=70982</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 1w70 nl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_1w70_nl&amp;diff=70982"/>
		<updated>2012-11-20T01:02:47Z</updated>

		<summary type="html">&lt;p&gt;Nloya: /* A - Achievable / T - Timeboxed */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;b&amp;gt;SaaS - 4.2 - SMART User Stories&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt;==&lt;br /&gt;
User stories are the basis for defining the functionality of any given system. They are a short description of the system that capture what the system does and gives the expectation of how the system should behave.&lt;br /&gt;
When we say User Stories, we don’t define any particular criteria as to how a user story should be written. A user story can be “Customer should have a good UI experience” or “When a customer logs in he/she should be able to see all the technical details of the product he/she has selected, with the reviews, price displayed alongside and an option of ‘Add to Cart’ to go along with it.”&lt;br /&gt;
Both the user stories described above are correct but one leaves too much for one to assume and the other gives one specific information in terms of display and functionality. The problem with the first user story is it is not restricted to any particular guideline, its just a user story but has no scope and hence can be either very short or very long. The advantage with the second user story is that it has been written based on a given set of goals which can be acronymed as SMART and will be explained below.&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;SMART User Stories&amp;lt;/b&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
SMART is a mnemonic for&amp;lt;br&amp;gt;&lt;br /&gt;
*S - Specific&lt;br /&gt;
*M - Measurable&lt;br /&gt;
*A - Achievable&lt;br /&gt;
*R - Relevant&lt;br /&gt;
*T- Timeboxed&lt;br /&gt;
&lt;br /&gt;
===S -Specific/ M - Measurable===&lt;br /&gt;
The user story should be specific enough to capture the requirements of the user. The user can be the customer who requires the software or the end user who will be using the software. Many times the user stories are vague or ambiguous leading to a lot of loss in time and energy spent in development.&lt;br /&gt;
User stories can be made specific by using the terms 'Given, When and Then' which describe the user story. The term “Given” specifies the background scenarios. It specifies all the preconditions.&lt;br /&gt;
“When” specifies the input  to the system. “Then” specifies the desired result/s.&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
   Given I am at www.google.com&lt;br /&gt;
   When I click on the button Gmail&lt;br /&gt;
   Then I should be redirected to Gmail.&lt;br /&gt;
Each scenario should be testable i.e its progress should be measurable.  There should be  known good output for every input. Every project needs concrete criteria for measuring progress toward its completion. The reason behind this is that if the scenarios are not measurable, it is not possible to know whether a team is making progress toward successful completion. Measuring progress is supposed to help a team stay on track, reach its target dates, and experience the exhilaration of achievement that spurs it on to continued effort required to reach the ultimate goal.&lt;br /&gt;
&lt;br /&gt;
===A - Achievable / T - Timeboxed===&lt;br /&gt;
Goals should be set in such a way that it is achievable or at least a working model of it is achievable within a single iteration i.e. it is achievable within a time period. The reason for this is that Agile methodologies always aim for working models at the end of iteration, it doesn’t necessarily have to be a complete feature but a run-down version of it which is working partially and is able to provide a minimal set of functionality is also accepted.&lt;br /&gt;
If the feature is such that it may span over multiple iterations then it is a good idea to break it up into subset of stories such that each implemented subset provides a working model of the feature, however small it may be, so that constant progress is made to implement the feature and also a working code is provided at the end of each iteration.&lt;br /&gt;
&lt;br /&gt;
While its a good idea to divide a feature into sub-features and have user stories for each iteration, the question arises of how to decide on the number of user stories for each iteration and the number of iterations that may require for the complete feature to be implemented. This is usually accomplished using velocity which is an estimate of the kind of progress made in the past based on the difficulty of the user stories and the kind of progress that can be made by taking into consideration the difficulty of the user stories that are yet to be implemented.&lt;br /&gt;
&lt;br /&gt;
As features are broken down to sub-features and stories are written for the sub-feature, which is to be completed within the iteration, points should be assigned to each of the stories based on the difficulty level of the story and how fine grained approach for point-assignment does an assigner want. Say for example an assigner wants just a simple approach for point-assignment then he/she can assign from a range of 1-3 (where 1 being easy, 2 being medium and 3 being hard) and if a more fine grained approach is required then the range can be increased to 1-5 or 1-10. Whatever the approach is followed the important thing is to allocate points to each of the stories based on one’s estimate. At the end of each iteration, Velocity is calculated, which is nothing but the total number of points completed per iteration. As Velocity is not just the total of the stories but the total based on the difficulty level of the stories, it acts as an important guiding tool which can be leveraged by anyone to get to know details about the project as is shown below.&lt;br /&gt;
&lt;br /&gt;
Uses of Velocity:&lt;br /&gt;
&lt;br /&gt;
*Velocity can be used to plan future iterations&lt;br /&gt;
*It gives an estimate of how much time or iterations would be required to completely implement the feature&lt;br /&gt;
*It gives an idea of whether the team is on track as the velocity is expected to remain constant if all other variables are unchanged (other variables such as number of team members or replacement of an experienced team member with a new team member, etc.)&lt;br /&gt;
*It can provide an estimate if a change is requested by customers and based on the time required to implement the change and the importance level of the change the decision can be made whether to implement it or not.&lt;br /&gt;
&lt;br /&gt;
Following this approach allows a task to be timeboxed, i.e. limited to a specific duration. It provides a kind of expectation which makes the team-members aware that if something is not working out its time to seek help, split the task, change teams or do anything that will help in the completion of the task.&lt;br /&gt;
&lt;br /&gt;
At the initial phase, the task of assigning points to stories may seem a bit daunting and a bit like second guessing oneself but as the iterations pass on and based on the understanding of the feature and the experience one has in assigning points to user-stories, the estimation will always improve and at the end will be very close to the actual statistics. Also estimates can be changed if one feels an incorrect estimation was done but care should be taken that the variation is not too much.&lt;br /&gt;
&lt;br /&gt;
===R- business Relevant===&lt;br /&gt;
A user story should be of business value, i.e it should generate additional income or protect revenue. The software defined by the user story can increase the value of the product by generating interest among new users and thereby generating potential new customers.A software can also protect revenue by  streamlining processes to cut costs.&lt;br /&gt;
One way of determining the business relevance of a product is by asking the question “why” recursively. This is similar to a problem solving technique called  “5 Whys” where questions asked recursively for root cause analysis. The methodology can be extended here to recursively ask why developing a software is of business relevance to that company. It is assumed that after asking multiple times the reason will have some business relevance (for eg  “To increase in revenue for the company”) or there is no valid reason justifying the software project. &lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;Example&amp;lt;/b&amp;gt;==&lt;br /&gt;
Let us understand SMART User Stories by taking an example:&lt;br /&gt;
&lt;br /&gt;
   I want an application that shows me the best deals.&lt;br /&gt;
&lt;br /&gt;
There all sorts of problems with the above user story. It doesn’t fit any of the criterion we have set using our SMART User Stories approach. Let’s go over with each of the problems and try to improve our user story step-by-step.&lt;br /&gt;
&lt;br /&gt;
S-Specific / M-Measurable:&amp;lt;br&amp;gt;&lt;br /&gt;
The above example is anything but specific nor it seems measurable. Well it does say that there needs to be an application that shows the best deals but it doesn’t mention to display the best deals from which all places or websites. Also it doesn’t mention about what it wants the best deals on. Also as it doesn’t mention about the websites it is difficult it to measure the story.&lt;br /&gt;
&lt;br /&gt;
A much better user story would have been:&amp;lt;br&amp;gt;&lt;br /&gt;
   I want an application that shows me the best deals on a particular product, which is entered by me before beginning the search, from the &amp;lt;br&amp;gt;  websites that I preselect.&lt;br /&gt;
&lt;br /&gt;
This says specifically on what product the user wants the search on and from which all websites. This is a very specific goal as there is no scope of assumption here. Of course the search results will be based on the specific words the user enters, but that is true for any website. The more specific you are in your search the more fine grained your search will be. Also because of the modified story, now it is easy to measure the story, as we can go through each website and compare prices and check whether the application did indeed return the best deals from various websites.&lt;br /&gt;
&lt;br /&gt;
A-Achievable:&amp;lt;br&amp;gt;&lt;br /&gt;
Appropriate timelines and deadlines should be set for implementing and testing the application. Suppose the client wants the above application for the Thanksgiving sale and he comes and asks for it during midweek of November, then creating the above story at that time wouldn’t be useful or advisable as the time period is too short for the goal to achieve.&lt;br /&gt;
&lt;br /&gt;
Assuming there is sufficient time for the application to be created and there are say 4 iterations possible. But the above story may not be practical for one iteration, one might need to break it down further to make it workable for 1 iteration as the target is to have a workable code at the end of each iteration. So the story for the particular iteration can be modified as:&lt;br /&gt;
&lt;br /&gt;
   Provide an interface for the user to provide the name of the product and the websites he/she wants to have a search in.&lt;br /&gt;
&lt;br /&gt;
This would be achievable for the first iteration. For the second iteration more functionality may be added:&lt;br /&gt;
&lt;br /&gt;
   Look for the price of the product in all of the websites given by the user and fetch all the results.&lt;br /&gt;
&lt;br /&gt;
This can be further modified in iteration 3 to give the best deal, based on price factor. This can be further modified to modify the result if any free goodies are being provided by any particular website. In this way the goal can be made achievable.&lt;br /&gt;
&lt;br /&gt;
T-Timeboxed&amp;lt;br&amp;gt;&lt;br /&gt;
All of the above 4 iterations that we planned should have the deadlines appropriately. If we suppose till one particular date if the team-member responsible for developing one particular functionality is not able to reach the target goal, it might be a good idea for him/her to ask to someone else or for some senior member to help out or to swap teams itself so that someone who has knowledge can work on that and can complete it without affecting the deadlines and making sure that the product is still workable at the end of that particular iteration. This should be followed for all the iterations. This will also allow sufficient time for testing which is a very important part of the application development.&lt;br /&gt;
&lt;br /&gt;
R-Relevant&amp;lt;br&amp;gt;&lt;br /&gt;
The story should be relevant so that the desired benefit can be obtained and maximized. Why would the client need it&lt;br /&gt;
*Probably because there are many websites which offer different deals and to get a single website which searches all the websites on behalf of the user or at least a subset of the websites would make it much easier for the user&lt;br /&gt;
*That will also lead to increase in the clicks the website gets&lt;br /&gt;
*Which will subsequently lead to increase in ads&lt;br /&gt;
*Which will lead to increase in revenue for the company&lt;br /&gt;
&lt;br /&gt;
Now the above goals are relevant for the application that user wants but it may not be relevant for the Terms and Conditions page or the login page that application may have.&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;Advantages/Disadvantages of SMART User stories&amp;lt;/b&amp;gt;==&lt;br /&gt;
===Advantages of SMART User stories===&lt;br /&gt;
Lets consider the advantages of SMART User stories by considering each letter of the mnemonic.&lt;br /&gt;
*Making a user story &amp;lt;i&amp;gt;specific&amp;lt;/i&amp;gt; makes the objectives of the project clear and prevent confusion amongst teams&lt;br /&gt;
*Having a well defined input /output relation makes the project &amp;lt;i&amp;gt;measurable&amp;lt;/i&amp;gt;/ testable for bugs and defects.&lt;br /&gt;
*Having a specific user story helps breaking the project down to &amp;lt;i&amp;gt;achievable&amp;lt;/i&amp;gt; goals These goals can be accomplished in single or multiple iterations.&lt;br /&gt;
*Asking whether a project is business &amp;lt;i&amp;gt;relevant&amp;lt;/i&amp;gt; helps in identifying the maximum potential of the project.&lt;br /&gt;
*A &amp;lt;i&amp;gt;timeboxed&amp;lt;/i&amp;gt; project helps in monitoring the progress of the project. It is also possible to estimate the velocity of the project using timeboxing.&lt;br /&gt;
===Disadvantages/Limitations of SMART User Stories===&lt;br /&gt;
&lt;br /&gt;
*Some people prefer other kind of mnemonics such as INVEST rather than SMART as they feel that the thing that SMART stands for is not the same for all people. S may stand for Specific for some, Significant for some, Stretching for others, similarly M may be Measurable or Meaningful, likewise each of the alphabet of SMART has different meaning for different people.&lt;br /&gt;
*It is important that points assignment to user stories is done by someone experienced enough to understand the features that customers require as well as the complexity and technical details required to implement it successfully otherwise the velocity will be far from what is expected.&lt;br /&gt;
==&amp;lt;b&amp;gt;Conclusion&amp;lt;/b&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
[http://www.youtube.com/watch?v=XzV0dytYQq0 SaaS 4.2: SMART User stories]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://uxdesign.smashingmagazine.com/2011/09/13/the-s-m-a-r-t-user-experience-strategy/ SMART User experience strategy]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://xp123.com/articles/invest-in-good-stories-and-smart-tasks/ INVEST in good stories and SMART Tasks]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.chiefsimplicityofficer.com/2010/04/user-stories-its-smart-to-invest/ User stories: Its SMART to INVEST]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;See Also&amp;lt;/b&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/User_story Information on user stories]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://gigaom.com/2008/05/05/how-to-create-smart-tasks/ Information on SMART tasks]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.uncommon-knowledge.co.uk/goal_setting/smart_4.html Information on SMART goals]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/5_Whys Link for 5 Whys]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Nloya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_1w70_nl&amp;diff=70977</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 1w70 nl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_1w70_nl&amp;diff=70977"/>
		<updated>2012-11-20T00:59:24Z</updated>

		<summary type="html">&lt;p&gt;Nloya: /* S -Specific/ M - Measurable */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;b&amp;gt;SaaS - 4.2 - SMART User Stories&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt;==&lt;br /&gt;
User stories are the basis for defining the functionality of any given system. They are a short description of the system that capture what the system does and gives the expectation of how the system should behave.&lt;br /&gt;
When we say User Stories, we don’t define any particular criteria as to how a user story should be written. A user story can be “Customer should have a good UI experience” or “When a customer logs in he/she should be able to see all the technical details of the product he/she has selected, with the reviews, price displayed alongside and an option of ‘Add to Cart’ to go along with it.”&lt;br /&gt;
Both the user stories described above are correct but one leaves too much for one to assume and the other gives one specific information in terms of display and functionality. The problem with the first user story is it is not restricted to any particular guideline, its just a user story but has no scope and hence can be either very short or very long. The advantage with the second user story is that it has been written based on a given set of goals which can be acronymed as SMART and will be explained below.&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;SMART User Stories&amp;lt;/b&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
SMART is a mnemonic for&amp;lt;br&amp;gt;&lt;br /&gt;
*S - Specific&lt;br /&gt;
*M - Measurable&lt;br /&gt;
*A - Achievable&lt;br /&gt;
*R - Relevant&lt;br /&gt;
*T- Timeboxed&lt;br /&gt;
&lt;br /&gt;
===S -Specific/ M - Measurable===&lt;br /&gt;
The user story should be specific enough to capture the requirements of the user. The user can be the customer who requires the software or the end user who will be using the software. Many times the user stories are vague or ambiguous leading to a lot of loss in time and energy spent in development.&lt;br /&gt;
User stories can be made specific by using the terms 'Given, When and Then' which describe the user story. The term “Given” specifies the background scenarios. It specifies all the preconditions.&lt;br /&gt;
“When” specifies the input  to the system. “Then” specifies the desired result/s.&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
   Given I am at www.google.com&lt;br /&gt;
   When I click on the button Gmail&lt;br /&gt;
   Then I should be redirected to Gmail.&lt;br /&gt;
Each scenario should be testable i.e its progress should be measurable.  There should be  known good output for every input. Every project needs concrete criteria for measuring progress toward its completion. The reason behind this is that if the scenarios are not measurable, it is not possible to know whether a team is making progress toward successful completion. Measuring progress is supposed to help a team stay on track, reach its target dates, and experience the exhilaration of achievement that spurs it on to continued effort required to reach the ultimate goal.&lt;br /&gt;
&lt;br /&gt;
===A - Achievable / T - Timeboxed===&lt;br /&gt;
Goals should be set in such a way that it is achievable or at least a working model of it is achievable within a single iteration i.e. it is achievable within a time period. The reason for this is that Agile methodologies always aim for working models at the end of iteration, it doesn’t necessarily have to be a complete feature but a run-down version of it which is working partially and is able to provide a minimal set of functionality is also accepted.&lt;br /&gt;
If the feature is such that it may span over multiple iterations then it is a good idea to break it up into subset of stories such that each implemented subset provides a working model of the feature, however small it may be so that constant progress is made to implement the feature and also a working code is provided at the end of each iteration.&lt;br /&gt;
&lt;br /&gt;
While its a good idea to divide a feature into sub-features and have user stories for each iteration, the question arises of how to decide on the number of user stories for each iteration and the number of iterations that may require for the complete feature to be implemented. This is usually accomplished using velocity which is an estimate of the kind of progress made in the past based on the difficulty of the user stories and the kind of progress that can be made by taking into consideration the difficulty of the user stories that are yet to be implemented.&lt;br /&gt;
&lt;br /&gt;
As features are broken down to sub-features and stories are written for the sub-feature, which is to be completed within the iteration, points should be assigned to each of the stories based on the difficulty level of the story and the how fine grained for point-assignment does an assignee want. Say for example an assignee wants just a simple approach for point-assignment then he/she can assign from a range of 1-3 (where 1 being easy, 2 being medium and 3 being hard) and if a more fine grained approach is required then the range can be increased to 1-5 or 1-10. Whatever the approach is followed the important thing is to allocate points to each of the stories based on one’s estimate. At the end of each iteration, Velocity is calculated, which is nothing but the total number of points completed per iteration. As Velocity is not just the total of the stories but the total based on the difficulty level of the stories, it acts as an important guiding tool which can be leveraged by anyone to get to know details about the project as is shown below.&lt;br /&gt;
&lt;br /&gt;
Uses of Velocity:&lt;br /&gt;
&lt;br /&gt;
*Velocity can be used to plan future iterations&lt;br /&gt;
*It gives an estimate of how much time or iterations would be required to completely implement the feature&lt;br /&gt;
*It gives an idea of whether the team is on track as the velocity is expected to remain constant if all other variables are unchanged (other variables such as number of team members or replacement of an experienced team member with a new team member, etc.)&lt;br /&gt;
*It can provide an estimate if a change is requested by customers and based on the time required to implement the change and the importance level of the change the decision can be made whether to implement it or not.&lt;br /&gt;
&lt;br /&gt;
Following this approach allows a task to be timeboxed, i.e. limited to a specific duration. It provides a kind of expectation which makes the team-members aware that if something is not working out its time to seek help, split the task, change teams or do anything that will help in the completion of the task.&lt;br /&gt;
&lt;br /&gt;
At the initial phase, the task of assigning points to stories may seem a bit daunting and a bit like second guessing oneself but as the iterations pass on and based on the understanding of the feature and the experience one has in assigning points to user-stories, the estimation will always improve and at the end will be very close to the actual statistics. Also estimates can be changed if one feels an incorrect estimation was done but care should be taken that the variation is not too much.&lt;br /&gt;
&lt;br /&gt;
===R- business Relevant===&lt;br /&gt;
A user story should be of business value, i.e it should generate additional income or protect revenue. The software defined by the user story can increase the value of the product by generating interest among new users and thereby generating potential new customers.A software can also protect revenue by  streamlining processes to cut costs.&lt;br /&gt;
One way of determining the business relevance of a product is by asking the question “why” recursively. This is similar to a problem solving technique called  “5 Whys” where questions asked recursively for root cause analysis. The methodology can be extended here to recursively ask why developing a software is of business relevance to that company. It is assumed that after asking multiple times the reason will have some business relevance (for eg  “To increase in revenue for the company”) or there is no valid reason justifying the software project. &lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;Example&amp;lt;/b&amp;gt;==&lt;br /&gt;
Let us understand SMART User Stories by taking an example:&lt;br /&gt;
&lt;br /&gt;
   I want an application that shows me the best deals.&lt;br /&gt;
&lt;br /&gt;
There all sorts of problems with the above user story. It doesn’t fit any of the criterion we have set using our SMART User Stories approach. Let’s go over with each of the problems and try to improve our user story step-by-step.&lt;br /&gt;
&lt;br /&gt;
S-Specific / M-Measurable:&amp;lt;br&amp;gt;&lt;br /&gt;
The above example is anything but specific nor it seems measurable. Well it does say that there needs to be an application that shows the best deals but it doesn’t mention to display the best deals from which all places or websites. Also it doesn’t mention about what it wants the best deals on. Also as it doesn’t mention about the websites it is difficult it to measure the story.&lt;br /&gt;
&lt;br /&gt;
A much better user story would have been:&amp;lt;br&amp;gt;&lt;br /&gt;
   I want an application that shows me the best deals on a particular product, which is entered by me before beginning the search, from the &amp;lt;br&amp;gt;  websites that I preselect.&lt;br /&gt;
&lt;br /&gt;
This says specifically on what product the user wants the search on and from which all websites. This is a very specific goal as there is no scope of assumption here. Of course the search results will be based on the specific words the user enters, but that is true for any website. The more specific you are in your search the more fine grained your search will be. Also because of the modified story, now it is easy to measure the story, as we can go through each website and compare prices and check whether the application did indeed return the best deals from various websites.&lt;br /&gt;
&lt;br /&gt;
A-Achievable:&amp;lt;br&amp;gt;&lt;br /&gt;
Appropriate timelines and deadlines should be set for implementing and testing the application. Suppose the client wants the above application for the Thanksgiving sale and he comes and asks for it during midweek of November, then creating the above story at that time wouldn’t be useful or advisable as the time period is too short for the goal to achieve.&lt;br /&gt;
&lt;br /&gt;
Assuming there is sufficient time for the application to be created and there are say 4 iterations possible. But the above story may not be practical for one iteration, one might need to break it down further to make it workable for 1 iteration as the target is to have a workable code at the end of each iteration. So the story for the particular iteration can be modified as:&lt;br /&gt;
&lt;br /&gt;
   Provide an interface for the user to provide the name of the product and the websites he/she wants to have a search in.&lt;br /&gt;
&lt;br /&gt;
This would be achievable for the first iteration. For the second iteration more functionality may be added:&lt;br /&gt;
&lt;br /&gt;
   Look for the price of the product in all of the websites given by the user and fetch all the results.&lt;br /&gt;
&lt;br /&gt;
This can be further modified in iteration 3 to give the best deal, based on price factor. This can be further modified to modify the result if any free goodies are being provided by any particular website. In this way the goal can be made achievable.&lt;br /&gt;
&lt;br /&gt;
T-Timeboxed&amp;lt;br&amp;gt;&lt;br /&gt;
All of the above 4 iterations that we planned should have the deadlines appropriately. If we suppose till one particular date if the team-member responsible for developing one particular functionality is not able to reach the target goal, it might be a good idea for him/her to ask to someone else or for some senior member to help out or to swap teams itself so that someone who has knowledge can work on that and can complete it without affecting the deadlines and making sure that the product is still workable at the end of that particular iteration. This should be followed for all the iterations. This will also allow sufficient time for testing which is a very important part of the application development.&lt;br /&gt;
&lt;br /&gt;
R-Relevant&amp;lt;br&amp;gt;&lt;br /&gt;
The story should be relevant so that the desired benefit can be obtained and maximized. Why would the client need it&lt;br /&gt;
*Probably because there are many websites which offer different deals and to get a single website which searches all the websites on behalf of the user or at least a subset of the websites would make it much easier for the user&lt;br /&gt;
*That will also lead to increase in the clicks the website gets&lt;br /&gt;
*Which will subsequently lead to increase in ads&lt;br /&gt;
*Which will lead to increase in revenue for the company&lt;br /&gt;
&lt;br /&gt;
Now the above goals are relevant for the application that user wants but it may not be relevant for the Terms and Conditions page or the login page that application may have.&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;Advantages/Disadvantages of SMART User stories&amp;lt;/b&amp;gt;==&lt;br /&gt;
===Advantages of SMART User stories===&lt;br /&gt;
Lets consider the advantages of SMART User stories by considering each letter of the mnemonic.&lt;br /&gt;
*Making a user story &amp;lt;i&amp;gt;specific&amp;lt;/i&amp;gt; makes the objectives of the project clear and prevent confusion amongst teams&lt;br /&gt;
*Having a well defined input /output relation makes the project &amp;lt;i&amp;gt;measurable&amp;lt;/i&amp;gt;/ testable for bugs and defects.&lt;br /&gt;
*Having a specific user story helps breaking the project down to &amp;lt;i&amp;gt;achievable&amp;lt;/i&amp;gt; goals These goals can be accomplished in single or multiple iterations.&lt;br /&gt;
*Asking whether a project is business &amp;lt;i&amp;gt;relevant&amp;lt;/i&amp;gt; helps in identifying the maximum potential of the project.&lt;br /&gt;
*A &amp;lt;i&amp;gt;timeboxed&amp;lt;/i&amp;gt; project helps in monitoring the progress of the project. It is also possible to estimate the velocity of the project using timeboxing.&lt;br /&gt;
===Disadvantages/Limitations of SMART User Stories===&lt;br /&gt;
&lt;br /&gt;
*Some people prefer other kind of mnemonics such as INVEST rather than SMART as they feel that the thing that SMART stands for is not the same for all people. S may stand for Specific for some, Significant for some, Stretching for others, similarly M may be Measurable or Meaningful, likewise each of the alphabet of SMART has different meaning for different people.&lt;br /&gt;
*It is important that points assignment to user stories is done by someone experienced enough to understand the features that customers require as well as the complexity and technical details required to implement it successfully otherwise the velocity will be far from what is expected.&lt;br /&gt;
==&amp;lt;b&amp;gt;Conclusion&amp;lt;/b&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
[http://www.youtube.com/watch?v=XzV0dytYQq0 SaaS 4.2: SMART User stories]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://uxdesign.smashingmagazine.com/2011/09/13/the-s-m-a-r-t-user-experience-strategy/ SMART User experience strategy]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://xp123.com/articles/invest-in-good-stories-and-smart-tasks/ INVEST in good stories and SMART Tasks]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.chiefsimplicityofficer.com/2010/04/user-stories-its-smart-to-invest/ User stories: Its SMART to INVEST]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;b&amp;gt;See Also&amp;lt;/b&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/User_story Information on user stories]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://gigaom.com/2008/05/05/how-to-create-smart-tasks/ Information on SMART tasks]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.uncommon-knowledge.co.uk/goal_setting/smart_4.html Information on SMART goals]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/5_Whys Link for 5 Whys]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Nloya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65347</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=65347"/>
		<updated>2012-09-20T03:59:30Z</updated>

		<summary type="html">&lt;p&gt;Nloya: /* Similar functionality in other languages */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&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 called 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 following example, if within method_missing() we define an undefined method, we get a stack level too deep error message.&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 becomes 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;
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;
=='''Similar functionality in other languages'''==&lt;br /&gt;
Method missing, one of the dynamic features of Ruby, is not a feature that is unique to Ruby. It exists in Smalltalk, Python, Groovy, some Javascripts and most CLOS (Common Lisp Object System)extensions. In this section we look at the few such similar implementations in other languages. The table below gives different ways the functionality related to method_missing is handled in other languages.&amp;lt;ref&amp;gt;http://olabini.com/blog/2010/04/patterns-of-method-missing/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 '''Construct'''                          '''Language '''&lt;br /&gt;
 AUTOLOAD                           Perl&lt;br /&gt;
 AUTOSCALAR, AUTOMETH, AUTOLOAD...  Perl6&lt;br /&gt;
 __getattr__                        Python&lt;br /&gt;
 method_missing                     Ruby&lt;br /&gt;
 doesNotUnderstand                  Smalltalk&lt;br /&gt;
 __noSuchMethod__(1)                CoffeeScript, JavaScript&lt;br /&gt;
 unknown                            Tcl&lt;br /&gt;
 no-applicable-method               Common Lisp&lt;br /&gt;
 doesNotRecognizeSelector           Objective-C&lt;br /&gt;
 TryInvokeMember(2)                 C#&lt;br /&gt;
 match [name, args] { ... }         E&lt;br /&gt;
 the predicate fail                 Prolog&lt;br /&gt;
 forward                            Io&lt;br /&gt;
&lt;br /&gt;
(1) supported by Firefox&lt;br /&gt;
&lt;br /&gt;
(2) only for dynamic objects&lt;br /&gt;
&lt;br /&gt;
Table Reference&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/2865865/are-there-equivalents-to-rubys-method-missing-in-other-languages&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''_getattr_ implementation in Python'''&amp;lt;ref&amp;gt;http://docs.python.org/reference/datamodel.html?highlight=__getattr__#object.__getattr__&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
object.__getattr__(self,name)&lt;br /&gt;
&lt;br /&gt;
This method is called when an attribute lookup has not found the attribute in the usual places i.e. it is not an instance attribute nor is it found in the class tree for self. name is the attribute name. This method should return the (computed) attribute value or raise an AttributeError exception.&lt;br /&gt;
&lt;br /&gt;
class Roman(object):&lt;br /&gt;
  def roman_to_int(self, roman):&lt;br /&gt;
    # implementation here&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def __getattr__(self, name):&lt;br /&gt;
    return self.roman_to_int(name)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; r = Roman()&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; r.iv&lt;br /&gt;
&lt;br /&gt;
4&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''doesNotUnderstand in Smalltalk language'''&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?DoesNotUnderstand&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In SmalltalkLanguage When a receiver is asked to perform a method that is unknown to it, then a run-time complaint is issued which is #doesNotUnderstand.&lt;br /&gt;
When a Smalltalk object is sent a message for a method it has not defined, the runtime system turns the message-send into an object and sends #doesNotUnderstand: to the original receiver with this message-send object as argument. By default the #doesNotUnderstand: method raises an exception, but the receiver can override it and implement it in a way that he sees fit.&lt;br /&gt;
&lt;br /&gt;
*'''Other languages'''&lt;br /&gt;
JavaScript also has a method which has an implementation similar to that of method_missing and that is &amp;quot;noSuchMethod&amp;quot;. The limitation of this method is that it is only supported by Firefox/Spidermonkey.&lt;br /&gt;
&lt;br /&gt;
Similarly, Perl has an AUTOLOAD method which works on subroutines &amp;amp; class/object methods.&lt;br /&gt;
&lt;br /&gt;
=='''Patterns of method missing&amp;lt;ref&amp;gt;http://olabini.com/blog/2010/04/patterns-of-method-missing/&amp;lt;/ref&amp;gt;'''== &lt;br /&gt;
Now that we have covered all the important areas about method missing including the advantages, the disadvantages and key points related to its functionality, it would be appropriate to know about the different ways method_missing is used and what are the consequences of its use.&lt;br /&gt;
&lt;br /&gt;
* Providing Debug information on Failure&lt;br /&gt;
Well as method missing is called when there is no object to handle the method being called, we can use method_missing to include more information about the reasons for it being called, i.e. to say that we can provide users with more information about the error messages and hence make the life of the programmers easy and provide a faster way to solve the bugs.&lt;br /&gt;
&lt;br /&gt;
* Encode parameters in method name&lt;br /&gt;
Instead of sending method as explicit parameters, another method is to use the name to encode parameters. Find below a Rails-style find expression:&lt;br /&gt;
Person.find_by_name_and_age(&amp;quot;ABC&amp;quot;,30)&lt;br /&gt;
Another way of writing the same:&lt;br /&gt;
Person.find_by(:name =&amp;gt; &amp;quot;ABC&amp;quot;, :age =&amp;gt; 30)&lt;br /&gt;
&lt;br /&gt;
The disadvantage of this is that creating such kind of API's make it difficult to debug and maintain the application.&lt;br /&gt;
&lt;br /&gt;
* Builders&lt;br /&gt;
The idea of a builder is that you use Ruby’s blocks and method_missing to make it easy to create any kind of output structure. You create a builder object and then send it messages and it responds to the messages by building up a data structure based on those messages. For example, the following code&lt;br /&gt;
&lt;br /&gt;
  builder = Builder::XmlMarkup.new(&amp;quot;&amp;quot;, 2)&lt;br /&gt;
  puts builder.person {&lt;br /&gt;
    name(&amp;quot;ABC&amp;quot;)&lt;br /&gt;
    phone(&amp;quot;12345&amp;quot;, &amp;quot;local&amp;quot;=&amp;gt;&amp;quot;yes&amp;quot;)&lt;br /&gt;
    address(&amp;quot;Raleigh&amp;quot;)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
will print&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;person&amp;gt;&lt;br /&gt;
    &amp;lt;name&amp;gt;ABC&amp;lt;/name&amp;gt;&lt;br /&gt;
    &amp;lt;phone local=&amp;quot;yes&amp;quot;&amp;gt;12345&amp;lt;/phone&amp;gt;&lt;br /&gt;
    &amp;lt;address&amp;gt;Raleigh&amp;lt;/address&amp;gt;&lt;br /&gt;
  &amp;lt;/person&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here we have defined a method_missing method and it handles any undefined method and adds the name of the method to the XML markup that is being built. Code blocks are used to capture the nested nature of the XML. The result is a very natural way to programmatically generate XML markup. Also the cumbersome task of closing the tags and escaping rules are taken care of for us.&lt;br /&gt;
&lt;br /&gt;
* Accessors&lt;br /&gt;
The inversion of the builder pattern is to use a parser that goes through the XML document and then allow access to the elements by using method_missing.&lt;br /&gt;
&lt;br /&gt;
* Test Helpers&lt;br /&gt;
Different kind of test helpers can be created using method_missing. Many of the open source Ruby projects implementations of method missing are found in the tests.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
method_missing is a very powerful feature of Ruby and as is the way with powerful things it can help you a great deal if used properly but it can make things a lot harder for you if implemented incorrectly. It is a kind of a feature which should be used sparingly, if not at all. And there are things that needs to be taken into consideration, as mentioned in the Key Points section above, if method_missing is to be implemented.&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>Nloya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65346</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=65346"/>
		<updated>2012-09-20T03:58:40Z</updated>

		<summary type="html">&lt;p&gt;Nloya: /* Similar functionality in other languages */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&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 called 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 following example, if within method_missing() we define an undefined method, we get a stack level too deep error message.&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 becomes 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;
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;
=='''Similar functionality in other languages'''==&lt;br /&gt;
Method missing, one of the dynamic features of Ruby, is not a feature that is unique to Ruby. It exists in Smalltalk, Python, Groovy, some Javascripts and most CLOS (Common Lisp Object System)extensions. In this section we look at the few such similar implementations in other languages. The table below gives different ways the functionality related to method_missing is handled in other languages.&amp;lt;ref&amp;gt;http://olabini.com/blog/2010/04/patterns-of-method-missing/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 '''Construct'''                          '''Language '''&lt;br /&gt;
 AUTOLOAD                           Perl&lt;br /&gt;
 AUTOSCALAR, AUTOMETH, AUTOLOAD...  Perl6&lt;br /&gt;
 __getattr__                        Python&lt;br /&gt;
 method_missing                     Ruby&lt;br /&gt;
 doesNotUnderstand                  Smalltalk&lt;br /&gt;
 __noSuchMethod__(1)                CoffeeScript, JavaScript&lt;br /&gt;
 unknown                            Tcl&lt;br /&gt;
 no-applicable-method               Common Lisp&lt;br /&gt;
 doesNotRecognizeSelector           Objective-C&lt;br /&gt;
 TryInvokeMember(2)                 C#&lt;br /&gt;
 match [name, args] { ... }         E&lt;br /&gt;
 the predicate fail                 Prolog&lt;br /&gt;
 forward                            Io&lt;br /&gt;
&lt;br /&gt;
(1) supported by Firefox&lt;br /&gt;
&lt;br /&gt;
(2) only for dynamic objects&lt;br /&gt;
&lt;br /&gt;
Table Reference&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/2865865/are-there-equivalents-to-rubys-method-missing-in-other-languages&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''_getattr_ implementation in Python'''&amp;lt;ref&amp;gt;http://docs.python.org/reference/datamodel.html?highlight=__getattr__#object.__getattr__&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
object.__getattr__(self,name)&lt;br /&gt;
&lt;br /&gt;
This method is called when an attribute lookup has not found the attribute in the usual places i.e. it is not an instance attribute nor is it found in the class tree for self. name is the attribute name. This method should return the (computed) attribute value or raise an AttributeError exception.&lt;br /&gt;
&lt;br /&gt;
class Roman(object):&lt;br /&gt;
  def roman_to_int(self, roman):&lt;br /&gt;
    # implementation here&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def __getattr__(self, name):&lt;br /&gt;
    return self.roman_to_int(name)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; r = Roman()&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; r.iv&lt;br /&gt;
4&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''doesNotUnderstand in Smalltalk language'''&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?DoesNotUnderstand&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In SmalltalkLanguage When a receiver is asked to perform a method that is unknown to it, then a run-time complaint is issued which is #doesNotUnderstand.&lt;br /&gt;
When a Smalltalk object is sent a message for a method it has not defined, the runtime system turns the message-send into an object and sends #doesNotUnderstand: to the original receiver with this message-send object as argument. By default the #doesNotUnderstand: method raises an exception, but the receiver can override it and implement it in a way that he sees fit.&lt;br /&gt;
&lt;br /&gt;
*'''Other languages'''&lt;br /&gt;
JavaScript also has a method which has an implementation similar to that of method_missing and that is &amp;quot;noSuchMethod&amp;quot;. The limitation of this method is that it is only supported by Firefox/Spidermonkey.&lt;br /&gt;
&lt;br /&gt;
Similarly, Perl has an AUTOLOAD method which works on subroutines &amp;amp; class/object methods.&lt;br /&gt;
&lt;br /&gt;
=='''Patterns of method missing&amp;lt;ref&amp;gt;http://olabini.com/blog/2010/04/patterns-of-method-missing/&amp;lt;/ref&amp;gt;'''== &lt;br /&gt;
Now that we have covered all the important areas about method missing including the advantages, the disadvantages and key points related to its functionality, it would be appropriate to know about the different ways method_missing is used and what are the consequences of its use.&lt;br /&gt;
&lt;br /&gt;
* Providing Debug information on Failure&lt;br /&gt;
Well as method missing is called when there is no object to handle the method being called, we can use method_missing to include more information about the reasons for it being called, i.e. to say that we can provide users with more information about the error messages and hence make the life of the programmers easy and provide a faster way to solve the bugs.&lt;br /&gt;
&lt;br /&gt;
* Encode parameters in method name&lt;br /&gt;
Instead of sending method as explicit parameters, another method is to use the name to encode parameters. Find below a Rails-style find expression:&lt;br /&gt;
Person.find_by_name_and_age(&amp;quot;ABC&amp;quot;,30)&lt;br /&gt;
Another way of writing the same:&lt;br /&gt;
Person.find_by(:name =&amp;gt; &amp;quot;ABC&amp;quot;, :age =&amp;gt; 30)&lt;br /&gt;
&lt;br /&gt;
The disadvantage of this is that creating such kind of API's make it difficult to debug and maintain the application.&lt;br /&gt;
&lt;br /&gt;
* Builders&lt;br /&gt;
The idea of a builder is that you use Ruby’s blocks and method_missing to make it easy to create any kind of output structure. You create a builder object and then send it messages and it responds to the messages by building up a data structure based on those messages. For example, the following code&lt;br /&gt;
&lt;br /&gt;
  builder = Builder::XmlMarkup.new(&amp;quot;&amp;quot;, 2)&lt;br /&gt;
  puts builder.person {&lt;br /&gt;
    name(&amp;quot;ABC&amp;quot;)&lt;br /&gt;
    phone(&amp;quot;12345&amp;quot;, &amp;quot;local&amp;quot;=&amp;gt;&amp;quot;yes&amp;quot;)&lt;br /&gt;
    address(&amp;quot;Raleigh&amp;quot;)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
will print&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;person&amp;gt;&lt;br /&gt;
    &amp;lt;name&amp;gt;ABC&amp;lt;/name&amp;gt;&lt;br /&gt;
    &amp;lt;phone local=&amp;quot;yes&amp;quot;&amp;gt;12345&amp;lt;/phone&amp;gt;&lt;br /&gt;
    &amp;lt;address&amp;gt;Raleigh&amp;lt;/address&amp;gt;&lt;br /&gt;
  &amp;lt;/person&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here we have defined a method_missing method and it handles any undefined method and adds the name of the method to the XML markup that is being built. Code blocks are used to capture the nested nature of the XML. The result is a very natural way to programmatically generate XML markup. Also the cumbersome task of closing the tags and escaping rules are taken care of for us.&lt;br /&gt;
&lt;br /&gt;
* Accessors&lt;br /&gt;
The inversion of the builder pattern is to use a parser that goes through the XML document and then allow access to the elements by using method_missing.&lt;br /&gt;
&lt;br /&gt;
* Test Helpers&lt;br /&gt;
Different kind of test helpers can be created using method_missing. Many of the open source Ruby projects implementations of method missing are found in the tests.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
method_missing is a very powerful feature of Ruby and as is the way with powerful things it can help you a great deal if used properly but it can make things a lot harder for you if implemented incorrectly. It is a kind of a feature which should be used sparingly, if not at all. And there are things that needs to be taken into consideration, as mentioned in the Key Points section above, if method_missing is to be implemented.&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>Nloya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65345</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=65345"/>
		<updated>2012-09-20T03:58:20Z</updated>

		<summary type="html">&lt;p&gt;Nloya: /* Similar functionality in other languages */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&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 called 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 following example, if within method_missing() we define an undefined method, we get a stack level too deep error message.&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 becomes 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;
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;
=='''Similar functionality in other languages'''==&lt;br /&gt;
Method missing, one of the dynamic features of Ruby, is not a feature that is unique to Ruby. It exists in Smalltalk, Python, Groovy, some Javascripts and most CLOS (Common Lisp Object System)extensions. In this section we look at the few such similar implementations in other languages. The table below gives different ways the functionality related to method_missing is handled in other languages.&amp;lt;ref&amp;gt;http://olabini.com/blog/2010/04/patterns-of-method-missing/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 '''Construct'''                          '''Language '''&lt;br /&gt;
 AUTOLOAD                           Perl&lt;br /&gt;
 AUTOSCALAR, AUTOMETH, AUTOLOAD...  Perl6&lt;br /&gt;
 __getattr__                        Python&lt;br /&gt;
 method_missing                     Ruby&lt;br /&gt;
 doesNotUnderstand                  Smalltalk&lt;br /&gt;
 __noSuchMethod__(1)                CoffeeScript, JavaScript&lt;br /&gt;
 unknown                            Tcl&lt;br /&gt;
 no-applicable-method               Common Lisp&lt;br /&gt;
 doesNotRecognizeSelector           Objective-C&lt;br /&gt;
 TryInvokeMember(2)                 C#&lt;br /&gt;
 match [name, args] { ... }         E&lt;br /&gt;
 the predicate fail                 Prolog&lt;br /&gt;
 forward                            Io&lt;br /&gt;
&lt;br /&gt;
(1) supported by Firefox&lt;br /&gt;
(2) only for dynamic objects&lt;br /&gt;
Table Reference&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/2865865/are-there-equivalents-to-rubys-method-missing-in-other-languages&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''_getattr_ implementation in Python'''&amp;lt;ref&amp;gt;http://docs.python.org/reference/datamodel.html?highlight=__getattr__#object.__getattr__&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
object.__getattr__(self,name)&lt;br /&gt;
&lt;br /&gt;
This method is called when an attribute lookup has not found the attribute in the usual places i.e. it is not an instance attribute nor is it found in the class tree for self. name is the attribute name. This method should return the (computed) attribute value or raise an AttributeError exception.&lt;br /&gt;
&lt;br /&gt;
class Roman(object):&lt;br /&gt;
  def roman_to_int(self, roman):&lt;br /&gt;
    # implementation here&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def __getattr__(self, name):&lt;br /&gt;
    return self.roman_to_int(name)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; r = Roman()&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; r.iv&lt;br /&gt;
4&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''doesNotUnderstand in Smalltalk language'''&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?DoesNotUnderstand&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In SmalltalkLanguage When a receiver is asked to perform a method that is unknown to it, then a run-time complaint is issued which is #doesNotUnderstand.&lt;br /&gt;
When a Smalltalk object is sent a message for a method it has not defined, the runtime system turns the message-send into an object and sends #doesNotUnderstand: to the original receiver with this message-send object as argument. By default the #doesNotUnderstand: method raises an exception, but the receiver can override it and implement it in a way that he sees fit.&lt;br /&gt;
&lt;br /&gt;
*'''Other languages'''&lt;br /&gt;
JavaScript also has a method which has an implementation similar to that of method_missing and that is &amp;quot;noSuchMethod&amp;quot;. The limitation of this method is that it is only supported by Firefox/Spidermonkey.&lt;br /&gt;
&lt;br /&gt;
Similarly, Perl has an AUTOLOAD method which works on subroutines &amp;amp; class/object methods.&lt;br /&gt;
&lt;br /&gt;
=='''Patterns of method missing&amp;lt;ref&amp;gt;http://olabini.com/blog/2010/04/patterns-of-method-missing/&amp;lt;/ref&amp;gt;'''== &lt;br /&gt;
Now that we have covered all the important areas about method missing including the advantages, the disadvantages and key points related to its functionality, it would be appropriate to know about the different ways method_missing is used and what are the consequences of its use.&lt;br /&gt;
&lt;br /&gt;
* Providing Debug information on Failure&lt;br /&gt;
Well as method missing is called when there is no object to handle the method being called, we can use method_missing to include more information about the reasons for it being called, i.e. to say that we can provide users with more information about the error messages and hence make the life of the programmers easy and provide a faster way to solve the bugs.&lt;br /&gt;
&lt;br /&gt;
* Encode parameters in method name&lt;br /&gt;
Instead of sending method as explicit parameters, another method is to use the name to encode parameters. Find below a Rails-style find expression:&lt;br /&gt;
Person.find_by_name_and_age(&amp;quot;ABC&amp;quot;,30)&lt;br /&gt;
Another way of writing the same:&lt;br /&gt;
Person.find_by(:name =&amp;gt; &amp;quot;ABC&amp;quot;, :age =&amp;gt; 30)&lt;br /&gt;
&lt;br /&gt;
The disadvantage of this is that creating such kind of API's make it difficult to debug and maintain the application.&lt;br /&gt;
&lt;br /&gt;
* Builders&lt;br /&gt;
The idea of a builder is that you use Ruby’s blocks and method_missing to make it easy to create any kind of output structure. You create a builder object and then send it messages and it responds to the messages by building up a data structure based on those messages. For example, the following code&lt;br /&gt;
&lt;br /&gt;
  builder = Builder::XmlMarkup.new(&amp;quot;&amp;quot;, 2)&lt;br /&gt;
  puts builder.person {&lt;br /&gt;
    name(&amp;quot;ABC&amp;quot;)&lt;br /&gt;
    phone(&amp;quot;12345&amp;quot;, &amp;quot;local&amp;quot;=&amp;gt;&amp;quot;yes&amp;quot;)&lt;br /&gt;
    address(&amp;quot;Raleigh&amp;quot;)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
will print&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;person&amp;gt;&lt;br /&gt;
    &amp;lt;name&amp;gt;ABC&amp;lt;/name&amp;gt;&lt;br /&gt;
    &amp;lt;phone local=&amp;quot;yes&amp;quot;&amp;gt;12345&amp;lt;/phone&amp;gt;&lt;br /&gt;
    &amp;lt;address&amp;gt;Raleigh&amp;lt;/address&amp;gt;&lt;br /&gt;
  &amp;lt;/person&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here we have defined a method_missing method and it handles any undefined method and adds the name of the method to the XML markup that is being built. Code blocks are used to capture the nested nature of the XML. The result is a very natural way to programmatically generate XML markup. Also the cumbersome task of closing the tags and escaping rules are taken care of for us.&lt;br /&gt;
&lt;br /&gt;
* Accessors&lt;br /&gt;
The inversion of the builder pattern is to use a parser that goes through the XML document and then allow access to the elements by using method_missing.&lt;br /&gt;
&lt;br /&gt;
* Test Helpers&lt;br /&gt;
Different kind of test helpers can be created using method_missing. Many of the open source Ruby projects implementations of method missing are found in the tests.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
method_missing is a very powerful feature of Ruby and as is the way with powerful things it can help you a great deal if used properly but it can make things a lot harder for you if implemented incorrectly. It is a kind of a feature which should be used sparingly, if not at all. And there are things that needs to be taken into consideration, as mentioned in the Key Points section above, if method_missing is to be implemented.&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>Nloya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65344</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=65344"/>
		<updated>2012-09-20T03:57:44Z</updated>

		<summary type="html">&lt;p&gt;Nloya: /* Similar functionality in other languages */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&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 called 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 following example, if within method_missing() we define an undefined method, we get a stack level too deep error message.&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 becomes 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;
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;
=='''Similar functionality in other languages'''==&lt;br /&gt;
Method missing, one of the dynamic features of Ruby, is not a feature that is unique to Ruby. It exists in Smalltalk, Python, Groovy, some Javascripts and most CLOS (Common Lisp Object System)extensions. In this section we look at the few such similar implementations in other languages. The table below gives different ways the functionality related to method_missing is handled in other languages.&amp;lt;ref&amp;gt;http://olabini.com/blog/2010/04/patterns-of-method-missing/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 '''Construct'''                          '''Language '''&lt;br /&gt;
 AUTOLOAD                           Perl&lt;br /&gt;
 AUTOSCALAR, AUTOMETH, AUTOLOAD...  Perl6&lt;br /&gt;
 __getattr__                        Python&lt;br /&gt;
 method_missing                     Ruby&lt;br /&gt;
 doesNotUnderstand                  Smalltalk&lt;br /&gt;
 __noSuchMethod__#                  CoffeeScript, JavaScript&lt;br /&gt;
 unknown                            Tcl&lt;br /&gt;
 no-applicable-method               Common Lisp&lt;br /&gt;
 doesNotRecognizeSelector           Objective-C&lt;br /&gt;
 TryInvokeMember##                  C#&lt;br /&gt;
 match [name, args] { ... }         E&lt;br /&gt;
 the predicate fail                 Prolog&lt;br /&gt;
 forward                            Io&lt;br /&gt;
&lt;br /&gt;
# supported by Firefox&lt;br /&gt;
## only for dynamic objects&lt;br /&gt;
Table Reference&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/2865865/are-there-equivalents-to-rubys-method-missing-in-other-languages&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''_getattr_ implementation in Python'''&amp;lt;ref&amp;gt;http://docs.python.org/reference/datamodel.html?highlight=__getattr__#object.__getattr__&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
object.__getattr__(self,name)&lt;br /&gt;
&lt;br /&gt;
This method is called when an attribute lookup has not found the attribute in the usual places i.e. it is not an instance attribute nor is it found in the class tree for self. name is the attribute name. This method should return the (computed) attribute value or raise an AttributeError exception.&lt;br /&gt;
&lt;br /&gt;
class Roman(object):&lt;br /&gt;
  def roman_to_int(self, roman):&lt;br /&gt;
    # implementation here&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def __getattr__(self, name):&lt;br /&gt;
    return self.roman_to_int(name)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; r = Roman()&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; r.iv&lt;br /&gt;
4&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''doesNotUnderstand in Smalltalk language'''&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?DoesNotUnderstand&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In SmalltalkLanguage When a receiver is asked to perform a method that is unknown to it, then a run-time complaint is issued which is #doesNotUnderstand.&lt;br /&gt;
When a Smalltalk object is sent a message for a method it has not defined, the runtime system turns the message-send into an object and sends #doesNotUnderstand: to the original receiver with this message-send object as argument. By default the #doesNotUnderstand: method raises an exception, but the receiver can override it and implement it in a way that he sees fit.&lt;br /&gt;
&lt;br /&gt;
*'''Other languages'''&lt;br /&gt;
JavaScript also has a method which has an implementation similar to that of method_missing and that is &amp;quot;noSuchMethod&amp;quot;. The limitation of this method is that it is only supported by Firefox/Spidermonkey.&lt;br /&gt;
&lt;br /&gt;
Similarly, Perl has an AUTOLOAD method which works on subroutines &amp;amp; class/object methods.&lt;br /&gt;
&lt;br /&gt;
=='''Patterns of method missing&amp;lt;ref&amp;gt;http://olabini.com/blog/2010/04/patterns-of-method-missing/&amp;lt;/ref&amp;gt;'''== &lt;br /&gt;
Now that we have covered all the important areas about method missing including the advantages, the disadvantages and key points related to its functionality, it would be appropriate to know about the different ways method_missing is used and what are the consequences of its use.&lt;br /&gt;
&lt;br /&gt;
* Providing Debug information on Failure&lt;br /&gt;
Well as method missing is called when there is no object to handle the method being called, we can use method_missing to include more information about the reasons for it being called, i.e. to say that we can provide users with more information about the error messages and hence make the life of the programmers easy and provide a faster way to solve the bugs.&lt;br /&gt;
&lt;br /&gt;
* Encode parameters in method name&lt;br /&gt;
Instead of sending method as explicit parameters, another method is to use the name to encode parameters. Find below a Rails-style find expression:&lt;br /&gt;
Person.find_by_name_and_age(&amp;quot;ABC&amp;quot;,30)&lt;br /&gt;
Another way of writing the same:&lt;br /&gt;
Person.find_by(:name =&amp;gt; &amp;quot;ABC&amp;quot;, :age =&amp;gt; 30)&lt;br /&gt;
&lt;br /&gt;
The disadvantage of this is that creating such kind of API's make it difficult to debug and maintain the application.&lt;br /&gt;
&lt;br /&gt;
* Builders&lt;br /&gt;
The idea of a builder is that you use Ruby’s blocks and method_missing to make it easy to create any kind of output structure. You create a builder object and then send it messages and it responds to the messages by building up a data structure based on those messages. For example, the following code&lt;br /&gt;
&lt;br /&gt;
  builder = Builder::XmlMarkup.new(&amp;quot;&amp;quot;, 2)&lt;br /&gt;
  puts builder.person {&lt;br /&gt;
    name(&amp;quot;ABC&amp;quot;)&lt;br /&gt;
    phone(&amp;quot;12345&amp;quot;, &amp;quot;local&amp;quot;=&amp;gt;&amp;quot;yes&amp;quot;)&lt;br /&gt;
    address(&amp;quot;Raleigh&amp;quot;)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
will print&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;person&amp;gt;&lt;br /&gt;
    &amp;lt;name&amp;gt;ABC&amp;lt;/name&amp;gt;&lt;br /&gt;
    &amp;lt;phone local=&amp;quot;yes&amp;quot;&amp;gt;12345&amp;lt;/phone&amp;gt;&lt;br /&gt;
    &amp;lt;address&amp;gt;Raleigh&amp;lt;/address&amp;gt;&lt;br /&gt;
  &amp;lt;/person&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here we have defined a method_missing method and it handles any undefined method and adds the name of the method to the XML markup that is being built. Code blocks are used to capture the nested nature of the XML. The result is a very natural way to programmatically generate XML markup. Also the cumbersome task of closing the tags and escaping rules are taken care of for us.&lt;br /&gt;
&lt;br /&gt;
* Accessors&lt;br /&gt;
The inversion of the builder pattern is to use a parser that goes through the XML document and then allow access to the elements by using method_missing.&lt;br /&gt;
&lt;br /&gt;
* Test Helpers&lt;br /&gt;
Different kind of test helpers can be created using method_missing. Many of the open source Ruby projects implementations of method missing are found in the tests.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
method_missing is a very powerful feature of Ruby and as is the way with powerful things it can help you a great deal if used properly but it can make things a lot harder for you if implemented incorrectly. It is a kind of a feature which should be used sparingly, if not at all. And there are things that needs to be taken into consideration, as mentioned in the Key Points section above, if method_missing is to be implemented.&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>Nloya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65343</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=65343"/>
		<updated>2012-09-20T03:57:13Z</updated>

		<summary type="html">&lt;p&gt;Nloya: /* Similar functionality in other languages */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&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 called 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 following example, if within method_missing() we define an undefined method, we get a stack level too deep error message.&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 becomes 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;
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;
=='''Similar functionality in other languages'''==&lt;br /&gt;
Method missing, one of the dynamic features of Ruby, is not a feature that is unique to Ruby. It exists in Smalltalk, Python, Groovy, some Javascripts and most CLOS (Common Lisp Object System)extensions. In this section we look at the few such similar implementations in other languages. The table below gives different ways the functionality related to method_missing is handled in other languages.&amp;lt;ref&amp;gt;http://olabini.com/blog/2010/04/patterns-of-method-missing/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 '''Construct'''                          '''Language '''&lt;br /&gt;
 AUTOLOAD                           Perl&lt;br /&gt;
 AUTOSCALAR, AUTOMETH, AUTOLOAD...  Perl6&lt;br /&gt;
 __getattr__                        Python&lt;br /&gt;
 method_missing                     Ruby&lt;br /&gt;
 doesNotUnderstand                  Smalltalk&lt;br /&gt;
 __noSuchMethod__*                  CoffeeScript, JavaScript&lt;br /&gt;
 unknown                            Tcl&lt;br /&gt;
 no-applicable-method               Common Lisp&lt;br /&gt;
 doesNotRecognizeSelector           Objective-C&lt;br /&gt;
 TryInvokeMember**                  C#&lt;br /&gt;
 match [name, args] { ... }         E&lt;br /&gt;
 the predicate fail                 Prolog&lt;br /&gt;
 forward                            Io&lt;br /&gt;
&lt;br /&gt;
* supported by Firefox&lt;br /&gt;
** only for dynamic objects&lt;br /&gt;
Table Reference&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/2865865/are-there-equivalents-to-rubys-method-missing-in-other-languages&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''_getattr_ implementation in Python'''&amp;lt;ref&amp;gt;http://docs.python.org/reference/datamodel.html?highlight=__getattr__#object.__getattr__&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
object.__getattr__(self,name)&lt;br /&gt;
&lt;br /&gt;
This method is called when an attribute lookup has not found the attribute in the usual places i.e. it is not an instance attribute nor is it found in the class tree for self. name is the attribute name. This method should return the (computed) attribute value or raise an AttributeError exception.&lt;br /&gt;
&lt;br /&gt;
class Roman(object):&lt;br /&gt;
  def roman_to_int(self, roman):&lt;br /&gt;
    # implementation here&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def __getattr__(self, name):&lt;br /&gt;
    return self.roman_to_int(name)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; r = Roman()&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; r.iv&lt;br /&gt;
4&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''doesNotUnderstand in Smalltalk language'''&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?DoesNotUnderstand&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In SmalltalkLanguage When a receiver is asked to perform a method that is unknown to it, then a run-time complaint is issued which is #doesNotUnderstand.&lt;br /&gt;
When a Smalltalk object is sent a message for a method it has not defined, the runtime system turns the message-send into an object and sends #doesNotUnderstand: to the original receiver with this message-send object as argument. By default the #doesNotUnderstand: method raises an exception, but the receiver can override it and implement it in a way that he sees fit.&lt;br /&gt;
&lt;br /&gt;
*'''Other languages'''&lt;br /&gt;
JavaScript also has a method which has an implementation similar to that of method_missing and that is &amp;quot;noSuchMethod&amp;quot;. The limitation of this method is that it is only supported by Firefox/Spidermonkey.&lt;br /&gt;
&lt;br /&gt;
Similarly, Perl has an AUTOLOAD method which works on subroutines &amp;amp; class/object methods.&lt;br /&gt;
&lt;br /&gt;
=='''Patterns of method missing&amp;lt;ref&amp;gt;http://olabini.com/blog/2010/04/patterns-of-method-missing/&amp;lt;/ref&amp;gt;'''== &lt;br /&gt;
Now that we have covered all the important areas about method missing including the advantages, the disadvantages and key points related to its functionality, it would be appropriate to know about the different ways method_missing is used and what are the consequences of its use.&lt;br /&gt;
&lt;br /&gt;
* Providing Debug information on Failure&lt;br /&gt;
Well as method missing is called when there is no object to handle the method being called, we can use method_missing to include more information about the reasons for it being called, i.e. to say that we can provide users with more information about the error messages and hence make the life of the programmers easy and provide a faster way to solve the bugs.&lt;br /&gt;
&lt;br /&gt;
* Encode parameters in method name&lt;br /&gt;
Instead of sending method as explicit parameters, another method is to use the name to encode parameters. Find below a Rails-style find expression:&lt;br /&gt;
Person.find_by_name_and_age(&amp;quot;ABC&amp;quot;,30)&lt;br /&gt;
Another way of writing the same:&lt;br /&gt;
Person.find_by(:name =&amp;gt; &amp;quot;ABC&amp;quot;, :age =&amp;gt; 30)&lt;br /&gt;
&lt;br /&gt;
The disadvantage of this is that creating such kind of API's make it difficult to debug and maintain the application.&lt;br /&gt;
&lt;br /&gt;
* Builders&lt;br /&gt;
The idea of a builder is that you use Ruby’s blocks and method_missing to make it easy to create any kind of output structure. You create a builder object and then send it messages and it responds to the messages by building up a data structure based on those messages. For example, the following code&lt;br /&gt;
&lt;br /&gt;
  builder = Builder::XmlMarkup.new(&amp;quot;&amp;quot;, 2)&lt;br /&gt;
  puts builder.person {&lt;br /&gt;
    name(&amp;quot;ABC&amp;quot;)&lt;br /&gt;
    phone(&amp;quot;12345&amp;quot;, &amp;quot;local&amp;quot;=&amp;gt;&amp;quot;yes&amp;quot;)&lt;br /&gt;
    address(&amp;quot;Raleigh&amp;quot;)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
will print&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;person&amp;gt;&lt;br /&gt;
    &amp;lt;name&amp;gt;ABC&amp;lt;/name&amp;gt;&lt;br /&gt;
    &amp;lt;phone local=&amp;quot;yes&amp;quot;&amp;gt;12345&amp;lt;/phone&amp;gt;&lt;br /&gt;
    &amp;lt;address&amp;gt;Raleigh&amp;lt;/address&amp;gt;&lt;br /&gt;
  &amp;lt;/person&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here we have defined a method_missing method and it handles any undefined method and adds the name of the method to the XML markup that is being built. Code blocks are used to capture the nested nature of the XML. The result is a very natural way to programmatically generate XML markup. Also the cumbersome task of closing the tags and escaping rules are taken care of for us.&lt;br /&gt;
&lt;br /&gt;
* Accessors&lt;br /&gt;
The inversion of the builder pattern is to use a parser that goes through the XML document and then allow access to the elements by using method_missing.&lt;br /&gt;
&lt;br /&gt;
* Test Helpers&lt;br /&gt;
Different kind of test helpers can be created using method_missing. Many of the open source Ruby projects implementations of method missing are found in the tests.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
method_missing is a very powerful feature of Ruby and as is the way with powerful things it can help you a great deal if used properly but it can make things a lot harder for you if implemented incorrectly. It is a kind of a feature which should be used sparingly, if not at all. And there are things that needs to be taken into consideration, as mentioned in the Key Points section above, if method_missing is to be implemented.&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>Nloya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65342</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=65342"/>
		<updated>2012-09-20T03:55:30Z</updated>

		<summary type="html">&lt;p&gt;Nloya: /* Key Points */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&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 called 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 following example, if within method_missing() we define an undefined method, we get a stack level too deep error message.&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 becomes 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;
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;
=='''Similar functionality in other languages'''==&lt;br /&gt;
Method missing, one of the dynamic features of Ruby, is not a feature that is unique to Ruby. It exists in Smalltalk, Python, Groovy, some Javascripts and most CLOS (Common Lisp Object System)extensions. In this section we look at the few such similar implementations in other languages. The table below gives different ways the functionality related to method_missing is handled in other languages.&amp;lt;ref&amp;gt;http://olabini.com/blog/2010/04/patterns-of-method-missing/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 '''Construct'''                          '''Language '''&lt;br /&gt;
 AUTOLOAD                           Perl&lt;br /&gt;
 AUTOSCALAR, AUTOMETH, AUTOLOAD...  Perl6&lt;br /&gt;
 __getattr__                        Python&lt;br /&gt;
 method_missing                     Ruby&lt;br /&gt;
 doesNotUnderstand                  Smalltalk&lt;br /&gt;
 __noSuchMethod__(17)               CoffeeScript, JavaScript&lt;br /&gt;
 unknown                            Tcl&lt;br /&gt;
 no-applicable-method               Common Lisp&lt;br /&gt;
 doesNotRecognizeSelector           Objective-C&lt;br /&gt;
 TryInvokeMember(18)                C#&lt;br /&gt;
 match [name, args] { ... }         E&lt;br /&gt;
 the predicate fail                 Prolog&lt;br /&gt;
 forward                            Io&lt;br /&gt;
Table Reference&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/2865865/are-there-equivalents-to-rubys-method-missing-in-other-languages&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''_getattr_ implementation in Python'''&amp;lt;ref&amp;gt;http://docs.python.org/reference/datamodel.html?highlight=__getattr__#object.__getattr__&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
object.__getattr__(self,name)&lt;br /&gt;
&lt;br /&gt;
This method is called when an attribute lookup has not found the attribute in the usual places i.e. it is not an instance attribute nor is it found in the class tree for self. name is the attribute name. This method should return the (computed) attribute value or raise an AttributeError exception.&lt;br /&gt;
&lt;br /&gt;
class Roman(object):&lt;br /&gt;
  def roman_to_int(self, roman):&lt;br /&gt;
    # implementation here&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def __getattr__(self, name):&lt;br /&gt;
    return self.roman_to_int(name)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; r = Roman()&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; r.iv&lt;br /&gt;
4&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''doesNotUnderstand in Smalltalk language'''&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?DoesNotUnderstand&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In SmalltalkLanguage When a receiver is asked to perform a method that is unknown to it, then a run-time complaint is issued which is #doesNotUnderstand.&lt;br /&gt;
When a Smalltalk object is sent a message for a method it has not defined, the runtime system turns the message-send into an object and sends #doesNotUnderstand: to the original receiver with this message-send object as argument. By default the #doesNotUnderstand: method raises an exception, but the receiver can override it and implement it in a way that he sees fit.&lt;br /&gt;
&lt;br /&gt;
*'''Other languages'''&lt;br /&gt;
JavaScript also has a method which has an implementation similar to that of method_missing and that is &amp;quot;noSuchMethod&amp;quot;. The limitation of this method is that it is only supported by Firefox/Spidermonkey.&lt;br /&gt;
&lt;br /&gt;
Similarly, Perl has an AUTOLOAD method which works on subroutines &amp;amp; class/object methods.&lt;br /&gt;
&lt;br /&gt;
=='''Patterns of method missing&amp;lt;ref&amp;gt;http://olabini.com/blog/2010/04/patterns-of-method-missing/&amp;lt;/ref&amp;gt;'''== &lt;br /&gt;
Now that we have covered all the important areas about method missing including the advantages, the disadvantages and key points related to its functionality, it would be appropriate to know about the different ways method_missing is used and what are the consequences of its use.&lt;br /&gt;
&lt;br /&gt;
* Providing Debug information on Failure&lt;br /&gt;
Well as method missing is called when there is no object to handle the method being called, we can use method_missing to include more information about the reasons for it being called, i.e. to say that we can provide users with more information about the error messages and hence make the life of the programmers easy and provide a faster way to solve the bugs.&lt;br /&gt;
&lt;br /&gt;
* Encode parameters in method name&lt;br /&gt;
Instead of sending method as explicit parameters, another method is to use the name to encode parameters. Find below a Rails-style find expression:&lt;br /&gt;
Person.find_by_name_and_age(&amp;quot;ABC&amp;quot;,30)&lt;br /&gt;
Another way of writing the same:&lt;br /&gt;
Person.find_by(:name =&amp;gt; &amp;quot;ABC&amp;quot;, :age =&amp;gt; 30)&lt;br /&gt;
&lt;br /&gt;
The disadvantage of this is that creating such kind of API's make it difficult to debug and maintain the application.&lt;br /&gt;
&lt;br /&gt;
* Builders&lt;br /&gt;
The idea of a builder is that you use Ruby’s blocks and method_missing to make it easy to create any kind of output structure. You create a builder object and then send it messages and it responds to the messages by building up a data structure based on those messages. For example, the following code&lt;br /&gt;
&lt;br /&gt;
  builder = Builder::XmlMarkup.new(&amp;quot;&amp;quot;, 2)&lt;br /&gt;
  puts builder.person {&lt;br /&gt;
    name(&amp;quot;ABC&amp;quot;)&lt;br /&gt;
    phone(&amp;quot;12345&amp;quot;, &amp;quot;local&amp;quot;=&amp;gt;&amp;quot;yes&amp;quot;)&lt;br /&gt;
    address(&amp;quot;Raleigh&amp;quot;)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
will print&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;person&amp;gt;&lt;br /&gt;
    &amp;lt;name&amp;gt;ABC&amp;lt;/name&amp;gt;&lt;br /&gt;
    &amp;lt;phone local=&amp;quot;yes&amp;quot;&amp;gt;12345&amp;lt;/phone&amp;gt;&lt;br /&gt;
    &amp;lt;address&amp;gt;Raleigh&amp;lt;/address&amp;gt;&lt;br /&gt;
  &amp;lt;/person&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here we have defined a method_missing method and it handles any undefined method and adds the name of the method to the XML markup that is being built. Code blocks are used to capture the nested nature of the XML. The result is a very natural way to programmatically generate XML markup. Also the cumbersome task of closing the tags and escaping rules are taken care of for us.&lt;br /&gt;
&lt;br /&gt;
* Accessors&lt;br /&gt;
The inversion of the builder pattern is to use a parser that goes through the XML document and then allow access to the elements by using method_missing.&lt;br /&gt;
&lt;br /&gt;
* Test Helpers&lt;br /&gt;
Different kind of test helpers can be created using method_missing. Many of the open source Ruby projects implementations of method missing are found in the tests.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
method_missing is a very powerful feature of Ruby and as is the way with powerful things it can help you a great deal if used properly but it can make things a lot harder for you if implemented incorrectly. It is a kind of a feature which should be used sparingly, if not at all. And there are things that needs to be taken into consideration, as mentioned in the Key Points section above, if method_missing is to be implemented.&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>Nloya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65341</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=65341"/>
		<updated>2012-09-20T03:53:09Z</updated>

		<summary type="html">&lt;p&gt;Nloya: /* Key Points */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&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 called 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 following example, if within method_missing() we define an undefined method, we get a stack level too deep error message.&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;
*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;
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;
=='''Similar functionality in other languages'''==&lt;br /&gt;
Method missing, one of the dynamic features of Ruby, is not a feature that is unique to Ruby. It exists in Smalltalk, Python, Groovy, some Javascripts and most CLOS (Common Lisp Object System)extensions. In this section we look at the few such similar implementations in other languages. The table below gives different ways the functionality related to method_missing is handled in other languages.&amp;lt;ref&amp;gt;http://olabini.com/blog/2010/04/patterns-of-method-missing/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 '''Construct'''                          '''Language '''&lt;br /&gt;
 AUTOLOAD                           Perl&lt;br /&gt;
 AUTOSCALAR, AUTOMETH, AUTOLOAD...  Perl6&lt;br /&gt;
 __getattr__                        Python&lt;br /&gt;
 method_missing                     Ruby&lt;br /&gt;
 doesNotUnderstand                  Smalltalk&lt;br /&gt;
 __noSuchMethod__(17)               CoffeeScript, JavaScript&lt;br /&gt;
 unknown                            Tcl&lt;br /&gt;
 no-applicable-method               Common Lisp&lt;br /&gt;
 doesNotRecognizeSelector           Objective-C&lt;br /&gt;
 TryInvokeMember(18)                C#&lt;br /&gt;
 match [name, args] { ... }         E&lt;br /&gt;
 the predicate fail                 Prolog&lt;br /&gt;
 forward                            Io&lt;br /&gt;
Table Reference&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/2865865/are-there-equivalents-to-rubys-method-missing-in-other-languages&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''_getattr_ implementation in Python'''&amp;lt;ref&amp;gt;http://docs.python.org/reference/datamodel.html?highlight=__getattr__#object.__getattr__&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
object.__getattr__(self,name)&lt;br /&gt;
&lt;br /&gt;
This method is called when an attribute lookup has not found the attribute in the usual places i.e. it is not an instance attribute nor is it found in the class tree for self. name is the attribute name. This method should return the (computed) attribute value or raise an AttributeError exception.&lt;br /&gt;
&lt;br /&gt;
class Roman(object):&lt;br /&gt;
  def roman_to_int(self, roman):&lt;br /&gt;
    # implementation here&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def __getattr__(self, name):&lt;br /&gt;
    return self.roman_to_int(name)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; r = Roman()&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; r.iv&lt;br /&gt;
4&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''doesNotUnderstand in Smalltalk language'''&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?DoesNotUnderstand&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In SmalltalkLanguage When a receiver is asked to perform a method that is unknown to it, then a run-time complaint is issued which is #doesNotUnderstand.&lt;br /&gt;
When a Smalltalk object is sent a message for a method it has not defined, the runtime system turns the message-send into an object and sends #doesNotUnderstand: to the original receiver with this message-send object as argument. By default the #doesNotUnderstand: method raises an exception, but the receiver can override it and implement it in a way that he sees fit.&lt;br /&gt;
&lt;br /&gt;
*'''Other languages'''&lt;br /&gt;
JavaScript also has a method which has an implementation similar to that of method_missing and that is &amp;quot;noSuchMethod&amp;quot;. The limitation of this method is that it is only supported by Firefox/Spidermonkey.&lt;br /&gt;
&lt;br /&gt;
Similarly, Perl has an AUTOLOAD method which works on subroutines &amp;amp; class/object methods.&lt;br /&gt;
&lt;br /&gt;
=='''Patterns of method missing&amp;lt;ref&amp;gt;http://olabini.com/blog/2010/04/patterns-of-method-missing/&amp;lt;/ref&amp;gt;'''== &lt;br /&gt;
Now that we have covered all the important areas about method missing including the advantages, the disadvantages and key points related to its functionality, it would be appropriate to know about the different ways method_missing is used and what are the consequences of its use.&lt;br /&gt;
&lt;br /&gt;
* Providing Debug information on Failure&lt;br /&gt;
Well as method missing is called when there is no object to handle the method being called, we can use method_missing to include more information about the reasons for it being called, i.e. to say that we can provide users with more information about the error messages and hence make the life of the programmers easy and provide a faster way to solve the bugs.&lt;br /&gt;
&lt;br /&gt;
* Encode parameters in method name&lt;br /&gt;
Instead of sending method as explicit parameters, another method is to use the name to encode parameters. Find below a Rails-style find expression:&lt;br /&gt;
Person.find_by_name_and_age(&amp;quot;ABC&amp;quot;,30)&lt;br /&gt;
Another way of writing the same:&lt;br /&gt;
Person.find_by(:name =&amp;gt; &amp;quot;ABC&amp;quot;, :age =&amp;gt; 30)&lt;br /&gt;
&lt;br /&gt;
The disadvantage of this is that creating such kind of API's make it difficult to debug and maintain the application.&lt;br /&gt;
&lt;br /&gt;
* Builders&lt;br /&gt;
The idea of a builder is that you use Ruby’s blocks and method_missing to make it easy to create any kind of output structure. You create a builder object and then send it messages and it responds to the messages by building up a data structure based on those messages. For example, the following code&lt;br /&gt;
&lt;br /&gt;
  builder = Builder::XmlMarkup.new(&amp;quot;&amp;quot;, 2)&lt;br /&gt;
  puts builder.person {&lt;br /&gt;
    name(&amp;quot;ABC&amp;quot;)&lt;br /&gt;
    phone(&amp;quot;12345&amp;quot;, &amp;quot;local&amp;quot;=&amp;gt;&amp;quot;yes&amp;quot;)&lt;br /&gt;
    address(&amp;quot;Raleigh&amp;quot;)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
will print&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;person&amp;gt;&lt;br /&gt;
    &amp;lt;name&amp;gt;ABC&amp;lt;/name&amp;gt;&lt;br /&gt;
    &amp;lt;phone local=&amp;quot;yes&amp;quot;&amp;gt;12345&amp;lt;/phone&amp;gt;&lt;br /&gt;
    &amp;lt;address&amp;gt;Raleigh&amp;lt;/address&amp;gt;&lt;br /&gt;
  &amp;lt;/person&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here we have defined a method_missing method and it handles any undefined method and adds the name of the method to the XML markup that is being built. Code blocks are used to capture the nested nature of the XML. The result is a very natural way to programmatically generate XML markup. Also the cumbersome task of closing the tags and escaping rules are taken care of for us.&lt;br /&gt;
&lt;br /&gt;
* Accessors&lt;br /&gt;
The inversion of the builder pattern is to use a parser that goes through the XML document and then allow access to the elements by using method_missing.&lt;br /&gt;
&lt;br /&gt;
* Test Helpers&lt;br /&gt;
Different kind of test helpers can be created using method_missing. Many of the open source Ruby projects implementations of method missing are found in the tests.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
method_missing is a very powerful feature of Ruby and as is the way with powerful things it can help you a great deal if used properly but it can make things a lot harder for you if implemented incorrectly. It is a kind of a feature which should be used sparingly, if not at all. And there are things that needs to be taken into consideration, as mentioned in the Key Points section above, if method_missing is to be implemented.&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>Nloya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65340</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=65340"/>
		<updated>2012-09-20T03:51:01Z</updated>

		<summary type="html">&lt;p&gt;Nloya: /* Ruby Method Lookup Flow */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&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 called 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 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;
*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;
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;
=='''Similar functionality in other languages'''==&lt;br /&gt;
Method missing, one of the dynamic features of Ruby, is not a feature that is unique to Ruby. It exists in Smalltalk, Python, Groovy, some Javascripts and most CLOS (Common Lisp Object System)extensions. In this section we look at the few such similar implementations in other languages. The table below gives different ways the functionality related to method_missing is handled in other languages.&amp;lt;ref&amp;gt;http://olabini.com/blog/2010/04/patterns-of-method-missing/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 '''Construct'''                          '''Language '''&lt;br /&gt;
 AUTOLOAD                           Perl&lt;br /&gt;
 AUTOSCALAR, AUTOMETH, AUTOLOAD...  Perl6&lt;br /&gt;
 __getattr__                        Python&lt;br /&gt;
 method_missing                     Ruby&lt;br /&gt;
 doesNotUnderstand                  Smalltalk&lt;br /&gt;
 __noSuchMethod__(17)               CoffeeScript, JavaScript&lt;br /&gt;
 unknown                            Tcl&lt;br /&gt;
 no-applicable-method               Common Lisp&lt;br /&gt;
 doesNotRecognizeSelector           Objective-C&lt;br /&gt;
 TryInvokeMember(18)                C#&lt;br /&gt;
 match [name, args] { ... }         E&lt;br /&gt;
 the predicate fail                 Prolog&lt;br /&gt;
 forward                            Io&lt;br /&gt;
Table Reference&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/2865865/are-there-equivalents-to-rubys-method-missing-in-other-languages&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''_getattr_ implementation in Python'''&amp;lt;ref&amp;gt;http://docs.python.org/reference/datamodel.html?highlight=__getattr__#object.__getattr__&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
object.__getattr__(self,name)&lt;br /&gt;
&lt;br /&gt;
This method is called when an attribute lookup has not found the attribute in the usual places i.e. it is not an instance attribute nor is it found in the class tree for self. name is the attribute name. This method should return the (computed) attribute value or raise an AttributeError exception.&lt;br /&gt;
&lt;br /&gt;
class Roman(object):&lt;br /&gt;
  def roman_to_int(self, roman):&lt;br /&gt;
    # implementation here&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def __getattr__(self, name):&lt;br /&gt;
    return self.roman_to_int(name)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; r = Roman()&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; r.iv&lt;br /&gt;
4&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''doesNotUnderstand in Smalltalk language'''&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?DoesNotUnderstand&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In SmalltalkLanguage When a receiver is asked to perform a method that is unknown to it, then a run-time complaint is issued which is #doesNotUnderstand.&lt;br /&gt;
When a Smalltalk object is sent a message for a method it has not defined, the runtime system turns the message-send into an object and sends #doesNotUnderstand: to the original receiver with this message-send object as argument. By default the #doesNotUnderstand: method raises an exception, but the receiver can override it and implement it in a way that he sees fit.&lt;br /&gt;
&lt;br /&gt;
*'''Other languages'''&lt;br /&gt;
JavaScript also has a method which has an implementation similar to that of method_missing and that is &amp;quot;noSuchMethod&amp;quot;. The limitation of this method is that it is only supported by Firefox/Spidermonkey.&lt;br /&gt;
&lt;br /&gt;
Similarly, Perl has an AUTOLOAD method which works on subroutines &amp;amp; class/object methods.&lt;br /&gt;
&lt;br /&gt;
=='''Patterns of method missing&amp;lt;ref&amp;gt;http://olabini.com/blog/2010/04/patterns-of-method-missing/&amp;lt;/ref&amp;gt;'''== &lt;br /&gt;
Now that we have covered all the important areas about method missing including the advantages, the disadvantages and key points related to its functionality, it would be appropriate to know about the different ways method_missing is used and what are the consequences of its use.&lt;br /&gt;
&lt;br /&gt;
* Providing Debug information on Failure&lt;br /&gt;
Well as method missing is called when there is no object to handle the method being called, we can use method_missing to include more information about the reasons for it being called, i.e. to say that we can provide users with more information about the error messages and hence make the life of the programmers easy and provide a faster way to solve the bugs.&lt;br /&gt;
&lt;br /&gt;
* Encode parameters in method name&lt;br /&gt;
Instead of sending method as explicit parameters, another method is to use the name to encode parameters. Find below a Rails-style find expression:&lt;br /&gt;
Person.find_by_name_and_age(&amp;quot;ABC&amp;quot;,30)&lt;br /&gt;
Another way of writing the same:&lt;br /&gt;
Person.find_by(:name =&amp;gt; &amp;quot;ABC&amp;quot;, :age =&amp;gt; 30)&lt;br /&gt;
&lt;br /&gt;
The disadvantage of this is that creating such kind of API's make it difficult to debug and maintain the application.&lt;br /&gt;
&lt;br /&gt;
* Builders&lt;br /&gt;
The idea of a builder is that you use Ruby’s blocks and method_missing to make it easy to create any kind of output structure. You create a builder object and then send it messages and it responds to the messages by building up a data structure based on those messages. For example, the following code&lt;br /&gt;
&lt;br /&gt;
  builder = Builder::XmlMarkup.new(&amp;quot;&amp;quot;, 2)&lt;br /&gt;
  puts builder.person {&lt;br /&gt;
    name(&amp;quot;ABC&amp;quot;)&lt;br /&gt;
    phone(&amp;quot;12345&amp;quot;, &amp;quot;local&amp;quot;=&amp;gt;&amp;quot;yes&amp;quot;)&lt;br /&gt;
    address(&amp;quot;Raleigh&amp;quot;)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
will print&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;person&amp;gt;&lt;br /&gt;
    &amp;lt;name&amp;gt;ABC&amp;lt;/name&amp;gt;&lt;br /&gt;
    &amp;lt;phone local=&amp;quot;yes&amp;quot;&amp;gt;12345&amp;lt;/phone&amp;gt;&lt;br /&gt;
    &amp;lt;address&amp;gt;Raleigh&amp;lt;/address&amp;gt;&lt;br /&gt;
  &amp;lt;/person&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here we have defined a method_missing method and it handles any undefined method and adds the name of the method to the XML markup that is being built. Code blocks are used to capture the nested nature of the XML. The result is a very natural way to programmatically generate XML markup. Also the cumbersome task of closing the tags and escaping rules are taken care of for us.&lt;br /&gt;
&lt;br /&gt;
* Accessors&lt;br /&gt;
The inversion of the builder pattern is to use a parser that goes through the XML document and then allow access to the elements by using method_missing.&lt;br /&gt;
&lt;br /&gt;
* Test Helpers&lt;br /&gt;
Different kind of test helpers can be created using method_missing. Many of the open source Ruby projects implementations of method missing are found in the tests.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
method_missing is a very powerful feature of Ruby and as is the way with powerful things it can help you a great deal if used properly but it can make things a lot harder for you if implemented incorrectly. It is a kind of a feature which should be used sparingly, if not at all. And there are things that needs to be taken into consideration, as mentioned in the Key Points section above, if method_missing is to be implemented.&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>Nloya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65339</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=65339"/>
		<updated>2012-09-20T03:49:50Z</updated>

		<summary type="html">&lt;p&gt;Nloya: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&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 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;
*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;
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;
=='''Similar functionality in other languages'''==&lt;br /&gt;
Method missing, one of the dynamic features of Ruby, is not a feature that is unique to Ruby. It exists in Smalltalk, Python, Groovy, some Javascripts and most CLOS (Common Lisp Object System)extensions. In this section we look at the few such similar implementations in other languages. The table below gives different ways the functionality related to method_missing is handled in other languages.&amp;lt;ref&amp;gt;http://olabini.com/blog/2010/04/patterns-of-method-missing/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 '''Construct'''                          '''Language '''&lt;br /&gt;
 AUTOLOAD                           Perl&lt;br /&gt;
 AUTOSCALAR, AUTOMETH, AUTOLOAD...  Perl6&lt;br /&gt;
 __getattr__                        Python&lt;br /&gt;
 method_missing                     Ruby&lt;br /&gt;
 doesNotUnderstand                  Smalltalk&lt;br /&gt;
 __noSuchMethod__(17)               CoffeeScript, JavaScript&lt;br /&gt;
 unknown                            Tcl&lt;br /&gt;
 no-applicable-method               Common Lisp&lt;br /&gt;
 doesNotRecognizeSelector           Objective-C&lt;br /&gt;
 TryInvokeMember(18)                C#&lt;br /&gt;
 match [name, args] { ... }         E&lt;br /&gt;
 the predicate fail                 Prolog&lt;br /&gt;
 forward                            Io&lt;br /&gt;
Table Reference&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/2865865/are-there-equivalents-to-rubys-method-missing-in-other-languages&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''_getattr_ implementation in Python'''&amp;lt;ref&amp;gt;http://docs.python.org/reference/datamodel.html?highlight=__getattr__#object.__getattr__&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
object.__getattr__(self,name)&lt;br /&gt;
&lt;br /&gt;
This method is called when an attribute lookup has not found the attribute in the usual places i.e. it is not an instance attribute nor is it found in the class tree for self. name is the attribute name. This method should return the (computed) attribute value or raise an AttributeError exception.&lt;br /&gt;
&lt;br /&gt;
class Roman(object):&lt;br /&gt;
  def roman_to_int(self, roman):&lt;br /&gt;
    # implementation here&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def __getattr__(self, name):&lt;br /&gt;
    return self.roman_to_int(name)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; r = Roman()&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; r.iv&lt;br /&gt;
4&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''doesNotUnderstand in Smalltalk language'''&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?DoesNotUnderstand&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In SmalltalkLanguage When a receiver is asked to perform a method that is unknown to it, then a run-time complaint is issued which is #doesNotUnderstand.&lt;br /&gt;
When a Smalltalk object is sent a message for a method it has not defined, the runtime system turns the message-send into an object and sends #doesNotUnderstand: to the original receiver with this message-send object as argument. By default the #doesNotUnderstand: method raises an exception, but the receiver can override it and implement it in a way that he sees fit.&lt;br /&gt;
&lt;br /&gt;
*'''Other languages'''&lt;br /&gt;
JavaScript also has a method which has an implementation similar to that of method_missing and that is &amp;quot;noSuchMethod&amp;quot;. The limitation of this method is that it is only supported by Firefox/Spidermonkey.&lt;br /&gt;
&lt;br /&gt;
Similarly, Perl has an AUTOLOAD method which works on subroutines &amp;amp; class/object methods.&lt;br /&gt;
&lt;br /&gt;
=='''Patterns of method missing&amp;lt;ref&amp;gt;http://olabini.com/blog/2010/04/patterns-of-method-missing/&amp;lt;/ref&amp;gt;'''== &lt;br /&gt;
Now that we have covered all the important areas about method missing including the advantages, the disadvantages and key points related to its functionality, it would be appropriate to know about the different ways method_missing is used and what are the consequences of its use.&lt;br /&gt;
&lt;br /&gt;
* Providing Debug information on Failure&lt;br /&gt;
Well as method missing is called when there is no object to handle the method being called, we can use method_missing to include more information about the reasons for it being called, i.e. to say that we can provide users with more information about the error messages and hence make the life of the programmers easy and provide a faster way to solve the bugs.&lt;br /&gt;
&lt;br /&gt;
* Encode parameters in method name&lt;br /&gt;
Instead of sending method as explicit parameters, another method is to use the name to encode parameters. Find below a Rails-style find expression:&lt;br /&gt;
Person.find_by_name_and_age(&amp;quot;ABC&amp;quot;,30)&lt;br /&gt;
Another way of writing the same:&lt;br /&gt;
Person.find_by(:name =&amp;gt; &amp;quot;ABC&amp;quot;, :age =&amp;gt; 30)&lt;br /&gt;
&lt;br /&gt;
The disadvantage of this is that creating such kind of API's make it difficult to debug and maintain the application.&lt;br /&gt;
&lt;br /&gt;
* Builders&lt;br /&gt;
The idea of a builder is that you use Ruby’s blocks and method_missing to make it easy to create any kind of output structure. You create a builder object and then send it messages and it responds to the messages by building up a data structure based on those messages. For example, the following code&lt;br /&gt;
&lt;br /&gt;
  builder = Builder::XmlMarkup.new(&amp;quot;&amp;quot;, 2)&lt;br /&gt;
  puts builder.person {&lt;br /&gt;
    name(&amp;quot;ABC&amp;quot;)&lt;br /&gt;
    phone(&amp;quot;12345&amp;quot;, &amp;quot;local&amp;quot;=&amp;gt;&amp;quot;yes&amp;quot;)&lt;br /&gt;
    address(&amp;quot;Raleigh&amp;quot;)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
will print&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;person&amp;gt;&lt;br /&gt;
    &amp;lt;name&amp;gt;ABC&amp;lt;/name&amp;gt;&lt;br /&gt;
    &amp;lt;phone local=&amp;quot;yes&amp;quot;&amp;gt;12345&amp;lt;/phone&amp;gt;&lt;br /&gt;
    &amp;lt;address&amp;gt;Raleigh&amp;lt;/address&amp;gt;&lt;br /&gt;
  &amp;lt;/person&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here we have defined a method_missing method and it handles any undefined method and adds the name of the method to the XML markup that is being built. Code blocks are used to capture the nested nature of the XML. The result is a very natural way to programmatically generate XML markup. Also the cumbersome task of closing the tags and escaping rules are taken care of for us.&lt;br /&gt;
&lt;br /&gt;
* Accessors&lt;br /&gt;
The inversion of the builder pattern is to use a parser that goes through the XML document and then allow access to the elements by using method_missing.&lt;br /&gt;
&lt;br /&gt;
* Test Helpers&lt;br /&gt;
Different kind of test helpers can be created using method_missing. Many of the open source Ruby projects implementations of method missing are found in the tests.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
method_missing is a very powerful feature of Ruby and as is the way with powerful things it can help you a great deal if used properly but it can make things a lot harder for you if implemented incorrectly. It is a kind of a feature which should be used sparingly, if not at all. And there are things that needs to be taken into consideration, as mentioned in the Key Points section above, if method_missing is to be implemented.&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>Nloya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65330</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=65330"/>
		<updated>2012-09-20T03:09:05Z</updated>

		<summary type="html">&lt;p&gt;Nloya: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&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 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;
*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;
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;
=='''Similar functionality in other languages'''==&lt;br /&gt;
Method missing, one of the dynamic features of Ruby, is not a feature that is unique to Ruby. It exists in Smalltalk, Python, Groovy, some Javascripts and most CLOS (Common Lisp Object System)extensions. In this section we look at the few such similar implementations in other languages. The table below gives different ways the functionality related to method_missing is handled in other languages.&amp;lt;ref&amp;gt;http://olabini.com/blog/2010/04/patterns-of-method-missing/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 '''Construct'''                          '''Language '''&lt;br /&gt;
 AUTOLOAD                           Perl&lt;br /&gt;
 AUTOSCALAR, AUTOMETH, AUTOLOAD...  Perl6&lt;br /&gt;
 __getattr__                        Python&lt;br /&gt;
 method_missing                     Ruby&lt;br /&gt;
 doesNotUnderstand                  Smalltalk&lt;br /&gt;
 __noSuchMethod__(17)               CoffeeScript, JavaScript&lt;br /&gt;
 unknown                            Tcl&lt;br /&gt;
 no-applicable-method               Common Lisp&lt;br /&gt;
 doesNotRecognizeSelector           Objective-C&lt;br /&gt;
 TryInvokeMember(18)                C#&lt;br /&gt;
 match [name, args] { ... }         E&lt;br /&gt;
 the predicate fail                 Prolog&lt;br /&gt;
 forward                            Io&lt;br /&gt;
Table Reference&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/2865865/are-there-equivalents-to-rubys-method-missing-in-other-languages&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''_getattr_ implementation in Python'''&amp;lt;ref&amp;gt;http://docs.python.org/reference/datamodel.html?highlight=__getattr__#object.__getattr__&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
object.__getattr__(self,name)&lt;br /&gt;
&lt;br /&gt;
This method is called when an attribute lookup has not found the attribute in the usual places i.e. it is not an instance attribute nor is it found in the class tree for self. name is the attribute name. This method should return the (computed) attribute value or raise an AttributeError exception.&lt;br /&gt;
&lt;br /&gt;
class Roman(object):&lt;br /&gt;
  def roman_to_int(self, roman):&lt;br /&gt;
    # implementation here&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def __getattr__(self, name):&lt;br /&gt;
    return self.roman_to_int(name)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; r = Roman()&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; r.iv&lt;br /&gt;
4&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''doesNotUnderstand in Smalltalk language'''&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?DoesNotUnderstand&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In SmalltalkLanguage When a receiver is asked to perform a method that is unknown to it, then a run-time complaint is issued which is #doesNotUnderstand.&lt;br /&gt;
When a Smalltalk object is sent a message for a method it has not defined, the runtime system turns the message-send into an object and sends #doesNotUnderstand: to the original receiver with this message-send object as argument. By default the #doesNotUnderstand: method raises an exception, but the receiver can override it and implement it in a way that he sees fit.&lt;br /&gt;
&lt;br /&gt;
*'''Other languages'''&lt;br /&gt;
JavaScript also has a method which has an implementation similar to that of method_missing and that is &amp;quot;noSuchMethod&amp;quot;. The limitation of this method is that it is only supported by Firefox/Spidermonkey.&lt;br /&gt;
&lt;br /&gt;
Similarly, Perl has an AUTOLOAD method which works on subroutines &amp;amp; class/object methods.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
method_missing is a very powerful feature of Ruby and as is the way with powerful things it can help you a great deal if used properly but it can make things a lot harder for you if implemented incorrectly. It is a kind of a feature which should be used sparingly, if not at all. And there are things that needs to be taken into consideration, as mentioned in the Key Points section above, if method_missing is to be implemented.&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>Nloya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65329</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=65329"/>
		<updated>2012-09-20T02:44:42Z</updated>

		<summary type="html">&lt;p&gt;Nloya: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&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 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;
*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;
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;
=='''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>Nloya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65328</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=65328"/>
		<updated>2012-09-20T02:43:38Z</updated>

		<summary type="html">&lt;p&gt;Nloya: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&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 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;
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;
=='''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>Nloya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w22_an&amp;diff=65106</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=65106"/>
		<updated>2012-09-15T02:23:55Z</updated>

		<summary type="html">&lt;p&gt;Nloya: &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;
*[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 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>Nloya</name></author>
	</entry>
</feed>