<?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=Msudhee</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=Msudhee"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Msudhee"/>
	<updated>2026-06-24T13:05:57Z</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_2w-1w65_am&amp;diff=71243</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w-1w65 am</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=71243"/>
		<updated>2012-11-26T19:08:16Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* Understanding Error Messages in Rails */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This is a wiki article for the material presented in the Coursera SaaS video series, [https://www.youtube.com/watch?v=Ee5vfe0mLb8 3.13 Debugging by Dr. Armando Fox and Dr. David Patterson]. We aim to cover all the material presented in the video with definitions and examples&lt;br /&gt;
===Why debugging in Rails can be tricky?===&lt;br /&gt;
*We are used to printing the error on the terminal in most applications(Example: [http://www.cplusplus.com/reference/clibrary/cstdio/stderr/ STDERR]). This may not be possible for a web application since its primary form of input and output is through HTTP requests and responses.&lt;br /&gt;
&lt;br /&gt;
*Errors early in flow might manifest itself late.&lt;br /&gt;
Consider the following hierarchy seen in a Rails application:&lt;br /&gt;
 URI -&amp;gt; Route -&amp;gt; Controller -&amp;gt; Model -&amp;gt; View -&amp;gt; Renderer&lt;br /&gt;
 &lt;br /&gt;
Here, something that goes wrong in the controller might not manifest itself until the renderer. The root cause of the error might have happened a long time ago.&lt;br /&gt;
&lt;br /&gt;
*Errors can be hard to localize/reproduce if it affects only some users or routes.&lt;br /&gt;
&lt;br /&gt;
There are several approaches that can be used for debugging based on the mode of operation, that is development mode or production mode:&lt;br /&gt;
 &lt;br /&gt;
'''Printing to terminal:'''This is useful for developers, when they are writing code they can print errors to the terminal and then examine them. We cannot use this approach in production mode.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Logging:''' This is a more general approach to debugging which can be used in both modes. The logged entries are permanent record of what the application is doing. The recorded errors are saved in a log file and can be referenced later.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interactive Debugging:''' Using this tool you can stop the application in its tracks and inspect the state of the variables or other parameters to locate the error.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the various approaches and the modes in which they can be used: &amp;lt;br&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Approach !! Development !! Production&lt;br /&gt;
|-&lt;br /&gt;
| Printing to Terminal || ✓ || &lt;br /&gt;
|-&lt;br /&gt;
| Logging || ✓ || ✓&lt;br /&gt;
|-&lt;br /&gt;
| Interactive Debugging || ✓ || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==RASP==&lt;br /&gt;
Steps to follow when faced with an error can be concisely represented by RASP according to Dr. Fox.&lt;br /&gt;
===What is RASP?===&lt;br /&gt;
RASP is an acronym which briefs the steps which a developer could follow if she were facing an error message. It stands for:&lt;br /&gt;
#'''Read''' the error message.&lt;br /&gt;
#'''Ask''' your colleague  &lt;br /&gt;
#'''Search''' using [http://stackoverflow.com/ Stack Overflow] or any other search engine.&lt;br /&gt;
#'''Post''' on [http://stackoverflow.com/ Stack Overflow] or class forum&lt;br /&gt;
&lt;br /&gt;
Reading the error message carefully is the first step in debugging. The error messages in Rails are incredibly detailed and it gives us a lot of information, reading it carefully can help us locate the file and line in which you are facing the error. But what if the line looks alright to you?&amp;lt;br&amp;gt;&lt;br /&gt;
The next step is to ask a colleague an informed question. In case you are doing pair programming, this is a good step to take. The question has to be of the form &amp;quot;I am trying to do this and I expected to get this but I got this other thing instead of foo.&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
If the previous steps fail then searching using stack overflow or Google is next, especially if its an error which is particular to a version of gems or OS.&amp;lt;br&amp;gt;&lt;br /&gt;
In case you don't find a solution to your problem the final step is to get minimal but complete information which reproduces the error message which you are experiencing and post it.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example question and solution from stack overflow:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Ques.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
As we can see the question follows the guidelines explained above. It gives minimal but complete information about the error. It does not give the entire description of the error. It is important to post minimal information so that the person who answers the question can understand your problem quickly.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Ans.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The answer is posted within an hour of posting the question. This shows that posting on stack overflow is a fast way of getting expert help with debugging.&lt;br /&gt;
&lt;br /&gt;
==Understanding Error Messages in Rails==&lt;br /&gt;
Rails usually provides a very verbose description of error messages. Dr. Fox tells us that error messages are our friends, they try to not only show us what went wrong but a great deal of detail of where it went wrong. Let us look at an example error message.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
An error message was deliberately caused by entering a route which wouldn't work. The application which we are using is the [http://en.wikipedia.org/wiki/Backchannel backchannel] application and we are trying to find a post with id=20 (it doesn't exist). This causes rails to throw the following error  message.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;'''ActiveRecord::RecordNotFound in PostsController#show'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;Couldn't find Post with id=20&amp;lt;br&amp;gt;&lt;br /&gt;
 Rails.root: C:/Users/BruceWayne/Downloads/BackChannelApplication&amp;lt;br&amp;gt;&lt;br /&gt;
 Application Trace | Framework Trace | Full Trace&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''What is the error message trying to tell us?'''&amp;lt;br&amp;gt;&lt;br /&gt;
It tells us that ActiveRecord raised the error, and the error was raised in the show method of the Posts Controller. Rails tried to find a post with id=20 but it failed.&lt;br /&gt;
===Application Trace===&lt;br /&gt;
The application trace will give us the file, line number and the method in which the error was thrown. For the above example the application trace will look like this:&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;code&amp;gt;app/controllers/posts_controller.rb:17:in `show'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also get the application trace manually at any point through the following command:&lt;br /&gt;
 begin&lt;br /&gt;
  raise object.inspect&lt;br /&gt;
 rescue&lt;br /&gt;
  Rails.logger.warn $!.backtrace.to_yaml&lt;br /&gt;
 end&lt;br /&gt;
This will cause a deliberate error along with an application trace of how you got there.&lt;br /&gt;
&lt;br /&gt;
===Stack Trace===&lt;br /&gt;
Full stack trace shows us the entire stack trace of right when the application started until the problem is encountered. Usually stack traces are very lengthy but they can be very useful to solve problems. Here is a partial stack trace from the back channel application error which we saw before:&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;code&amp;gt;activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:341:in `find_one'&amp;lt;br&amp;gt;&lt;br /&gt;
 activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:312:in `find_with_ids'&amp;lt;br&amp;gt;&lt;br /&gt;
 activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:107:in `find'&amp;lt;br&amp;gt;&lt;br /&gt;
 C:in `find'&amp;lt;br&amp;gt;&lt;br /&gt;
 app/controllers/posts_controller.rb:17:in `show'&amp;lt;br&amp;gt;&lt;br /&gt;
 actionpack (3.2.8) lib/action_controller/metal/implicit_render.rb:4:in `send_action'&amp;lt;br&amp;gt;&lt;br /&gt;
 actionpack (3.2.8) lib/abstract_controller/base.rb:167:in `process_action'&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can see the stack trace right from where the Rails application started, we can see calls to &amp;lt;code&amp;gt;activerecord&amp;lt;/code&amp;gt; in the beginning. It is unlikely that there would be a problem in those files. As we continue looking into the stack trace we see the find method, we can click on the link in the trace and it will take us to the line in which the error was found. Most often the first few lines of the stack trace will give us the cause behind the error.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Stack trace can be logged using the following lines of code:&lt;br /&gt;
 begin&lt;br /&gt;
  raise&lt;br /&gt;
 rescue =&amp;gt; e&lt;br /&gt;
  logger.error e.message&lt;br /&gt;
  e.backtrace.each { |line| logger.error line }&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===Env Dump and Session Dump===&lt;br /&gt;
Session dump gives all the information of the user's session. This is useful if the error which needs to be fixed is particular to a user or a group of users.&lt;br /&gt;
 &amp;lt;code&amp;gt;_csrf_token: &amp;quot;LiTiqHSVFOr8uT0+pFJhNCFjUc3YikuJy6F77QG+O1Y=&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 comment_id: 1&amp;lt;br&amp;gt;&lt;br /&gt;
 post_id: 1&amp;lt;br&amp;gt;&lt;br /&gt;
 session_id: &amp;quot;c562769a55b39620228ce6064aaa1637&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 user: #&amp;lt;User id: 4, name: &amp;quot;seriously&amp;quot;, username: &amp;quot;seriously&amp;quot;, email: &amp;quot;seriously@seriously.com&amp;quot;,&amp;lt;br&amp;gt; encrypted_password: &amp;quot;cb32e64bd4cb11c7424ea4ea75731450e99ed120d4bab155a42...&amp;quot;, salt: &amp;quot;DlLGMQzwgU&amp;quot;, is_admin: nil,&amp;lt;br&amp;gt; created_at: &amp;quot;2012-11-18 01:08:35&amp;quot;, updated_at: &amp;quot;2012-11-18 01:08:35&amp;quot;&amp;gt;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A session dump can be obtained using the following command:&lt;br /&gt;
 &amp;lt;%= debug session %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Environment dump gives details of the rails runtime environment. If the error is localized to users who use the same version of a host or a protocol, we could find that out using the environment dump.&lt;br /&gt;
 &amp;lt;code&amp;gt;GATEWAY_INTERFACE: &amp;quot;CGI/1.1&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT: &amp;quot;text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_CHARSET: &amp;quot;ISO-8859-1,utf-8;q=0.7,*;q=0.3&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_ENCODING: &amp;quot;gzip,deflate,sdch&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_LANGUAGE: &amp;quot;en-US,en;q=0.8&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 REMOTE_ADDR: &amp;quot;127.0.0.1&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 REMOTE_HOST: &amp;quot;Wayne-PC&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 SERVER_NAME: &amp;quot;localhost&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 SERVER_PROTOCOL: &amp;quot;HTTP/1.1&amp;quot;&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A Very Common Error Message in Ruby===&lt;br /&gt;
&amp;lt;code&amp;gt;undefined method ‘foo’ for nil:NilClass&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Most often, it means that an assignment failed and we didn't check for errors.&amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;code&amp;gt;@m = Movie.find_by_id(id) #could be nil&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When you try to call m.title after an assignment like the one above, it will throw this error.&lt;br /&gt;
&lt;br /&gt;
==Rails Debugger==&lt;br /&gt;
===What is a debugger?===&lt;br /&gt;
Sometimes printing errors to the console or logging is not enough to find out the root cause behind an error message. It is during these times when the debugger is a developer's best friend. The debugger helps us to step forward or backward in the code, execute or skip lines of code, examine the state of a variable or a parameter which has been passed. This will help the developer pinpoint to the actual source of the problem and fix it.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''How to install the debugger?'''&amp;lt;br&amp;gt;&lt;br /&gt;
In Rails, ruby-debug is a gem. We can install it like any other gem. To use the gem in a Rails application we need to add the following line: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;require &amp;quot;ruby-debug&amp;quot;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
in the &amp;lt;code&amp;gt;config/environments/development.rb&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby 1.9, you can use this command to install a compatible version of the debugger gem:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;gem install debugger&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''Running the debugger&amp;lt;br&amp;gt;'''&lt;br /&gt;
To use the debugger in the rails application we need to start the server with the &amp;lt;code&amp;gt;--debugger&amp;lt;/code&amp;gt; option. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;$ rails server --debugger&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we don't do this we would encounter an error like this:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;***** Debugger requested, but was not available: Start server with --debugger to enable *****&amp;lt;/code&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can invoke the debugger from any method by using the &amp;lt;code&amp;gt;debugger&amp;lt;/code&amp;gt; keyword in the method.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class PostsController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    debugger&lt;br /&gt;
    @post = Post.new&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Once the debugger method is called a debugger shell is started inside the terminal window where the application server was launched, and the cursor will be placed at ruby-debug’s prompt &amp;lt;code&amp;gt;(rdb:n)&amp;lt;/code&amp;gt; where n is the thread number. The prompt will show the next line of code which is waiting to run.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Rails is a relatively new platform for web development, it is continually evolving which effectively means debugging is harder. However by leveraging the knowledge of people who have encountered similar errors before we can resolve a subset of problems, the ones particular to versions of ruby and various gems. We have tools like debugger and application trace to help us solve problems which are specific to our application. To know more about using the debugger, please refer to the Further Reading section of the article.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# https://www.youtube.com/watch?v=Ee5vfe0mLb8&lt;br /&gt;
# http://railstips.org/blog/archives/2011/08/31/stupid-simple-debugging/&lt;br /&gt;
# http://guides.rubyonrails.org/debugging_rails_applications.html&lt;br /&gt;
# http://railscasts.com/episodes/54-debugging-with-ruby-debug&lt;br /&gt;
# http://bashdb.sourceforge.net/ruby-debug.html&lt;br /&gt;
# http://cheat.errtheblog.com/s/rdebug/&lt;br /&gt;
# http://railscasts.com/episodes/24-the-stack-trace&lt;br /&gt;
# http://www.scribd.com/doc/86869289/3/Rails-Cookery-3&lt;br /&gt;
# http://www.ruby-forum.com/topic/67687&lt;br /&gt;
# http://stackoverflow.com/questions/8408936/rake-dbmigrate-error&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
# [http://guides.rubyonrails.org/debugging_rails_applications.html Rails Guide - Debugging Rails Applications]&lt;br /&gt;
# [http://www.sitepoint.com/debug-rails-app-ruby-debug/ Debug your rails app with ruby-debug]&lt;br /&gt;
# [http://rubyforge.org/projects/ruby-debug/ Ruby Forge - Documentation for ruby-debug]&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=71242</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w-1w65 am</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=71242"/>
		<updated>2012-11-26T19:07:21Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This is a wiki article for the material presented in the Coursera SaaS video series, [https://www.youtube.com/watch?v=Ee5vfe0mLb8 3.13 Debugging by Dr. Armando Fox and Dr. David Patterson]. We aim to cover all the material presented in the video with definitions and examples&lt;br /&gt;
===Why debugging in Rails can be tricky?===&lt;br /&gt;
*We are used to printing the error on the terminal in most applications(Example: [http://www.cplusplus.com/reference/clibrary/cstdio/stderr/ STDERR]). This may not be possible for a web application since its primary form of input and output is through HTTP requests and responses.&lt;br /&gt;
&lt;br /&gt;
*Errors early in flow might manifest itself late.&lt;br /&gt;
Consider the following hierarchy seen in a Rails application:&lt;br /&gt;
 URI -&amp;gt; Route -&amp;gt; Controller -&amp;gt; Model -&amp;gt; View -&amp;gt; Renderer&lt;br /&gt;
 &lt;br /&gt;
Here, something that goes wrong in the controller might not manifest itself until the renderer. The root cause of the error might have happened a long time ago.&lt;br /&gt;
&lt;br /&gt;
*Errors can be hard to localize/reproduce if it affects only some users or routes.&lt;br /&gt;
&lt;br /&gt;
There are several approaches that can be used for debugging based on the mode of operation, that is development mode or production mode:&lt;br /&gt;
 &lt;br /&gt;
'''Printing to terminal:'''This is useful for developers, when they are writing code they can print errors to the terminal and then examine them. We cannot use this approach in production mode.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Logging:''' This is a more general approach to debugging which can be used in both modes. The logged entries are permanent record of what the application is doing. The recorded errors are saved in a log file and can be referenced later.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interactive Debugging:''' Using this tool you can stop the application in its tracks and inspect the state of the variables or other parameters to locate the error.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the various approaches and the modes in which they can be used: &amp;lt;br&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Approach !! Development !! Production&lt;br /&gt;
|-&lt;br /&gt;
| Printing to Terminal || ✓ || &lt;br /&gt;
|-&lt;br /&gt;
| Logging || ✓ || ✓&lt;br /&gt;
|-&lt;br /&gt;
| Interactive Debugging || ✓ || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==RASP==&lt;br /&gt;
Steps to follow when faced with an error can be concisely represented by RASP according to Dr. Fox.&lt;br /&gt;
===What is RASP?===&lt;br /&gt;
RASP is an acronym which briefs the steps which a developer could follow if she were facing an error message. It stands for:&lt;br /&gt;
#'''Read''' the error message.&lt;br /&gt;
#'''Ask''' your colleague  &lt;br /&gt;
#'''Search''' using [http://stackoverflow.com/ Stack Overflow] or any other search engine.&lt;br /&gt;
#'''Post''' on [http://stackoverflow.com/ Stack Overflow] or class forum&lt;br /&gt;
&lt;br /&gt;
Reading the error message carefully is the first step in debugging. The error messages in Rails are incredibly detailed and it gives us a lot of information, reading it carefully can help us locate the file and line in which you are facing the error. But what if the line looks alright to you?&amp;lt;br&amp;gt;&lt;br /&gt;
The next step is to ask a colleague an informed question. In case you are doing pair programming, this is a good step to take. The question has to be of the form &amp;quot;I am trying to do this and I expected to get this but I got this other thing instead of foo.&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
If the previous steps fail then searching using stack overflow or Google is next, especially if its an error which is particular to a version of gems or OS.&amp;lt;br&amp;gt;&lt;br /&gt;
In case you don't find a solution to your problem the final step is to get minimal but complete information which reproduces the error message which you are experiencing and post it.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example question and solution from stack overflow:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Ques.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
As we can see the question follows the guidelines explained above. It gives minimal but complete information about the error. It does not give the entire description of the error. It is important to post minimal information so that the person who answers the question can understand your problem quickly.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Ans.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The answer is posted within an hour of posting the question. This shows that posting on stack overflow is a fast way of getting expert help with debugging.&lt;br /&gt;
&lt;br /&gt;
==Understanding Error Messages in Rails==&lt;br /&gt;
Rails usually provides a very verbose description of error messages. Dr. Fox tells us that error messages are our friends, they try to not only show us what went wrong but a great deal of detail of where it went wrong. Let us look at an example error message.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
An error message was deliberately caused by entering a route which wouldn't work. The application which we are using is the backchannel application and we are trying to find a post with id=20 (it doesn't exist). This causes rails to throw the following error  message.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;'''ActiveRecord::RecordNotFound in PostsController#show'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;Couldn't find Post with id=20&amp;lt;br&amp;gt;&lt;br /&gt;
 Rails.root: C:/Users/BruceWayne/Downloads/BackChannelApplication&amp;lt;br&amp;gt;&lt;br /&gt;
 Application Trace | Framework Trace | Full Trace&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''What is the error message trying to tell us?'''&amp;lt;br&amp;gt;&lt;br /&gt;
It tells us that ActiveRecord raised the error, and the error was raised in the show method of the Posts Controller. Rails tried to find a post with id=20 but it failed.&lt;br /&gt;
===Application Trace===&lt;br /&gt;
The application trace will give us the file, line number and the method in which the error was thrown. For the above example the application trace will look like this:&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;code&amp;gt;app/controllers/posts_controller.rb:17:in `show'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also get the application trace manually at any point through the following command:&lt;br /&gt;
 begin&lt;br /&gt;
  raise object.inspect&lt;br /&gt;
 rescue&lt;br /&gt;
  Rails.logger.warn $!.backtrace.to_yaml&lt;br /&gt;
 end&lt;br /&gt;
This will cause a deliberate error along with an application trace of how you got there.&lt;br /&gt;
&lt;br /&gt;
===Stack Trace===&lt;br /&gt;
Full stack trace shows us the entire stack trace of right when the application started until the problem is encountered. Usually stack traces are very lengthy but they can be very useful to solve problems. Here is a partial stack trace from the back channel application error which we saw before:&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;code&amp;gt;activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:341:in `find_one'&amp;lt;br&amp;gt;&lt;br /&gt;
 activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:312:in `find_with_ids'&amp;lt;br&amp;gt;&lt;br /&gt;
 activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:107:in `find'&amp;lt;br&amp;gt;&lt;br /&gt;
 C:in `find'&amp;lt;br&amp;gt;&lt;br /&gt;
 app/controllers/posts_controller.rb:17:in `show'&amp;lt;br&amp;gt;&lt;br /&gt;
 actionpack (3.2.8) lib/action_controller/metal/implicit_render.rb:4:in `send_action'&amp;lt;br&amp;gt;&lt;br /&gt;
 actionpack (3.2.8) lib/abstract_controller/base.rb:167:in `process_action'&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can see the stack trace right from where the Rails application started, we can see calls to &amp;lt;code&amp;gt;activerecord&amp;lt;/code&amp;gt; in the beginning. It is unlikely that there would be a problem in those files. As we continue looking into the stack trace we see the find method, we can click on the link in the trace and it will take us to the line in which the error was found. Most often the first few lines of the stack trace will give us the cause behind the error.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Stack trace can be logged using the following lines of code:&lt;br /&gt;
 begin&lt;br /&gt;
  raise&lt;br /&gt;
 rescue =&amp;gt; e&lt;br /&gt;
  logger.error e.message&lt;br /&gt;
  e.backtrace.each { |line| logger.error line }&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===Env Dump and Session Dump===&lt;br /&gt;
Session dump gives all the information of the user's session. This is useful if the error which needs to be fixed is particular to a user or a group of users.&lt;br /&gt;
 &amp;lt;code&amp;gt;_csrf_token: &amp;quot;LiTiqHSVFOr8uT0+pFJhNCFjUc3YikuJy6F77QG+O1Y=&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 comment_id: 1&amp;lt;br&amp;gt;&lt;br /&gt;
 post_id: 1&amp;lt;br&amp;gt;&lt;br /&gt;
 session_id: &amp;quot;c562769a55b39620228ce6064aaa1637&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 user: #&amp;lt;User id: 4, name: &amp;quot;seriously&amp;quot;, username: &amp;quot;seriously&amp;quot;, email: &amp;quot;seriously@seriously.com&amp;quot;,&amp;lt;br&amp;gt; encrypted_password: &amp;quot;cb32e64bd4cb11c7424ea4ea75731450e99ed120d4bab155a42...&amp;quot;, salt: &amp;quot;DlLGMQzwgU&amp;quot;, is_admin: nil,&amp;lt;br&amp;gt; created_at: &amp;quot;2012-11-18 01:08:35&amp;quot;, updated_at: &amp;quot;2012-11-18 01:08:35&amp;quot;&amp;gt;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A session dump can be obtained using the following command:&lt;br /&gt;
 &amp;lt;%= debug session %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Environment dump gives details of the rails runtime environment. If the error is localized to users who use the same version of a host or a protocol, we could find that out using the environment dump.&lt;br /&gt;
 &amp;lt;code&amp;gt;GATEWAY_INTERFACE: &amp;quot;CGI/1.1&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT: &amp;quot;text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_CHARSET: &amp;quot;ISO-8859-1,utf-8;q=0.7,*;q=0.3&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_ENCODING: &amp;quot;gzip,deflate,sdch&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_LANGUAGE: &amp;quot;en-US,en;q=0.8&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 REMOTE_ADDR: &amp;quot;127.0.0.1&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 REMOTE_HOST: &amp;quot;Wayne-PC&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 SERVER_NAME: &amp;quot;localhost&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 SERVER_PROTOCOL: &amp;quot;HTTP/1.1&amp;quot;&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A Very Common Error Message in Ruby===&lt;br /&gt;
&amp;lt;code&amp;gt;undefined method ‘foo’ for nil:NilClass&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Most often, it means that an assignment failed and we didn't check for errors.&amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;code&amp;gt;@m = Movie.find_by_id(id) #could be nil&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When you try to call m.title after an assignment like the one above, it will throw this error.&lt;br /&gt;
&lt;br /&gt;
==Rails Debugger==&lt;br /&gt;
===What is a debugger?===&lt;br /&gt;
Sometimes printing errors to the console or logging is not enough to find out the root cause behind an error message. It is during these times when the debugger is a developer's best friend. The debugger helps us to step forward or backward in the code, execute or skip lines of code, examine the state of a variable or a parameter which has been passed. This will help the developer pinpoint to the actual source of the problem and fix it.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''How to install the debugger?'''&amp;lt;br&amp;gt;&lt;br /&gt;
In Rails, ruby-debug is a gem. We can install it like any other gem. To use the gem in a Rails application we need to add the following line: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;require &amp;quot;ruby-debug&amp;quot;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
in the &amp;lt;code&amp;gt;config/environments/development.rb&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby 1.9, you can use this command to install a compatible version of the debugger gem:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;gem install debugger&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''Running the debugger&amp;lt;br&amp;gt;'''&lt;br /&gt;
To use the debugger in the rails application we need to start the server with the &amp;lt;code&amp;gt;--debugger&amp;lt;/code&amp;gt; option. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;$ rails server --debugger&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we don't do this we would encounter an error like this:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;***** Debugger requested, but was not available: Start server with --debugger to enable *****&amp;lt;/code&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can invoke the debugger from any method by using the &amp;lt;code&amp;gt;debugger&amp;lt;/code&amp;gt; keyword in the method.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class PostsController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    debugger&lt;br /&gt;
    @post = Post.new&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Once the debugger method is called a debugger shell is started inside the terminal window where the application server was launched, and the cursor will be placed at ruby-debug’s prompt &amp;lt;code&amp;gt;(rdb:n)&amp;lt;/code&amp;gt; where n is the thread number. The prompt will show the next line of code which is waiting to run.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Rails is a relatively new platform for web development, it is continually evolving which effectively means debugging is harder. However by leveraging the knowledge of people who have encountered similar errors before we can resolve a subset of problems, the ones particular to versions of ruby and various gems. We have tools like debugger and application trace to help us solve problems which are specific to our application. To know more about using the debugger, please refer to the Further Reading section of the article.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# https://www.youtube.com/watch?v=Ee5vfe0mLb8&lt;br /&gt;
# http://railstips.org/blog/archives/2011/08/31/stupid-simple-debugging/&lt;br /&gt;
# http://guides.rubyonrails.org/debugging_rails_applications.html&lt;br /&gt;
# http://railscasts.com/episodes/54-debugging-with-ruby-debug&lt;br /&gt;
# http://bashdb.sourceforge.net/ruby-debug.html&lt;br /&gt;
# http://cheat.errtheblog.com/s/rdebug/&lt;br /&gt;
# http://railscasts.com/episodes/24-the-stack-trace&lt;br /&gt;
# http://www.scribd.com/doc/86869289/3/Rails-Cookery-3&lt;br /&gt;
# http://www.ruby-forum.com/topic/67687&lt;br /&gt;
# http://stackoverflow.com/questions/8408936/rake-dbmigrate-error&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
# [http://guides.rubyonrails.org/debugging_rails_applications.html Rails Guide - Debugging Rails Applications]&lt;br /&gt;
# [http://www.sitepoint.com/debug-rails-app-ruby-debug/ Debug your rails app with ruby-debug]&lt;br /&gt;
# [http://rubyforge.org/projects/ruby-debug/ Ruby Forge - Documentation for ruby-debug]&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=71241</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w-1w65 am</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=71241"/>
		<updated>2012-11-26T19:07:06Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* Further Reading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This is a wiki article for the material presented in the Coursera SaaS video series, [https://www.youtube.com/watch?v=Ee5vfe0mLb8 3.13 Debugging by Dr. Armando Fox and Dr. David Patterson]. We aim to cover all the material presented in the video with definitions and examples&lt;br /&gt;
===Why debugging in Rails can be tricky?===&lt;br /&gt;
*We are used to printing the error on the terminal in most applications(Example: [http://www.cplusplus.com/reference/clibrary/cstdio/stderr/ STDERR]). This may not be possible for a web application since its primary form of input and output is through HTTP requests and responses.&lt;br /&gt;
&lt;br /&gt;
*Errors early in flow might manifest itself late.&lt;br /&gt;
Consider the following hierarchy seen in a Rails application:&lt;br /&gt;
 URI -&amp;gt; Route -&amp;gt; Controller -&amp;gt; Model -&amp;gt; View -&amp;gt; Renderer&lt;br /&gt;
 &lt;br /&gt;
Here, something that goes wrong in the controller might not manifest itself until the renderer. The root cause of the error might have happened a long time ago.&lt;br /&gt;
&lt;br /&gt;
*Errors can be hard to localize/reproduce if it affects only some users or routes.&lt;br /&gt;
&lt;br /&gt;
There are several approaches that can be used for debugging based on the mode of operation, that is development mode or production mode:&lt;br /&gt;
 &lt;br /&gt;
'''Printing to terminal:'''This is useful for developers, when they are writing code they can print errors to the terminal and then examine them. We cannot use this approach in production mode.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Logging:''' This is a more general approach to debugging which can be used in both modes. The logged entries are permanent record of what the application is doing. The recorded errors are saved in a log file and can be referenced later.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interactive Debugging:''' Using this tool you can stop the application in its tracks and inspect the state of the variables or other parameters to locate the error.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the various approaches and the modes in which they can be used: &amp;lt;br&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Approach !! Development !! Production&lt;br /&gt;
|-&lt;br /&gt;
| Printing to Terminal || ✓ || &lt;br /&gt;
|-&lt;br /&gt;
| Logging || ✓ || ✓&lt;br /&gt;
|-&lt;br /&gt;
| Interactive Debugging || ✓ || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==RASP==&lt;br /&gt;
Steps to follow when faced with an error can be concisely represented by RASP according to Dr. Fox.&lt;br /&gt;
===What is RASP?===&lt;br /&gt;
RASP is an acronym which briefs the steps which a developer could follow if she were facing an error message. It stands for:&lt;br /&gt;
#'''Read''' the error message.&lt;br /&gt;
#'''Ask''' your colleague  &lt;br /&gt;
#'''Search''' using [http://stackoverflow.com/ Stack Overflow] or any other search engine.&lt;br /&gt;
#'''Post''' on [http://stackoverflow.com/ Stack Overflow] or class forum&lt;br /&gt;
&lt;br /&gt;
Reading the error message carefully is the first step in debugging. The error messages in Rails are incredibly detailed and it gives us a lot of information, reading it carefully can help us locate the file and line in which you are facing the error. But what if the line looks alright to you?&amp;lt;br&amp;gt;&lt;br /&gt;
The next step is to ask a colleague an informed question. In case you are doing pair programming, this is a good step to take. The question has to be of the form &amp;quot;I am trying to do this and I expected to get this but I got this other thing instead of foo.&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
If the previous steps fail then searching using stack overflow or Google is next, especially if its an error which is particular to a version of gems or OS.&amp;lt;br&amp;gt;&lt;br /&gt;
In case you don't find a solution to your problem the final step is to get minimal but complete information which reproduces the error message which you are experiencing and post it.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example question and solution from stack overflow:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Ques.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
As we can see the question follows the guidelines explained above. It gives minimal but complete information about the error. It does not give the entire description of the error. It is important to post minimal information so that the person who answers the question can understand your problem quickly.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Ans.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The answer is posted within an hour of posting the question. This shows that posting on stack overflow is a fast way of getting expert help with debugging.&lt;br /&gt;
&lt;br /&gt;
==Understanding Error Messages in Rails==&lt;br /&gt;
Rails usually provides a very verbose description of error messages. Dr. Fox tells us that error messages are our friends, they try to not only show us what went wrong but a great deal of detail of where it went wrong. Let us look at an example error message.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
An error message was deliberately caused by entering a route which wouldn't work. The application which we are using is the backchannel application and we are trying to find a post with id=20 (it doesn't exist). This causes rails to throw the following error  message.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;'''ActiveRecord::RecordNotFound in PostsController#show'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;Couldn't find Post with id=20&amp;lt;br&amp;gt;&lt;br /&gt;
 Rails.root: C:/Users/BruceWayne/Downloads/BackChannelApplication&amp;lt;br&amp;gt;&lt;br /&gt;
 Application Trace | Framework Trace | Full Trace&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''What is the error message trying to tell us?'''&amp;lt;br&amp;gt;&lt;br /&gt;
It tells us that ActiveRecord raised the error, and the error was raised in the show method of the Posts Controller. Rails tried to find a post with id=20 but it failed.&lt;br /&gt;
===Application Trace===&lt;br /&gt;
The application trace will give us the file, line number and the method in which the error was thrown. For the above example the application trace will look like this:&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;code&amp;gt;app/controllers/posts_controller.rb:17:in `show'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also get the application trace manually at any point through the following command:&lt;br /&gt;
 begin&lt;br /&gt;
  raise object.inspect&lt;br /&gt;
 rescue&lt;br /&gt;
  Rails.logger.warn $!.backtrace.to_yaml&lt;br /&gt;
 end&lt;br /&gt;
This will cause a deliberate error along with an application trace of how you got there.&lt;br /&gt;
&lt;br /&gt;
===Stack Trace===&lt;br /&gt;
Full stack trace shows us the entire stack trace of right when the application started until the problem is encountered. Usually stack traces are very lengthy but they can be very useful to solve problems. Here is a partial stack trace from the back channel application error which we saw before:&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;code&amp;gt;activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:341:in `find_one'&amp;lt;br&amp;gt;&lt;br /&gt;
 activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:312:in `find_with_ids'&amp;lt;br&amp;gt;&lt;br /&gt;
 activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:107:in `find'&amp;lt;br&amp;gt;&lt;br /&gt;
 C:in `find'&amp;lt;br&amp;gt;&lt;br /&gt;
 app/controllers/posts_controller.rb:17:in `show'&amp;lt;br&amp;gt;&lt;br /&gt;
 actionpack (3.2.8) lib/action_controller/metal/implicit_render.rb:4:in `send_action'&amp;lt;br&amp;gt;&lt;br /&gt;
 actionpack (3.2.8) lib/abstract_controller/base.rb:167:in `process_action'&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can see the stack trace right from where the Rails application started, we can see calls to &amp;lt;code&amp;gt;activerecord&amp;lt;/code&amp;gt; in the beginning. It is unlikely that there would be a problem in those files. As we continue looking into the stack trace we see the find method, we can click on the link in the trace and it will take us to the line in which the error was found. Most often the first few lines of the stack trace will give us the cause behind the error.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Stack trace can be logged using the following lines of code:&lt;br /&gt;
 begin&lt;br /&gt;
  raise&lt;br /&gt;
 rescue =&amp;gt; e&lt;br /&gt;
  logger.error e.message&lt;br /&gt;
  e.backtrace.each { |line| logger.error line }&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===Env Dump and Session Dump===&lt;br /&gt;
Session dump gives all the information of the user's session. This is useful if the error which needs to be fixed is particular to a user or a group of users.&lt;br /&gt;
 &amp;lt;code&amp;gt;_csrf_token: &amp;quot;LiTiqHSVFOr8uT0+pFJhNCFjUc3YikuJy6F77QG+O1Y=&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 comment_id: 1&amp;lt;br&amp;gt;&lt;br /&gt;
 post_id: 1&amp;lt;br&amp;gt;&lt;br /&gt;
 session_id: &amp;quot;c562769a55b39620228ce6064aaa1637&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 user: #&amp;lt;User id: 4, name: &amp;quot;seriously&amp;quot;, username: &amp;quot;seriously&amp;quot;, email: &amp;quot;seriously@seriously.com&amp;quot;,&amp;lt;br&amp;gt; encrypted_password: &amp;quot;cb32e64bd4cb11c7424ea4ea75731450e99ed120d4bab155a42...&amp;quot;, salt: &amp;quot;DlLGMQzwgU&amp;quot;, is_admin: nil,&amp;lt;br&amp;gt; created_at: &amp;quot;2012-11-18 01:08:35&amp;quot;, updated_at: &amp;quot;2012-11-18 01:08:35&amp;quot;&amp;gt;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A session dump can be obtained using the following command:&lt;br /&gt;
 &amp;lt;%= debug session %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Environment dump gives details of the rails runtime environment. If the error is localized to users who use the same version of a host or a protocol, we could find that out using the environment dump.&lt;br /&gt;
 &amp;lt;code&amp;gt;GATEWAY_INTERFACE: &amp;quot;CGI/1.1&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT: &amp;quot;text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_CHARSET: &amp;quot;ISO-8859-1,utf-8;q=0.7,*;q=0.3&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_ENCODING: &amp;quot;gzip,deflate,sdch&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_LANGUAGE: &amp;quot;en-US,en;q=0.8&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 REMOTE_ADDR: &amp;quot;127.0.0.1&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 REMOTE_HOST: &amp;quot;Wayne-PC&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 SERVER_NAME: &amp;quot;localhost&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 SERVER_PROTOCOL: &amp;quot;HTTP/1.1&amp;quot;&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A Very Common Error Message in Ruby===&lt;br /&gt;
&amp;lt;code&amp;gt;undefined method ‘foo’ for nil:NilClass&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Most often, it means that an assignment failed and we didn't check for errors.&amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;code&amp;gt;@m = Movie.find_by_id(id) #could be nil&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When you try to call m.title after an assignment like the one above, it will throw this error.&lt;br /&gt;
&lt;br /&gt;
==Rails Debugger==&lt;br /&gt;
===What is a debugger?===&lt;br /&gt;
Sometimes printing errors to the console or logging is not enough to find out the root cause behind an error message. It is during these times when the debugger is a developer's best friend. The debugger helps us to step forward or backward in the code, execute or skip lines of code, examine the state of a variable or a parameter which has been passed. This will help the developer pinpoint to the actual source of the problem and fix it.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''How to install the debugger?'''&amp;lt;br&amp;gt;&lt;br /&gt;
In Rails, ruby-debug is a gem. We can install it like any other gem. To use the gem in a Rails application we need to add the following line: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;require &amp;quot;ruby-debug&amp;quot;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
in the &amp;lt;code&amp;gt;config/environments/development.rb&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby 1.9, you can use this command to install a compatible version of the debugger gem:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;gem install debugger&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''Running the debugger&amp;lt;br&amp;gt;'''&lt;br /&gt;
To use the debugger in the rails application we need to start the server with the &amp;lt;code&amp;gt;--debugger&amp;lt;/code&amp;gt; option. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;$ rails server --debugger&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we don't do this we would encounter an error like this:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;***** Debugger requested, but was not available: Start server with --debugger to enable *****&amp;lt;/code&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can invoke the debugger from any method by using the &amp;lt;code&amp;gt;debugger&amp;lt;/code&amp;gt; keyword in the method.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class PostsController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    debugger&lt;br /&gt;
    @post = Post.new&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Once the debugger method is called a debugger shell is started inside the terminal window where the application server was launched, and the cursor will be placed at ruby-debug’s prompt &amp;lt;code&amp;gt;(rdb:n)&amp;lt;/code&amp;gt; where n is the thread number. The prompt will show the next line of code which is waiting to run.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Rails is a relatively new platform for web development, it is continually evolving which effectively means debugging is harder. However by leveraging the knowledge of people who have encountered similar errors before we can resolve a subset of problems, the ones particular to versions of ruby and various gems. We have tools like debugger and application trace to help us solve problems which are specific to our application. To know more about using the debugger, please refer to the Further Reading section of the article.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# https://www.youtube.com/watch?v=Ee5vfe0mLb8&lt;br /&gt;
# http://railstips.org/blog/archives/2011/08/31/stupid-simple-debugging/&lt;br /&gt;
# http://guides.rubyonrails.org/debugging_rails_applications.html&lt;br /&gt;
# http://railscasts.com/episodes/54-debugging-with-ruby-debug&lt;br /&gt;
# http://bashdb.sourceforge.net/ruby-debug.html&lt;br /&gt;
# http://cheat.errtheblog.com/s/rdebug/&lt;br /&gt;
# http://railscasts.com/episodes/24-the-stack-trace&lt;br /&gt;
# http://www.scribd.com/doc/86869289/3/Rails-Cookery-3&lt;br /&gt;
# http://www.ruby-forum.com/topic/67687&lt;br /&gt;
# http://stackoverflow.com/questions/8408936/rake-dbmigrate-error&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70371</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w-1w65 am</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70371"/>
		<updated>2012-11-18T23:50:03Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* Stack Trace */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This is a wiki article for the material presented in the Coursera SaaS video series, [https://www.youtube.com/watch?v=Ee5vfe0mLb8 3.13 Debugging by Dr. Armando Fox and Dr. David Patterson]. We aim to cover all the material presented in the video with definitions and examples&lt;br /&gt;
===Why debugging in Rails can be tricky?===&lt;br /&gt;
*We are used to printing the error on the terminal in most applications(Example: [http://www.cplusplus.com/reference/clibrary/cstdio/stderr/ STDERR]). This may not be possible for a web application since its primary form of input and output is through HTTP requests and responses.&lt;br /&gt;
&lt;br /&gt;
*Errors early in flow might manifest itself late.&lt;br /&gt;
Consider the following hierarchy seen in a Rails application:&lt;br /&gt;
 URI -&amp;gt; Route -&amp;gt; Controller -&amp;gt; Model -&amp;gt; View -&amp;gt; Renderer&lt;br /&gt;
 &lt;br /&gt;
Here, something that goes wrong in the controller might not manifest itself until the renderer. The root cause of the error might have happened a long time ago.&lt;br /&gt;
&lt;br /&gt;
*Errors can be hard to localize/reproduce if it affects only some users or routes.&lt;br /&gt;
&lt;br /&gt;
There are several approaches that can be used for debugging based on the mode of operation, that is development mode or production mode:&lt;br /&gt;
 &lt;br /&gt;
'''Printing to terminal:'''This is useful for developers, when they are writing code they can print errors to the terminal and then examine them. We cannot use this approach in production mode.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Logging:''' This is a more general approach to debugging which can be used in both modes. The logged entries are permanent record of what the application is doing. The recorded errors are saved in a log file and can be referenced later.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interactive Debugging:''' Using this tool you can stop the application in its tracks and inspect the state of the variables or other parameters to locate the error.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the various approaches and the modes in which they can be used: &amp;lt;br&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Approach !! Development !! Production&lt;br /&gt;
|-&lt;br /&gt;
| Printing to Terminal || ✓ || &lt;br /&gt;
|-&lt;br /&gt;
| Logging || ✓ || ✓&lt;br /&gt;
|-&lt;br /&gt;
| Interactive Debugging || ✓ || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==RASP==&lt;br /&gt;
Steps to follow when faced with an error can be concisely represented by RASP according to Dr. Fox.&lt;br /&gt;
===What is RASP?===&lt;br /&gt;
RASP is an acronym which briefs the steps which a developer could follow if she were facing an error message. It stands for:&lt;br /&gt;
#'''Read''' the error message.&lt;br /&gt;
#'''Ask''' your colleague  &lt;br /&gt;
#'''Search''' using [http://stackoverflow.com/ Stack Overflow] or any other search engine.&lt;br /&gt;
#'''Post''' on [http://stackoverflow.com/ Stack Overflow] or class forum&lt;br /&gt;
&lt;br /&gt;
Reading the error message carefully is the first step in debugging. The error messages in Rails are incredibly detailed and it gives us a lot of information, reading it carefully can help us locate the file and line in which you are facing the error. But what if the line looks alright to you?&amp;lt;br&amp;gt;&lt;br /&gt;
The next step is to ask a colleague an informed question. In case you are doing pair programming, this is a good step to take. The question has to be of the form &amp;quot;I am trying to do this and I expected to get this but I got this other thing instead of foo.&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
If the previous steps fail then searching using stack overflow or Google is next, especially if its an error which is particular to a version of gems or OS.&amp;lt;br&amp;gt;&lt;br /&gt;
In case you don't find a solution to your problem the final step is to get minimal but complete information which reproduces the error message which you are experiencing and post it.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example question and solution from stack overflow:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Ques.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
As we can see the question follows the guidelines explained above. It gives minimal but complete information about the error. It does not give the entire description of the error. It is important to post minimal information so that the person who answers the question can understand your problem quickly.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Ans.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The answer is posted within an hour of posting the question. This shows that posting on stack overflow is a fast way of getting expert help with debugging.&lt;br /&gt;
&lt;br /&gt;
==Understanding Error Messages in Rails==&lt;br /&gt;
Rails usually provides a very verbose description of error messages. Dr. Fox tells us that error messages are our friends, they try to not only show us what went wrong but a great deal of detail of where it went wrong. Let us look at an example error message.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
An error message was deliberately caused by entering a route which wouldn't work. The application which we are using is the backchannel application and we are trying to find a post with id=20 (it doesn't exist). This causes rails to throw the following error  message.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;'''ActiveRecord::RecordNotFound in PostsController#show'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;Couldn't find Post with id=20&amp;lt;br&amp;gt;&lt;br /&gt;
 Rails.root: C:/Users/BruceWayne/Downloads/BackChannelApplication&amp;lt;br&amp;gt;&lt;br /&gt;
 Application Trace | Framework Trace | Full Trace&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''What is the error message trying to tell us?'''&amp;lt;br&amp;gt;&lt;br /&gt;
It tells us that ActiveRecord raised the error, and the error was raised in the show method of the Posts Controller. Rails tried to find a post with id=20 but it failed.&lt;br /&gt;
===Application Trace===&lt;br /&gt;
The application trace will give us the file, line number and the method in which the error was thrown. For the above example the application trace will look like this:&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;code&amp;gt;app/controllers/posts_controller.rb:17:in `show'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also get the application trace manually at any point through the following command:&lt;br /&gt;
 begin&lt;br /&gt;
  raise object.inspect&lt;br /&gt;
 rescue&lt;br /&gt;
  Rails.logger.warn $!.backtrace.to_yaml&lt;br /&gt;
 end&lt;br /&gt;
This will cause a deliberate error along with an application trace of how you got there.&lt;br /&gt;
&lt;br /&gt;
===Stack Trace===&lt;br /&gt;
Full stack trace shows us the entire stack trace of right when the application started until the problem is encountered. Usually stack traces are very lengthy but they can be very useful to solve problems. Here is a partial stack trace from the back channel application error which we saw before:&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;code&amp;gt;activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:341:in `find_one'&amp;lt;br&amp;gt;&lt;br /&gt;
 activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:312:in `find_with_ids'&amp;lt;br&amp;gt;&lt;br /&gt;
 activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:107:in `find'&amp;lt;br&amp;gt;&lt;br /&gt;
 C:in `find'&amp;lt;br&amp;gt;&lt;br /&gt;
 app/controllers/posts_controller.rb:17:in `show'&amp;lt;br&amp;gt;&lt;br /&gt;
 actionpack (3.2.8) lib/action_controller/metal/implicit_render.rb:4:in `send_action'&amp;lt;br&amp;gt;&lt;br /&gt;
 actionpack (3.2.8) lib/abstract_controller/base.rb:167:in `process_action'&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can see the stack trace right from where the Rails application started, we can see calls to &amp;lt;code&amp;gt;activerecord&amp;lt;/code&amp;gt; in the beginning. It is unlikely that there would be a problem in those files. As we continue looking into the stack trace we see the find method, we can click on the link in the trace and it will take us to the line in which the error was found. Most often the first few lines of the stack trace will give us the cause behind the error.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Stack trace can be logged using the following lines of code:&lt;br /&gt;
 begin&lt;br /&gt;
  raise&lt;br /&gt;
 rescue =&amp;gt; e&lt;br /&gt;
  logger.error e.message&lt;br /&gt;
  e.backtrace.each { |line| logger.error line }&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===Env Dump and Session Dump===&lt;br /&gt;
Session dump gives all the information of the user's session. This is useful if the error which needs to be fixed is particular to a user or a group of users.&lt;br /&gt;
 &amp;lt;code&amp;gt;_csrf_token: &amp;quot;LiTiqHSVFOr8uT0+pFJhNCFjUc3YikuJy6F77QG+O1Y=&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 comment_id: 1&amp;lt;br&amp;gt;&lt;br /&gt;
 post_id: 1&amp;lt;br&amp;gt;&lt;br /&gt;
 session_id: &amp;quot;c562769a55b39620228ce6064aaa1637&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 user: #&amp;lt;User id: 4, name: &amp;quot;seriously&amp;quot;, username: &amp;quot;seriously&amp;quot;, email: &amp;quot;seriously@seriously.com&amp;quot;,&amp;lt;br&amp;gt; encrypted_password: &amp;quot;cb32e64bd4cb11c7424ea4ea75731450e99ed120d4bab155a42...&amp;quot;, salt: &amp;quot;DlLGMQzwgU&amp;quot;, is_admin: nil,&amp;lt;br&amp;gt; created_at: &amp;quot;2012-11-18 01:08:35&amp;quot;, updated_at: &amp;quot;2012-11-18 01:08:35&amp;quot;&amp;gt;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A session dump can be obtained using the following command:&lt;br /&gt;
 &amp;lt;%= debug session %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Environment dump gives details of the rails runtime environment. If the error is localized to users who use the same version of a host or a protocol, we could find that out using the environment dump.&lt;br /&gt;
 &amp;lt;code&amp;gt;GATEWAY_INTERFACE: &amp;quot;CGI/1.1&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT: &amp;quot;text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_CHARSET: &amp;quot;ISO-8859-1,utf-8;q=0.7,*;q=0.3&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_ENCODING: &amp;quot;gzip,deflate,sdch&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_LANGUAGE: &amp;quot;en-US,en;q=0.8&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 REMOTE_ADDR: &amp;quot;127.0.0.1&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 REMOTE_HOST: &amp;quot;Wayne-PC&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 SERVER_NAME: &amp;quot;localhost&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 SERVER_PROTOCOL: &amp;quot;HTTP/1.1&amp;quot;&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A Very Common Error Message in Ruby===&lt;br /&gt;
&amp;lt;code&amp;gt;undefined method ‘foo’ for nil:NilClass&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Most often, it means that an assignment failed and we didn't check for errors.&amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;code&amp;gt;@m = Movie.find_by_id(id) #could be nil&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When you try to call m.title after an assignment like the one above, it will throw this error.&lt;br /&gt;
&lt;br /&gt;
==Rails Debugger==&lt;br /&gt;
===What is a debugger?===&lt;br /&gt;
Sometimes printing errors to the console or logging is not enough to find out the root cause behind an error message. It is during these times when the debugger is a developer's best friend. The debugger helps us to step forward or backward in the code, execute or skip lines of code, examine the state of a variable or a parameter which has been passed. This will help the developer pinpoint to the actual source of the problem and fix it.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''How to install the debugger?'''&amp;lt;br&amp;gt;&lt;br /&gt;
In Rails, ruby-debug is a gem. We can install it like any other gem. To use the gem in a Rails application we need to add the following line: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;require &amp;quot;ruby-debug&amp;quot;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
in the &amp;lt;code&amp;gt;config/environments/development.rb&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby 1.9, you can use this command to install a compatible version of the debugger gem:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;gem install debugger&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''Running the debugger&amp;lt;br&amp;gt;'''&lt;br /&gt;
To use the debugger in the rails application we need to start the server with the &amp;lt;code&amp;gt;--debugger&amp;lt;/code&amp;gt; option. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;$ rails server --debugger&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we don't do this we would encounter an error like this:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;***** Debugger requested, but was not available: Start server with --debugger to enable *****&amp;lt;/code&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can invoke the debugger from any method by using the &amp;lt;code&amp;gt;debugger&amp;lt;/code&amp;gt; keyword in the method.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class PostsController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    debugger&lt;br /&gt;
    @post = Post.new&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Once the debugger method is called a debugger shell is started inside the terminal window where the application server was launched, and the cursor will be placed at ruby-debug’s prompt &amp;lt;code&amp;gt;(rdb:n)&amp;lt;/code&amp;gt; where n is the thread number. The prompt will show the next line of code which is waiting to run.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Rails is a relatively new platform for web development, it is continually evolving which effectively means debugging is harder. However by leveraging the knowledge of people who have encountered similar errors before we can resolve a subset of problems, the ones particular to versions of ruby and various gems. We have tools like debugger and application trace to help us solve problems which are specific to our application. To know more about using the debugger, please refer to the Further Reading section of the article.&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
# [http://guides.rubyonrails.org/debugging_rails_applications.html Rails Guide - Debugging Rails Applications]&lt;br /&gt;
# [http://www.sitepoint.com/debug-rails-app-ruby-debug/ Debug your rails app with ruby-debug]&lt;br /&gt;
# [http://rubyforge.org/projects/ruby-debug/ Ruby Forge - Documentation for ruby-debug]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# https://www.youtube.com/watch?v=Ee5vfe0mLb8&lt;br /&gt;
# http://railstips.org/blog/archives/2011/08/31/stupid-simple-debugging/&lt;br /&gt;
# http://guides.rubyonrails.org/debugging_rails_applications.html&lt;br /&gt;
# http://railscasts.com/episodes/54-debugging-with-ruby-debug&lt;br /&gt;
# http://bashdb.sourceforge.net/ruby-debug.html&lt;br /&gt;
# http://cheat.errtheblog.com/s/rdebug/&lt;br /&gt;
# http://railscasts.com/episodes/24-the-stack-trace&lt;br /&gt;
# http://www.scribd.com/doc/86869289/3/Rails-Cookery-3&lt;br /&gt;
# http://www.ruby-forum.com/topic/67687&lt;br /&gt;
# http://stackoverflow.com/questions/8408936/rake-dbmigrate-error&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70370</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w-1w65 am</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70370"/>
		<updated>2012-11-18T23:48:20Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* Conclusion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This is a wiki article for the material presented in the Coursera SaaS video series, [https://www.youtube.com/watch?v=Ee5vfe0mLb8 3.13 Debugging by Dr. Armando Fox and Dr. David Patterson]. We aim to cover all the material presented in the video with definitions and examples&lt;br /&gt;
===Why debugging in Rails can be tricky?===&lt;br /&gt;
*We are used to printing the error on the terminal in most applications(Example: [http://www.cplusplus.com/reference/clibrary/cstdio/stderr/ STDERR]). This may not be possible for a web application since its primary form of input and output is through HTTP requests and responses.&lt;br /&gt;
&lt;br /&gt;
*Errors early in flow might manifest itself late.&lt;br /&gt;
Consider the following hierarchy seen in a Rails application:&lt;br /&gt;
 URI -&amp;gt; Route -&amp;gt; Controller -&amp;gt; Model -&amp;gt; View -&amp;gt; Renderer&lt;br /&gt;
 &lt;br /&gt;
Here, something that goes wrong in the controller might not manifest itself until the renderer. The root cause of the error might have happened a long time ago.&lt;br /&gt;
&lt;br /&gt;
*Errors can be hard to localize/reproduce if it affects only some users or routes.&lt;br /&gt;
&lt;br /&gt;
There are several approaches that can be used for debugging based on the mode of operation, that is development mode or production mode:&lt;br /&gt;
 &lt;br /&gt;
'''Printing to terminal:'''This is useful for developers, when they are writing code they can print errors to the terminal and then examine them. We cannot use this approach in production mode.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Logging:''' This is a more general approach to debugging which can be used in both modes. The logged entries are permanent record of what the application is doing. The recorded errors are saved in a log file and can be referenced later.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interactive Debugging:''' Using this tool you can stop the application in its tracks and inspect the state of the variables or other parameters to locate the error.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the various approaches and the modes in which they can be used: &amp;lt;br&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Approach !! Development !! Production&lt;br /&gt;
|-&lt;br /&gt;
| Printing to Terminal || ✓ || &lt;br /&gt;
|-&lt;br /&gt;
| Logging || ✓ || ✓&lt;br /&gt;
|-&lt;br /&gt;
| Interactive Debugging || ✓ || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==RASP==&lt;br /&gt;
Steps to follow when faced with an error can be concisely represented by RASP according to Dr. Fox.&lt;br /&gt;
===What is RASP?===&lt;br /&gt;
RASP is an acronym which briefs the steps which a developer could follow if she were facing an error message. It stands for:&lt;br /&gt;
#'''Read''' the error message.&lt;br /&gt;
#'''Ask''' your colleague  &lt;br /&gt;
#'''Search''' using [http://stackoverflow.com/ Stack Overflow] or any other search engine.&lt;br /&gt;
#'''Post''' on [http://stackoverflow.com/ Stack Overflow] or class forum&lt;br /&gt;
&lt;br /&gt;
Reading the error message carefully is the first step in debugging. The error messages in Rails are incredibly detailed and it gives us a lot of information, reading it carefully can help us locate the file and line in which you are facing the error. But what if the line looks alright to you?&amp;lt;br&amp;gt;&lt;br /&gt;
The next step is to ask a colleague an informed question. In case you are doing pair programming, this is a good step to take. The question has to be of the form &amp;quot;I am trying to do this and I expected to get this but I got this other thing instead of foo.&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
If the previous steps fail then searching using stack overflow or Google is next, especially if its an error which is particular to a version of gems or OS.&amp;lt;br&amp;gt;&lt;br /&gt;
In case you don't find a solution to your problem the final step is to get minimal but complete information which reproduces the error message which you are experiencing and post it.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example question and solution from stack overflow:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Ques.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
As we can see the question follows the guidelines explained above. It gives minimal but complete information about the error. It does not give the entire description of the error. It is important to post minimal information so that the person who answers the question can understand your problem quickly.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Ans.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The answer is posted within an hour of posting the question. This shows that posting on stack overflow is a fast way of getting expert help with debugging.&lt;br /&gt;
&lt;br /&gt;
==Understanding Error Messages in Rails==&lt;br /&gt;
Rails usually provides a very verbose description of error messages. Dr. Fox tells us that error messages are our friends, they try to not only show us what went wrong but a great deal of detail of where it went wrong. Let us look at an example error message.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
An error message was deliberately caused by entering a route which wouldn't work. The application which we are using is the backchannel application and we are trying to find a post with id=20 (it doesn't exist). This causes rails to throw the following error  message.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;'''ActiveRecord::RecordNotFound in PostsController#show'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;Couldn't find Post with id=20&amp;lt;br&amp;gt;&lt;br /&gt;
 Rails.root: C:/Users/BruceWayne/Downloads/BackChannelApplication&amp;lt;br&amp;gt;&lt;br /&gt;
 Application Trace | Framework Trace | Full Trace&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''What is the error message trying to tell us?'''&amp;lt;br&amp;gt;&lt;br /&gt;
It tells us that ActiveRecord raised the error, and the error was raised in the show method of the Posts Controller. Rails tried to find a post with id=20 but it failed.&lt;br /&gt;
===Application Trace===&lt;br /&gt;
The application trace will give us the file, line number and the method in which the error was thrown. For the above example the application trace will look like this:&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;code&amp;gt;app/controllers/posts_controller.rb:17:in `show'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also get the application trace manually at any point through the following command:&lt;br /&gt;
 begin&lt;br /&gt;
  raise object.inspect&lt;br /&gt;
 rescue&lt;br /&gt;
  Rails.logger.warn $!.backtrace.to_yaml&lt;br /&gt;
 end&lt;br /&gt;
This will cause a deliberate error along with an application trace of how you got there.&lt;br /&gt;
&lt;br /&gt;
===Stack Trace===&lt;br /&gt;
Full stack trace shows us the entire stack trace of right when the application started until the problem is encountered. Usually stack traces are very lengthy but they can be very useful to solve problems. Here is a partial stack trace from the back channel application error which we saw before:&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;code&amp;gt;activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:341:in `find_one'&amp;lt;br&amp;gt;&lt;br /&gt;
 activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:312:in `find_with_ids'&amp;lt;br&amp;gt;&lt;br /&gt;
 activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:107:in `find'&amp;lt;br&amp;gt;&lt;br /&gt;
 C:in `find'&amp;lt;br&amp;gt;&lt;br /&gt;
 app/controllers/posts_controller.rb:17:in `show'&amp;lt;br&amp;gt;&lt;br /&gt;
 actionpack (3.2.8) lib/action_controller/metal/implicit_render.rb:4:in `send_action'&amp;lt;br&amp;gt;&lt;br /&gt;
 actionpack (3.2.8) lib/abstract_controller/base.rb:167:in `process_action'&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can see the stack trace right from where the Rails application started, we can see the calls to activerecord. It is unlikely that there would be a problem in those files. As we continue looking into the stack trace we see the find method, we can click on the link in the trace and it will take us to the line in which the error was found. Most often the first few lines of the stack trace will give us the cause behind the error.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Stack trace can be logged using the following lines of code:&lt;br /&gt;
 begin&lt;br /&gt;
  raise&lt;br /&gt;
 rescue =&amp;gt; e&lt;br /&gt;
  logger.error e.message&lt;br /&gt;
  e.backtrace.each { |line| logger.error line }&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===Env Dump and Session Dump===&lt;br /&gt;
Session dump gives all the information of the user's session. This is useful if the error which needs to be fixed is particular to a user or a group of users.&lt;br /&gt;
 &amp;lt;code&amp;gt;_csrf_token: &amp;quot;LiTiqHSVFOr8uT0+pFJhNCFjUc3YikuJy6F77QG+O1Y=&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 comment_id: 1&amp;lt;br&amp;gt;&lt;br /&gt;
 post_id: 1&amp;lt;br&amp;gt;&lt;br /&gt;
 session_id: &amp;quot;c562769a55b39620228ce6064aaa1637&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 user: #&amp;lt;User id: 4, name: &amp;quot;seriously&amp;quot;, username: &amp;quot;seriously&amp;quot;, email: &amp;quot;seriously@seriously.com&amp;quot;,&amp;lt;br&amp;gt; encrypted_password: &amp;quot;cb32e64bd4cb11c7424ea4ea75731450e99ed120d4bab155a42...&amp;quot;, salt: &amp;quot;DlLGMQzwgU&amp;quot;, is_admin: nil,&amp;lt;br&amp;gt; created_at: &amp;quot;2012-11-18 01:08:35&amp;quot;, updated_at: &amp;quot;2012-11-18 01:08:35&amp;quot;&amp;gt;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A session dump can be obtained using the following command:&lt;br /&gt;
 &amp;lt;%= debug session %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Environment dump gives details of the rails runtime environment. If the error is localized to users who use the same version of a host or a protocol, we could find that out using the environment dump.&lt;br /&gt;
 &amp;lt;code&amp;gt;GATEWAY_INTERFACE: &amp;quot;CGI/1.1&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT: &amp;quot;text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_CHARSET: &amp;quot;ISO-8859-1,utf-8;q=0.7,*;q=0.3&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_ENCODING: &amp;quot;gzip,deflate,sdch&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_LANGUAGE: &amp;quot;en-US,en;q=0.8&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 REMOTE_ADDR: &amp;quot;127.0.0.1&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 REMOTE_HOST: &amp;quot;Wayne-PC&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 SERVER_NAME: &amp;quot;localhost&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 SERVER_PROTOCOL: &amp;quot;HTTP/1.1&amp;quot;&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A Very Common Error Message in Ruby===&lt;br /&gt;
&amp;lt;code&amp;gt;undefined method ‘foo’ for nil:NilClass&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Most often, it means that an assignment failed and we didn't check for errors.&amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;code&amp;gt;@m = Movie.find_by_id(id) #could be nil&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When you try to call m.title after an assignment like the one above, it will throw this error.&lt;br /&gt;
&lt;br /&gt;
==Rails Debugger==&lt;br /&gt;
===What is a debugger?===&lt;br /&gt;
Sometimes printing errors to the console or logging is not enough to find out the root cause behind an error message. It is during these times when the debugger is a developer's best friend. The debugger helps us to step forward or backward in the code, execute or skip lines of code, examine the state of a variable or a parameter which has been passed. This will help the developer pinpoint to the actual source of the problem and fix it.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''How to install the debugger?'''&amp;lt;br&amp;gt;&lt;br /&gt;
In Rails, ruby-debug is a gem. We can install it like any other gem. To use the gem in a Rails application we need to add the following line: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;require &amp;quot;ruby-debug&amp;quot;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
in the &amp;lt;code&amp;gt;config/environments/development.rb&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby 1.9, you can use this command to install a compatible version of the debugger gem:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;gem install debugger&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''Running the debugger&amp;lt;br&amp;gt;'''&lt;br /&gt;
To use the debugger in the rails application we need to start the server with the &amp;lt;code&amp;gt;--debugger&amp;lt;/code&amp;gt; option. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;$ rails server --debugger&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we don't do this we would encounter an error like this:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;***** Debugger requested, but was not available: Start server with --debugger to enable *****&amp;lt;/code&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can invoke the debugger from any method by using the &amp;lt;code&amp;gt;debugger&amp;lt;/code&amp;gt; keyword in the method.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class PostsController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    debugger&lt;br /&gt;
    @post = Post.new&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Once the debugger method is called a debugger shell is started inside the terminal window where the application server was launched, and the cursor will be placed at ruby-debug’s prompt &amp;lt;code&amp;gt;(rdb:n)&amp;lt;/code&amp;gt; where n is the thread number. The prompt will show the next line of code which is waiting to run.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Rails is a relatively new platform for web development, it is continually evolving which effectively means debugging is harder. However by leveraging the knowledge of people who have encountered similar errors before we can resolve a subset of problems, the ones particular to versions of ruby and various gems. We have tools like debugger and application trace to help us solve problems which are specific to our application. To know more about using the debugger, please refer to the Further Reading section of the article.&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
# [http://guides.rubyonrails.org/debugging_rails_applications.html Rails Guide - Debugging Rails Applications]&lt;br /&gt;
# [http://www.sitepoint.com/debug-rails-app-ruby-debug/ Debug your rails app with ruby-debug]&lt;br /&gt;
# [http://rubyforge.org/projects/ruby-debug/ Ruby Forge - Documentation for ruby-debug]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# https://www.youtube.com/watch?v=Ee5vfe0mLb8&lt;br /&gt;
# http://railstips.org/blog/archives/2011/08/31/stupid-simple-debugging/&lt;br /&gt;
# http://guides.rubyonrails.org/debugging_rails_applications.html&lt;br /&gt;
# http://railscasts.com/episodes/54-debugging-with-ruby-debug&lt;br /&gt;
# http://bashdb.sourceforge.net/ruby-debug.html&lt;br /&gt;
# http://cheat.errtheblog.com/s/rdebug/&lt;br /&gt;
# http://railscasts.com/episodes/24-the-stack-trace&lt;br /&gt;
# http://www.scribd.com/doc/86869289/3/Rails-Cookery-3&lt;br /&gt;
# http://www.ruby-forum.com/topic/67687&lt;br /&gt;
# http://stackoverflow.com/questions/8408936/rake-dbmigrate-error&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70320</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w-1w65 am</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70320"/>
		<updated>2012-11-18T19:59:18Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* What is a debugger? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This is a wiki article for the material presented in the Coursera SaaS video series, [https://www.youtube.com/watch?v=Ee5vfe0mLb8 3.13 Debugging by Dr. Armando Fox and Dr. David Patterson]. We aim to cover all the material presented in the video with definitions and examples&lt;br /&gt;
===Why debugging in Rails can be tricky?===&lt;br /&gt;
*We are used to printing the error on the terminal in most applications(Example: [http://www.cplusplus.com/reference/clibrary/cstdio/stderr/ STDERR]). This may not be possible for a web application since its primary form of input and output is through HTTP requests and responses.&lt;br /&gt;
&lt;br /&gt;
*Errors early in flow might manifest itself late.&lt;br /&gt;
Consider the following hierarchy seen in a Rails application:&lt;br /&gt;
 URI -&amp;gt; Route -&amp;gt; Controller -&amp;gt; Model -&amp;gt; View -&amp;gt; Renderer&lt;br /&gt;
 &lt;br /&gt;
Here, something that goes wrong in the controller might not manifest itself until the renderer. The root cause of the error might have happened a long time ago.&lt;br /&gt;
&lt;br /&gt;
*Errors can be hard to localize/reproduce if it affects only some users or routes.&lt;br /&gt;
&lt;br /&gt;
There are several approaches that can be used for debugging based on the mode of operation, that is development mode or production mode:&lt;br /&gt;
 &lt;br /&gt;
'''Printing to terminal:'''This is useful for developers, when they are writing code they can print errors to the terminal and then examine them. We cannot use this approach in production mode.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Logging:''' This is a more general approach to debugging which can be used in both modes. The logged entries are permanent record of what the application is doing. The recorded errors are saved in a log file and can be referenced later.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interactive Debugging:''' Using this tool you can stop the application in its tracks and inspect the state of the variables or other parameters to locate the error.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the various approaches and the modes in which they can be used: &amp;lt;br&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Approach !! Development !! Production&lt;br /&gt;
|-&lt;br /&gt;
| Printing to Terminal || ✓ || &lt;br /&gt;
|-&lt;br /&gt;
| Logging || ✓ || ✓&lt;br /&gt;
|-&lt;br /&gt;
| Interactive Debugging || ✓ || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==RASP==&lt;br /&gt;
Steps to follow when faced with an error can be concisely represented by RASP according to Dr. Fox.&lt;br /&gt;
===What is RASP?===&lt;br /&gt;
RASP is an acronym which briefs the steps which a developer could follow if she were facing an error message. It stands for:&lt;br /&gt;
#'''Read''' the error message.&lt;br /&gt;
#'''Ask''' your colleague  &lt;br /&gt;
#'''Search''' using [http://stackoverflow.com/ Stack Overflow] or any other search engine.&lt;br /&gt;
#'''Post''' on [http://stackoverflow.com/ Stack Overflow] or class forum&lt;br /&gt;
&lt;br /&gt;
Reading the error message carefully is the first step in debugging. The error messages in Rails are incredibly detailed and it gives us a lot of information, reading it carefully can help us locate the file and line in which you are facing the error. But what if the line looks alright to you?&amp;lt;br&amp;gt;&lt;br /&gt;
The next step is to ask a colleague an informed question. In case you are doing pair programming, this is a good step to take. The question has to be of the form &amp;quot;I am trying to do this and I expected to get this but I got this other thing instead of foo.&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
If the previous steps fail then searching using stack overflow or Google is next, especially if its an error which is particular to a version of gems or OS.&amp;lt;br&amp;gt;&lt;br /&gt;
In case you don't find a solution to your problem the final step is to get minimal but complete information which reproduces the error message which you are experiencing and post it.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example question and solution from stack overflow:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Ques.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
As we can see the question follows the guidelines explained above. It gives minimal but complete information about the error. It does not give the entire description of the error. It is important to post minimal information so that the person who answers the question can understand your problem quickly.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Ans.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The answer is posted within an hour of posting the question. This shows that posting on stack overflow is a fast way of getting expert help with debugging.&lt;br /&gt;
&lt;br /&gt;
==Understanding Error Messages in Rails==&lt;br /&gt;
Rails usually provides a very verbose description of error messages. Dr. Fox tells us that error messages are our friends, they try to not only show us what went wrong but a great deal of detail of where it went wrong. Let us look at an example error message.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
An error message was deliberately caused by entering a route which wouldn't work. The application which we are using is the backchannel application and we are trying to find a post with id=20 (it doesn't exist). This causes rails to throw the following error  message.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;'''ActiveRecord::RecordNotFound in PostsController#show'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;Couldn't find Post with id=20&amp;lt;br&amp;gt;&lt;br /&gt;
 Rails.root: C:/Users/BruceWayne/Downloads/BackChannelApplication&amp;lt;br&amp;gt;&lt;br /&gt;
 Application Trace | Framework Trace | Full Trace&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''What is the error message trying to tell us?'''&amp;lt;br&amp;gt;&lt;br /&gt;
It tells us that ActiveRecord raised the error, and the error was raised in the show method of the Posts Controller. Rails tried to find a post with id=20 but it failed.&lt;br /&gt;
===Application Trace===&lt;br /&gt;
The application trace will give us the file, line number and the method in which the error was thrown. For the above example the application trace will look like this:&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;code&amp;gt;app/controllers/posts_controller.rb:17:in `show'&amp;lt;/code&amp;gt;&lt;br /&gt;
===Stack Trace===&lt;br /&gt;
Full stack trace shows us the entire stack trace of right when the application started until the problem is encountered. Usually stack traces are very lengthy but they can be very useful to solve problems. Here is a partial stack trace from the back channel application error which we saw before:&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;code&amp;gt;activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:341:in `find_one'&amp;lt;br&amp;gt;&lt;br /&gt;
 activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:312:in `find_with_ids'&amp;lt;br&amp;gt;&lt;br /&gt;
 activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:107:in `find'&amp;lt;br&amp;gt;&lt;br /&gt;
 C:in `find'&amp;lt;br&amp;gt;&lt;br /&gt;
 app/controllers/posts_controller.rb:17:in `show'&amp;lt;br&amp;gt;&lt;br /&gt;
 actionpack (3.2.8) lib/action_controller/metal/implicit_render.rb:4:in `send_action'&amp;lt;br&amp;gt;&lt;br /&gt;
 actionpack (3.2.8) lib/abstract_controller/base.rb:167:in `process_action'&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can see the stack trace right from where the Rails application started, we can see the calls to activerecord. It is unlikely that there would be a problem in those files. As we continue looking into the stack trace we see the find method, we can click on the link in the trace and it will take us to the line in which the error was found. Most often the first few lines of the stack trace will give us the cause behind the error.&lt;br /&gt;
===Env Dump and Session Dump===&lt;br /&gt;
Session dump gives all the information of the user's session. This is useful if the error which needs to be fixed is particular to a user or a group of users.&lt;br /&gt;
 &amp;lt;code&amp;gt;_csrf_token: &amp;quot;LiTiqHSVFOr8uT0+pFJhNCFjUc3YikuJy6F77QG+O1Y=&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 comment_id: 1&amp;lt;br&amp;gt;&lt;br /&gt;
 post_id: 1&amp;lt;br&amp;gt;&lt;br /&gt;
 session_id: &amp;quot;c562769a55b39620228ce6064aaa1637&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 user: #&amp;lt;User id: 4, name: &amp;quot;seriously&amp;quot;, username: &amp;quot;seriously&amp;quot;, email: &amp;quot;seriously@seriously.com&amp;quot;,&amp;lt;br&amp;gt; encrypted_password: &amp;quot;cb32e64bd4cb11c7424ea4ea75731450e99ed120d4bab155a42...&amp;quot;, salt: &amp;quot;DlLGMQzwgU&amp;quot;, is_admin: nil,&amp;lt;br&amp;gt; created_at: &amp;quot;2012-11-18 01:08:35&amp;quot;, updated_at: &amp;quot;2012-11-18 01:08:35&amp;quot;&amp;gt;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Environment dump gives details of the rails runtime environment. If the error is localized to users who use the same version of a host or a protocol, we could find that out using the environment dump.&lt;br /&gt;
 &amp;lt;code&amp;gt;GATEWAY_INTERFACE: &amp;quot;CGI/1.1&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT: &amp;quot;text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_CHARSET: &amp;quot;ISO-8859-1,utf-8;q=0.7,*;q=0.3&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_ENCODING: &amp;quot;gzip,deflate,sdch&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_LANGUAGE: &amp;quot;en-US,en;q=0.8&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 REMOTE_ADDR: &amp;quot;127.0.0.1&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 REMOTE_HOST: &amp;quot;Wayne-PC&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 SERVER_NAME: &amp;quot;localhost&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 SERVER_PROTOCOL: &amp;quot;HTTP/1.1&amp;quot;&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A Very Common Error Message in Ruby===&lt;br /&gt;
&amp;lt;code&amp;gt;undefined method ‘foo’ for nil:NilClass&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Most often, it means that an assignment failed and we didn't check for errors.&amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;code&amp;gt;@m = Movie.find_by_id(id) #could be nil&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When you try to call m.title after an assignment like the one above, it will throw this error.&lt;br /&gt;
&lt;br /&gt;
==Rails Debugger==&lt;br /&gt;
===What is a debugger?===&lt;br /&gt;
Sometimes printing errors to the console or logging is not enough to find out the root cause behind an error message. It is during these times when the debugger is a developer's best friend. The debugger helps us to step forward or backward in the code, execute or skip lines of code, examine the state of a variable or a parameter which has been passed. This will help the developer pinpoint to the actual source of the problem and fix it.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''How to install the debugger?'''&amp;lt;br&amp;gt;&lt;br /&gt;
In Rails, ruby-debug is a gem. We can install it like any other gem. To use the gem in a Rails application we need to add the following line: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;require &amp;quot;ruby-debug&amp;quot;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
in the &amp;lt;code&amp;gt;config/environments/development.rb&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby 1.9, you can use this command to install a compatible version of the debugger gem:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;gem install debugger&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''Running the debugger&amp;lt;br&amp;gt;'''&lt;br /&gt;
To use the debugger in the rails application we need to start the server with the &amp;lt;code&amp;gt;--debugger&amp;lt;/code&amp;gt; option. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;$ rails server --debugger&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we don't do this we would encounter an error like this:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;***** Debugger requested, but was not available: Start server with --debugger to enable *****&amp;lt;/code&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can invoke the debugger from any method by using the &amp;lt;code&amp;gt;debugger&amp;lt;/code&amp;gt; keyword in the method.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class PostsController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    debugger&lt;br /&gt;
    @post = Post.new&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Once the debugger method is called a debugger shell is started inside the terminal window where the application server was launched, and the cursor will be placed at ruby-debug’s prompt &amp;lt;code&amp;gt;(rdb:n)&amp;lt;/code&amp;gt; where n is the thread number. The prompt will show the next line of code which is waiting to run.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Rails is a relatively new platform for development, it is continually evolving which effectively means debugging is harder. However by leveraging the knowledge of people who have encountered similar errors before we can resolve a subset of the problems, the ones particular to versions of ruby and other gems. We have tools like debugger and application trace to help us solve problems which are specific to our application. To know more about using the debugger, please refer to the Further Reading section of the article.&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
# [http://guides.rubyonrails.org/debugging_rails_applications.html Rails Guide - Debugging Rails Applications]&lt;br /&gt;
# [http://www.sitepoint.com/debug-rails-app-ruby-debug/ Debug your rails app with ruby-debug]&lt;br /&gt;
# [http://rubyforge.org/projects/ruby-debug/ Ruby Forge - Documentation for ruby-debug]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# https://www.youtube.com/watch?v=Ee5vfe0mLb8&lt;br /&gt;
# http://railstips.org/blog/archives/2011/08/31/stupid-simple-debugging/&lt;br /&gt;
# http://guides.rubyonrails.org/debugging_rails_applications.html&lt;br /&gt;
# http://railscasts.com/episodes/54-debugging-with-ruby-debug&lt;br /&gt;
# http://bashdb.sourceforge.net/ruby-debug.html&lt;br /&gt;
# http://cheat.errtheblog.com/s/rdebug/&lt;br /&gt;
# http://railscasts.com/episodes/24-the-stack-trace&lt;br /&gt;
# http://www.scribd.com/doc/86869289/3/Rails-Cookery-3&lt;br /&gt;
# http://www.ruby-forum.com/topic/67687&lt;br /&gt;
# http://stackoverflow.com/questions/8408936/rake-dbmigrate-error&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70318</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w-1w65 am</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70318"/>
		<updated>2012-11-18T19:57:53Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This is a wiki article for the material presented in the Coursera SaaS video series, [https://www.youtube.com/watch?v=Ee5vfe0mLb8 3.13 Debugging by Dr. Armando Fox and Dr. David Patterson]. We aim to cover all the material presented in the video with definitions and examples&lt;br /&gt;
===Why debugging in Rails can be tricky?===&lt;br /&gt;
*We are used to printing the error on the terminal in most applications(Example: [http://www.cplusplus.com/reference/clibrary/cstdio/stderr/ STDERR]). This may not be possible for a web application since its primary form of input and output is through HTTP requests and responses.&lt;br /&gt;
&lt;br /&gt;
*Errors early in flow might manifest itself late.&lt;br /&gt;
Consider the following hierarchy seen in a Rails application:&lt;br /&gt;
 URI -&amp;gt; Route -&amp;gt; Controller -&amp;gt; Model -&amp;gt; View -&amp;gt; Renderer&lt;br /&gt;
 &lt;br /&gt;
Here, something that goes wrong in the controller might not manifest itself until the renderer. The root cause of the error might have happened a long time ago.&lt;br /&gt;
&lt;br /&gt;
*Errors can be hard to localize/reproduce if it affects only some users or routes.&lt;br /&gt;
&lt;br /&gt;
There are several approaches that can be used for debugging based on the mode of operation, that is development mode or production mode:&lt;br /&gt;
 &lt;br /&gt;
'''Printing to terminal:'''This is useful for developers, when they are writing code they can print errors to the terminal and then examine them. We cannot use this approach in production mode.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Logging:''' This is a more general approach to debugging which can be used in both modes. The logged entries are permanent record of what the application is doing. The recorded errors are saved in a log file and can be referenced later.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interactive Debugging:''' Using this tool you can stop the application in its tracks and inspect the state of the variables or other parameters to locate the error.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the various approaches and the modes in which they can be used: &amp;lt;br&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Approach !! Development !! Production&lt;br /&gt;
|-&lt;br /&gt;
| Printing to Terminal || ✓ || &lt;br /&gt;
|-&lt;br /&gt;
| Logging || ✓ || ✓&lt;br /&gt;
|-&lt;br /&gt;
| Interactive Debugging || ✓ || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==RASP==&lt;br /&gt;
Steps to follow when faced with an error can be concisely represented by RASP according to Dr. Fox.&lt;br /&gt;
===What is RASP?===&lt;br /&gt;
RASP is an acronym which briefs the steps which a developer could follow if she were facing an error message. It stands for:&lt;br /&gt;
#'''Read''' the error message.&lt;br /&gt;
#'''Ask''' your colleague  &lt;br /&gt;
#'''Search''' using [http://stackoverflow.com/ Stack Overflow] or any other search engine.&lt;br /&gt;
#'''Post''' on [http://stackoverflow.com/ Stack Overflow] or class forum&lt;br /&gt;
&lt;br /&gt;
Reading the error message carefully is the first step in debugging. The error messages in Rails are incredibly detailed and it gives us a lot of information, reading it carefully can help us locate the file and line in which you are facing the error. But what if the line looks alright to you?&amp;lt;br&amp;gt;&lt;br /&gt;
The next step is to ask a colleague an informed question. In case you are doing pair programming, this is a good step to take. The question has to be of the form &amp;quot;I am trying to do this and I expected to get this but I got this other thing instead of foo.&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
If the previous steps fail then searching using stack overflow or Google is next, especially if its an error which is particular to a version of gems or OS.&amp;lt;br&amp;gt;&lt;br /&gt;
In case you don't find a solution to your problem the final step is to get minimal but complete information which reproduces the error message which you are experiencing and post it.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example question and solution from stack overflow:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Ques.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
As we can see the question follows the guidelines explained above. It gives minimal but complete information about the error. It does not give the entire description of the error. It is important to post minimal information so that the person who answers the question can understand your problem quickly.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Ans.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The answer is posted within an hour of posting the question. This shows that posting on stack overflow is a fast way of getting expert help with debugging.&lt;br /&gt;
&lt;br /&gt;
==Understanding Error Messages in Rails==&lt;br /&gt;
Rails usually provides a very verbose description of error messages. Dr. Fox tells us that error messages are our friends, they try to not only show us what went wrong but a great deal of detail of where it went wrong. Let us look at an example error message.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
An error message was deliberately caused by entering a route which wouldn't work. The application which we are using is the backchannel application and we are trying to find a post with id=20 (it doesn't exist). This causes rails to throw the following error  message.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;'''ActiveRecord::RecordNotFound in PostsController#show'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;Couldn't find Post with id=20&amp;lt;br&amp;gt;&lt;br /&gt;
 Rails.root: C:/Users/BruceWayne/Downloads/BackChannelApplication&amp;lt;br&amp;gt;&lt;br /&gt;
 Application Trace | Framework Trace | Full Trace&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''What is the error message trying to tell us?'''&amp;lt;br&amp;gt;&lt;br /&gt;
It tells us that ActiveRecord raised the error, and the error was raised in the show method of the Posts Controller. Rails tried to find a post with id=20 but it failed.&lt;br /&gt;
===Application Trace===&lt;br /&gt;
The application trace will give us the file, line number and the method in which the error was thrown. For the above example the application trace will look like this:&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;code&amp;gt;app/controllers/posts_controller.rb:17:in `show'&amp;lt;/code&amp;gt;&lt;br /&gt;
===Stack Trace===&lt;br /&gt;
Full stack trace shows us the entire stack trace of right when the application started until the problem is encountered. Usually stack traces are very lengthy but they can be very useful to solve problems. Here is a partial stack trace from the back channel application error which we saw before:&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;code&amp;gt;activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:341:in `find_one'&amp;lt;br&amp;gt;&lt;br /&gt;
 activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:312:in `find_with_ids'&amp;lt;br&amp;gt;&lt;br /&gt;
 activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:107:in `find'&amp;lt;br&amp;gt;&lt;br /&gt;
 C:in `find'&amp;lt;br&amp;gt;&lt;br /&gt;
 app/controllers/posts_controller.rb:17:in `show'&amp;lt;br&amp;gt;&lt;br /&gt;
 actionpack (3.2.8) lib/action_controller/metal/implicit_render.rb:4:in `send_action'&amp;lt;br&amp;gt;&lt;br /&gt;
 actionpack (3.2.8) lib/abstract_controller/base.rb:167:in `process_action'&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can see the stack trace right from where the Rails application started, we can see the calls to activerecord. It is unlikely that there would be a problem in those files. As we continue looking into the stack trace we see the find method, we can click on the link in the trace and it will take us to the line in which the error was found. Most often the first few lines of the stack trace will give us the cause behind the error.&lt;br /&gt;
===Env Dump and Session Dump===&lt;br /&gt;
Session dump gives all the information of the user's session. This is useful if the error which needs to be fixed is particular to a user or a group of users.&lt;br /&gt;
 &amp;lt;code&amp;gt;_csrf_token: &amp;quot;LiTiqHSVFOr8uT0+pFJhNCFjUc3YikuJy6F77QG+O1Y=&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 comment_id: 1&amp;lt;br&amp;gt;&lt;br /&gt;
 post_id: 1&amp;lt;br&amp;gt;&lt;br /&gt;
 session_id: &amp;quot;c562769a55b39620228ce6064aaa1637&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 user: #&amp;lt;User id: 4, name: &amp;quot;seriously&amp;quot;, username: &amp;quot;seriously&amp;quot;, email: &amp;quot;seriously@seriously.com&amp;quot;,&amp;lt;br&amp;gt; encrypted_password: &amp;quot;cb32e64bd4cb11c7424ea4ea75731450e99ed120d4bab155a42...&amp;quot;, salt: &amp;quot;DlLGMQzwgU&amp;quot;, is_admin: nil,&amp;lt;br&amp;gt; created_at: &amp;quot;2012-11-18 01:08:35&amp;quot;, updated_at: &amp;quot;2012-11-18 01:08:35&amp;quot;&amp;gt;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Environment dump gives details of the rails runtime environment. If the error is localized to users who use the same version of a host or a protocol, we could find that out using the environment dump.&lt;br /&gt;
 &amp;lt;code&amp;gt;GATEWAY_INTERFACE: &amp;quot;CGI/1.1&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT: &amp;quot;text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_CHARSET: &amp;quot;ISO-8859-1,utf-8;q=0.7,*;q=0.3&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_ENCODING: &amp;quot;gzip,deflate,sdch&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_LANGUAGE: &amp;quot;en-US,en;q=0.8&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 REMOTE_ADDR: &amp;quot;127.0.0.1&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 REMOTE_HOST: &amp;quot;Wayne-PC&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 SERVER_NAME: &amp;quot;localhost&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 SERVER_PROTOCOL: &amp;quot;HTTP/1.1&amp;quot;&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A Very Common Error Message in Ruby===&lt;br /&gt;
&amp;lt;code&amp;gt;undefined method ‘foo’ for nil:NilClass&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Most often, it means that an assignment failed and we didn't check for errors.&amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;code&amp;gt;@m = Movie.find_by_id(id) #could be nil&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When you try to call m.title after an assignment like the one above, it will throw this error.&lt;br /&gt;
&lt;br /&gt;
==Rails Debugger==&lt;br /&gt;
===What is a debugger?===&lt;br /&gt;
Sometimes printing errors to the console or logging is not enough to find out the root cause behind an error message. It is during these times when the debugger is a developer's best friend. The debugger helps us to step forward or backward in the code, execute or skip lines of code, examine the state of a variable or a parameter which has been passed. This will help the developer pinpoint to the actual source of the problem and fix it.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''How to install the debugger?'''&amp;lt;br&amp;gt;&lt;br /&gt;
In Rails, ruby-debug is a gem. We can install it like any other gem. To use the gem in a Rails application we need to add the following line: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;require &amp;quot;ruby-debug&amp;quot;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
in the &amp;lt;code&amp;gt;config/environments/development.rb&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby 1.9, you can use this command to install a compatible version of the debugger gem:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;gem install debugger&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''Running the debugger&amp;lt;br&amp;gt;'''&lt;br /&gt;
To use the debugger in the rails application we need to start the server with the &amp;lt;code&amp;gt;--debugger&amp;lt;/code&amp;gt; option. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;$ rails server --debugger&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we don't do this we would encounter an error like this:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;***** Debugger requested, but was not available: Start server with --debugger to enable *****&amp;lt;/code&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can invoke the debugger from any method by using the &amp;lt;code&amp;gt;debugger&amp;lt;/code&amp;gt; keyword in the method.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class PostController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    debugger&lt;br /&gt;
    @post = Post.new&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Once the debugger method is called a debugger shell is started inside the terminal window where the application server was launched, and the cursor will be placed at ruby-debug’s prompt &amp;lt;code&amp;gt;(rdb:n)&amp;lt;/code&amp;gt; where n is the thread number. The prompt will show the next line of code which is waiting to run.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Rails is a relatively new platform for development, it is continually evolving which effectively means debugging is harder. However by leveraging the knowledge of people who have encountered similar errors before we can resolve a subset of the problems, the ones particular to versions of ruby and other gems. We have tools like debugger and application trace to help us solve problems which are specific to our application. To know more about using the debugger, please refer to the Further Reading section of the article.&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
# [http://guides.rubyonrails.org/debugging_rails_applications.html Rails Guide - Debugging Rails Applications]&lt;br /&gt;
# [http://www.sitepoint.com/debug-rails-app-ruby-debug/ Debug your rails app with ruby-debug]&lt;br /&gt;
# [http://rubyforge.org/projects/ruby-debug/ Ruby Forge - Documentation for ruby-debug]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# https://www.youtube.com/watch?v=Ee5vfe0mLb8&lt;br /&gt;
# http://railstips.org/blog/archives/2011/08/31/stupid-simple-debugging/&lt;br /&gt;
# http://guides.rubyonrails.org/debugging_rails_applications.html&lt;br /&gt;
# http://railscasts.com/episodes/54-debugging-with-ruby-debug&lt;br /&gt;
# http://bashdb.sourceforge.net/ruby-debug.html&lt;br /&gt;
# http://cheat.errtheblog.com/s/rdebug/&lt;br /&gt;
# http://railscasts.com/episodes/24-the-stack-trace&lt;br /&gt;
# http://www.scribd.com/doc/86869289/3/Rails-Cookery-3&lt;br /&gt;
# http://www.ruby-forum.com/topic/67687&lt;br /&gt;
# http://stackoverflow.com/questions/8408936/rake-dbmigrate-error&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70317</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w-1w65 am</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70317"/>
		<updated>2012-11-18T19:57:03Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This is a wiki article for the material presented in the Coursera SaaS video series, [https://www.youtube.com/watch?v=Ee5vfe0mLb8 3.13 Debugging by Dr. Armando Fox and Dr. David Patterson]. We aim to cover all the material presented in the video with definitions and examples&lt;br /&gt;
===Why debugging in Rails can be tricky?===&lt;br /&gt;
*We are used to printing the error on the terminal in most applications(Example: [http://www.cplusplus.com/reference/clibrary/cstdio/stderr/ STDERR]). This may not be possible for a web application since its primary form of input and output is through HTTP requests and responses.&lt;br /&gt;
&lt;br /&gt;
*Errors early in flow might manifest itself late.&lt;br /&gt;
Consider the following hierarchy seen in a Rails application:&lt;br /&gt;
 URI -&amp;gt; Route -&amp;gt; Controller -&amp;gt; Model -&amp;gt; View -&amp;gt; Renderer&lt;br /&gt;
 &lt;br /&gt;
Here, something that goes wrong in the controller might not manifest itself until the renderer. The root cause of the error might have happened a long time ago.&lt;br /&gt;
&lt;br /&gt;
*Errors can be hard to localize/reproduce if it affects only some users or routes.&lt;br /&gt;
&lt;br /&gt;
There are several approaches that can be used for debugging based on the mode of operation, that is development mode or production mode:&lt;br /&gt;
 &lt;br /&gt;
'''Printing to terminal:'''This is useful for developers, when they are writing code they can print errors to the terminal and then examine them. We cannot use this approach in production mode.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Logging:''' This is a more general approach to debugging which can be used in both modes. The logged entries are permanent record of what the application is doing. The recorded errors are saved in a log file and can be referenced later.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interactive Debugging:''' Using this tool you can stop the application in its tracks and inspect the state of the variables or other parameters to locate the error.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the various approaches and the modes in which they can be used: &amp;lt;br&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Approach !! Development !! Production&lt;br /&gt;
|-&lt;br /&gt;
| Printing to Terminal || ✓ || &lt;br /&gt;
|-&lt;br /&gt;
| Logging || ✓ || ✓&lt;br /&gt;
|-&lt;br /&gt;
| Interactive Debugging || ✓ || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==RASP==&lt;br /&gt;
Steps to follow when faced with an error can be concisely represented by RASP according to Dr. Fox.&lt;br /&gt;
===What is RASP?===&lt;br /&gt;
RASP is an acronym which briefs the steps which a developer could follow if she were facing an error message. It stands for:&lt;br /&gt;
#'''Read''' the error message.&lt;br /&gt;
#'''Ask''' your colleague  &lt;br /&gt;
#'''Search''' using [http://stackoverflow.com/ Stack Overflow] or any other search engine.&lt;br /&gt;
#'''Post''' on [http://stackoverflow.com/ Stack Overflow] or class forum&lt;br /&gt;
&lt;br /&gt;
Reading the error message carefully is the first step in debugging. The error messages in Rails are incredibly detailed and it gives us a lot of information, reading it carefully can help us locate the file and line in which you are facing the error. But what if the line looks alright to you?&amp;lt;br&amp;gt;&lt;br /&gt;
The next step is to ask a colleague an informed question. In case you are doing pair programming, this is a good step to take. The question has to be of the form &amp;quot;I am trying to do this and I expected to get this but I got this other thing instead of foo.&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
If the previous steps fail then searching using stack overflow or Google is next, especially if its an error which is particular to a version of gems or OS.&amp;lt;br&amp;gt;&lt;br /&gt;
In case you don't find a solution to your problem the final step is to get minimal but complete information which reproduces the error message which you are experiencing and post it.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example question and solution from stack overflow:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Ques.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
As we can see the question follows the guidelines explained above. It gives minimal but complete information about the error. It does not give the entire description of the error. It is important to post minimal information so that the person who answers the question can understand your problem quickly.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Ans.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The answer is posted within an hour of posting the question. This shows that posting on stack overflow is a fast way of getting expert help with debugging.&lt;br /&gt;
&lt;br /&gt;
==Understanding Error Messages in Rails==&lt;br /&gt;
Rails usually provides a very verbose description of error messages. Dr. Fox tells us that error messages are our friends, they try to not only show us what went wrong but a great deal of detail of where it went wrong. Let us look at an example error message.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
An error message was deliberately caused by entering a route which wouldn't work. The application which we are using is the backchannel application and we are trying to find a post with id=20 (it doesn't exist). This causes rails to throw the following error  message.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;'''ActiveRecord::RecordNotFound in PostsController#show'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;Couldn't find Post with id=20&amp;lt;br&amp;gt;&lt;br /&gt;
 Rails.root: C:/Users/BruceWayne/Downloads/BackChannelApplication&amp;lt;br&amp;gt;&lt;br /&gt;
 Application Trace | Framework Trace | Full Trace&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''What is the error message trying to tell us?'''&amp;lt;br&amp;gt;&lt;br /&gt;
It tells us that ActiveRecord raised the error, and the error was raised in the show method of the Posts Controller. Rails tried to find a post with id=20 but it failed.&lt;br /&gt;
===Application Trace===&lt;br /&gt;
The application trace will give us the file, line number and the method in which the error was thrown. For the above example the application trace will look like this:&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;code&amp;gt;app/controllers/posts_controller.rb:17:in `show'&amp;lt;/code&amp;gt;&lt;br /&gt;
===Stack Trace===&lt;br /&gt;
Full stack trace shows us the entire stack trace of right when the application started until the problem is encountered. Usually stack traces are very lengthy but they can be very useful to solve problems. Here is a partial stack trace from the back channel application error which we saw before:&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;code&amp;gt;activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:341:in `find_one'&amp;lt;br&amp;gt;&lt;br /&gt;
 activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:312:in `find_with_ids'&amp;lt;br&amp;gt;&lt;br /&gt;
 activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:107:in `find'&amp;lt;br&amp;gt;&lt;br /&gt;
 C:in `find'&amp;lt;br&amp;gt;&lt;br /&gt;
 app/controllers/posts_controller.rb:17:in `show'&amp;lt;br&amp;gt;&lt;br /&gt;
 actionpack (3.2.8) lib/action_controller/metal/implicit_render.rb:4:in `send_action'&amp;lt;br&amp;gt;&lt;br /&gt;
 actionpack (3.2.8) lib/abstract_controller/base.rb:167:in `process_action'&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can see the stack trace right from where the Rails application started, we can see the calls to activerecord. It is unlikely that there would be a problem in those files. As we continue looking into the stack trace we see the find method, we can click on the link in the trace and it will take us to the line in which the error was found. Most often the first few lines of the stack trace will give us the cause behind the error.&lt;br /&gt;
===Env Dump and Session Dump===&lt;br /&gt;
Session dump gives all the information of the user's session. This is useful if the error which needs to be fixed is particular to a user or a group of users.&lt;br /&gt;
 &amp;lt;code&amp;gt;_csrf_token: &amp;quot;LiTiqHSVFOr8uT0+pFJhNCFjUc3YikuJy6F77QG+O1Y=&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 comment_id: 1&amp;lt;br&amp;gt;&lt;br /&gt;
 post_id: 1&amp;lt;br&amp;gt;&lt;br /&gt;
 session_id: &amp;quot;c562769a55b39620228ce6064aaa1637&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 user: #&amp;lt;User id: 4, name: &amp;quot;seriously&amp;quot;, username: &amp;quot;seriously&amp;quot;, email: &amp;quot;seriously@seriously.com&amp;quot;,&amp;lt;br&amp;gt; encrypted_password: &amp;quot;cb32e64bd4cb11c7424ea4ea75731450e99ed120d4bab155a42...&amp;quot;, salt: &amp;quot;DlLGMQzwgU&amp;quot;, is_admin: nil,&amp;lt;br&amp;gt; created_at: &amp;quot;2012-11-18 01:08:35&amp;quot;, updated_at: &amp;quot;2012-11-18 01:08:35&amp;quot;&amp;gt;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Environment dump gives details of the rails runtime environment. If the error is localized to users who use the same version of a host or a protocol, we could find that out using the environment dump.&lt;br /&gt;
 &amp;lt;code&amp;gt;GATEWAY_INTERFACE: &amp;quot;CGI/1.1&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT: &amp;quot;text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_CHARSET: &amp;quot;ISO-8859-1,utf-8;q=0.7,*;q=0.3&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_ENCODING: &amp;quot;gzip,deflate,sdch&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_LANGUAGE: &amp;quot;en-US,en;q=0.8&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 REMOTE_ADDR: &amp;quot;127.0.0.1&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 REMOTE_HOST: &amp;quot;Wayne-PC&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 SERVER_NAME: &amp;quot;localhost&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 SERVER_PROTOCOL: &amp;quot;HTTP/1.1&amp;quot;&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A Very Common Error Message in Ruby===&lt;br /&gt;
&amp;lt;code&amp;gt;undefined method ‘foo’ for nil:NilClass&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Most often, it means that an assignment failed and we didn't check for errors.&amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;code&amp;gt;@m = Movie.find_by_id(id) #could be nil&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When you try to call m.title after an assignment like the one above, it will throw this error.&lt;br /&gt;
&lt;br /&gt;
==Rails Debugger==&lt;br /&gt;
===What is a debugger?===&lt;br /&gt;
Sometimes printing errors to the console or logging is not enough to find out the root cause behind an error message. It is during these times when the debugger is a developer's best friend. The debugger helps us to step forward or backward in the code, execute or skip lines of code, examine the state of a variable or a parameter which has been passed. This will help the developer pinpoint to the actual source of the problem and fix it.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''How to install the debugger?'''&amp;lt;br&amp;gt;&lt;br /&gt;
In Rails, ruby-debug is a gem. We can install it like any other gem. To use the gem in a Rails application we need to add the following line: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;require &amp;quot;ruby-debug&amp;quot;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
in the &amp;lt;code&amp;gt;config/environments/development.rb&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby 1.9, you can use this command to install a compatible version of the debugger gem:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;gem install debugger&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''Running the debugger&amp;lt;br&amp;gt;'''&lt;br /&gt;
To use the debugger in the rails application we need to start the server with the &amp;lt;code&amp;gt;--debugger&amp;lt;/code&amp;gt; option. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;$ rails server --debugger&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we don't do this we would encounter an error like this:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;***** Debugger requested, but was not available: Start server with --debugger to enable *****&amp;lt;/code&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can invoke the debugger from any method by using the &amp;lt;code&amp;gt;debugger&amp;lt;/code&amp;gt; keyword in the method.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class PostController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    debugger&lt;br /&gt;
    @post = Post.new&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Once the debugger method is called a debugger shell is started inside the terminal window where the application server was launched, and the cursor will be placed at ruby-debug’s prompt &amp;lt;code&amp;gt;(rdb:n)&amp;lt;/code&amp;gt; where n is the thread number. The prompt will show the next line of code which is waiting to run.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Rails is a relatively new platform for development, it is continually evolving which effectively means debugging is harder. However by leveraging the knowledge of people who have encountered similar errors before we can resolve a subset of the problems, the ones particular to versions of ruby and other gems. We have tools like debugger and application trace to help us solve problems which are specific to our application. To know more about using the debugger, please refer to the Further Reading section of the article.&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
# [http://guides.rubyonrails.org/debugging_rails_applications.html Rails Guide - Debugging Rails Applications]&lt;br /&gt;
# [http://www.sitepoint.com/debug-rails-app-ruby-debug/ Debug your rails app with ruby-debug]&lt;br /&gt;
# [http://rubyforge.org/projects/ruby-debug/ Ruby Forge - Documentation for ruby-debug]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# https://www.youtube.com/watch?v=Ee5vfe0mLb8&lt;br /&gt;
# http://railstips.org/blog/archives/2011/08/31/stupid-simple-debugging/&lt;br /&gt;
# http://guides.rubyonrails.org/debugging_rails_applications.html&lt;br /&gt;
# http://railscasts.com/episodes/54-debugging-with-ruby-debug&lt;br /&gt;
# http://bashdb.sourceforge.net/ruby-debug.html&lt;br /&gt;
# http://cheat.errtheblog.com/s/rdebug/&lt;br /&gt;
# http://railscasts.com/episodes/24-the-stack-trace&lt;br /&gt;
# http://www.scribd.com/doc/86869289/3/Rails-Cookery-3&lt;br /&gt;
# http://www.ruby-forum.com/topic/67687&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70316</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w-1w65 am</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70316"/>
		<updated>2012-11-18T19:53:58Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* A Very Common Error Message in Ruby */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This is a wiki article for the material presented in the Coursera SaaS video series, [https://www.youtube.com/watch?v=Ee5vfe0mLb8 3.13 Debugging by Dr. Armando Fox and Dr. David Patterson]. We aim to cover all the material presented in the video with definitions and examples&lt;br /&gt;
===Why debugging in Rails can be tricky?===&lt;br /&gt;
*We are used to printing the error on the terminal in most applications(Example: [http://www.cplusplus.com/reference/clibrary/cstdio/stderr/ STDERR]). This may not be possible for a web application since its primary form of input and output is through HTTP requests and responses.&lt;br /&gt;
&lt;br /&gt;
*Errors early in flow might manifest itself late.&lt;br /&gt;
Consider the following hierarchy seen in a Rails application:&lt;br /&gt;
 URI -&amp;gt; Route -&amp;gt; Controller -&amp;gt; Model -&amp;gt; View -&amp;gt; Renderer&lt;br /&gt;
 &lt;br /&gt;
Here, something that goes wrong in the controller might not manifest itself until the renderer. The root cause of the error might have happened a long time ago.&lt;br /&gt;
&lt;br /&gt;
*Errors can be hard to localize/reproduce if it affects only some users or routes.&lt;br /&gt;
&lt;br /&gt;
There are several approaches that can be used for debugging based on the mode of operation, that is development mode or production mode:&lt;br /&gt;
 &lt;br /&gt;
'''Printing to terminal:'''This is useful for developers, when they are writing code they can print errors to the terminal and then examine them. We cannot use this approach in production mode.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Logging:''' This is a more general approach to debugging which can be used in both modes. The logged entries are permanent record of what the application is doing. The recorded errors are saved in a log file and can be referenced later.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interactive Debugging:''' Using this tool you can stop the application in its tracks and inspect the state of the variables or other parameters to locate the error.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the various approaches and the modes in which they can be used: &amp;lt;br&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Approach !! Development !! Production&lt;br /&gt;
|-&lt;br /&gt;
| Printing to Terminal || ✓ || &lt;br /&gt;
|-&lt;br /&gt;
| Logging || ✓ || ✓&lt;br /&gt;
|-&lt;br /&gt;
| Interactive Debugging || ✓ || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==RASP==&lt;br /&gt;
Steps to follow when faced with an error can be concisely represented by RASP according to Dr. Fox.&lt;br /&gt;
===What is RASP?===&lt;br /&gt;
RASP is an acronym which briefs the steps which a developer could follow if she were facing an error message. It stands for:&lt;br /&gt;
#'''Read''' the error message.&lt;br /&gt;
#'''Ask''' your colleague  &lt;br /&gt;
#'''Search''' using [http://stackoverflow.com/ Stack Overflow] or any other search engine.&lt;br /&gt;
#'''Post''' on [http://stackoverflow.com/ Stack Overflow] or class forum&lt;br /&gt;
&lt;br /&gt;
Reading the error message carefully is the first step in debugging. The error messages in Rails are incredibly detailed and it gives us a lot of information, reading it carefully can help us locate the file and line in which you are facing the error. But what if the line looks alright to you?&amp;lt;br&amp;gt;&lt;br /&gt;
The next step is to ask a colleague an informed question. In case you are doing pair programming, this is a good step to take. The question has to be of the form &amp;quot;I am trying to do this and I expected to get this but I got this other thing instead of foo.&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
If the previous steps fail then searching using stack overflow or Google is next, especially if its an error which is particular to a version of gems or OS.&amp;lt;br&amp;gt;&lt;br /&gt;
In case you don't find a solution to your problem the final step is to get minimal but complete information which reproduces the error message which you are experiencing and post it.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example question and solution from stack overflow:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Ques.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
As we can see the question follows the guidelines explained above. It gives minimal but complete information about the error. It does not give the entire description of the error. It is important to post minimal information so that the person who answers the question can understand your problem quickly.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Ans.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The answer is posted within an hour of posting the question. This shows that posting on stack overflow is a fast way of getting expert help with debugging.&lt;br /&gt;
&lt;br /&gt;
==Understanding Error Messages in Rails==&lt;br /&gt;
Rails usually provides a very verbose description of error messages. Dr. Fox tells us that error messages are our friends, they try to not only show us what went wrong but a great deal of detail of where it went wrong. Let us look at an example error message.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
An error message was deliberately caused by entering a route which wouldn't work. The application which we are using is the backchannel application and we are trying to find a post with id=20 (it doesn't exist). This causes rails to throw the following error  message.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;'''ActiveRecord::RecordNotFound in PostsController#show'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;Couldn't find Post with id=20&amp;lt;br&amp;gt;&lt;br /&gt;
 Rails.root: C:/Users/BruceWayne/Downloads/BackChannelApplication&amp;lt;br&amp;gt;&lt;br /&gt;
 Application Trace | Framework Trace | Full Trace&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''What is the error message trying to tell us?'''&amp;lt;br&amp;gt;&lt;br /&gt;
It tells us that ActiveRecord raised the error, and the error was raised in the show method of the Posts Controller. Rails tried to find a post with id=20 but it failed.&lt;br /&gt;
===Application Trace===&lt;br /&gt;
The application trace will give us the file, line number and the method in which the error was thrown. For the above example the application trace will look like this:&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;code&amp;gt;app/controllers/posts_controller.rb:17:in `show'&amp;lt;/code&amp;gt;&lt;br /&gt;
===Stack Trace===&lt;br /&gt;
Full stack trace shows us the entire stack trace of right when the application started until the problem is encountered. Usually stack traces are very lengthy but they can be very useful to solve problems. Here is a partial stack trace from the back channel application error which we saw before:&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;code&amp;gt;activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:341:in `find_one'&amp;lt;br&amp;gt;&lt;br /&gt;
 activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:312:in `find_with_ids'&amp;lt;br&amp;gt;&lt;br /&gt;
 activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:107:in `find'&amp;lt;br&amp;gt;&lt;br /&gt;
 C:in `find'&amp;lt;br&amp;gt;&lt;br /&gt;
 app/controllers/posts_controller.rb:17:in `show'&amp;lt;br&amp;gt;&lt;br /&gt;
 actionpack (3.2.8) lib/action_controller/metal/implicit_render.rb:4:in `send_action'&amp;lt;br&amp;gt;&lt;br /&gt;
 actionpack (3.2.8) lib/abstract_controller/base.rb:167:in `process_action'&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can see the stack trace right from where the Rails application started, we can see the calls to activerecord. It is unlikely that there would be a problem in those files. As we continue looking into the stack trace we see the find method, we can click on the link in the trace and it will take us to the line in which the error was found. Most often the first few lines of the stack trace will give us the cause behind the error.&lt;br /&gt;
===Env Dump and Session Dump===&lt;br /&gt;
Session dump gives all the information of the user's session. This is useful if the error which needs to be fixed is particular to a user or a group of users.&lt;br /&gt;
 &amp;lt;code&amp;gt;_csrf_token: &amp;quot;LiTiqHSVFOr8uT0+pFJhNCFjUc3YikuJy6F77QG+O1Y=&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 comment_id: 1&amp;lt;br&amp;gt;&lt;br /&gt;
 post_id: 1&amp;lt;br&amp;gt;&lt;br /&gt;
 session_id: &amp;quot;c562769a55b39620228ce6064aaa1637&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 user: #&amp;lt;User id: 4, name: &amp;quot;seriously&amp;quot;, username: &amp;quot;seriously&amp;quot;, email: &amp;quot;seriously@seriously.com&amp;quot;,&amp;lt;br&amp;gt; encrypted_password: &amp;quot;cb32e64bd4cb11c7424ea4ea75731450e99ed120d4bab155a42...&amp;quot;, salt: &amp;quot;DlLGMQzwgU&amp;quot;, is_admin: nil,&amp;lt;br&amp;gt; created_at: &amp;quot;2012-11-18 01:08:35&amp;quot;, updated_at: &amp;quot;2012-11-18 01:08:35&amp;quot;&amp;gt;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Environment dump gives details of the rails runtime environment. If the error is localized to users who use the same version of a host or a protocol, we could find that out using the environment dump.&lt;br /&gt;
 &amp;lt;code&amp;gt;GATEWAY_INTERFACE: &amp;quot;CGI/1.1&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT: &amp;quot;text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_CHARSET: &amp;quot;ISO-8859-1,utf-8;q=0.7,*;q=0.3&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_ENCODING: &amp;quot;gzip,deflate,sdch&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_LANGUAGE: &amp;quot;en-US,en;q=0.8&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 REMOTE_ADDR: &amp;quot;127.0.0.1&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 REMOTE_HOST: &amp;quot;Wayne-PC&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 SERVER_NAME: &amp;quot;localhost&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 SERVER_PROTOCOL: &amp;quot;HTTP/1.1&amp;quot;&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A Very Common Error Message in Ruby===&lt;br /&gt;
&amp;lt;code&amp;gt;undefined method ‘foo’ for nil:NilClass&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Most often, it means that an assignment failed and we didn't check for errors.&amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;code&amp;gt;@m = Movie.find_by_id(id) #could be nil&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When you try to call m.title after an assignment like the one above, it will throw this error.&lt;br /&gt;
&lt;br /&gt;
==Rails Debugger==&lt;br /&gt;
===What is a debugger?===&lt;br /&gt;
Sometimes printing errors to the console or logging is not enough to find out the root cause behind an error message. It is during these times when the debugger is a developer's best friend. The debugger helps us to step forward or backward in the code, execute or skip lines of code, examine the state of a variable or a parameter which has been passed. This will help the developer pinpoint to the actual source of the problem and fix it.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''How to install the debugger?'''&amp;lt;br&amp;gt;&lt;br /&gt;
In Rails, ruby-debug is a gem. We can install it like any other gem. To use the gem in a Rails application we need to add the following line: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;require &amp;quot;ruby-debug&amp;quot;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
in the &amp;lt;code&amp;gt;config/environments/development.rb&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby 1.9, you can use this command to install a compatible version of the debugger gem:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;gem install debugger&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''Running the debugger&amp;lt;br&amp;gt;'''&lt;br /&gt;
To use the debugger in the rails application we need to start the server with the &amp;lt;code&amp;gt;--debugger&amp;lt;/code&amp;gt; option. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;$ rails server --debugger&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we don't do this we would encounter an error like this:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;***** Debugger requested, but was not available: Start server with --debugger to enable *****&amp;lt;/code&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can invoke the debugger from any method by using the &amp;lt;code&amp;gt;debugger&amp;lt;/code&amp;gt; keyword in the method.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class PostController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    debugger&lt;br /&gt;
    @post = Post.new&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Once the debugger method is called a debugger shell is started inside the terminal window where the application server was launched, and the cursor will be placed at ruby-debug’s prompt &amp;lt;code&amp;gt;(rdb:n)&amp;lt;/code&amp;gt; where n is the thread number. The prompt will show the next line of code which is waiting to run.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Rails is a relatively new platform for development, it is continually evolving which effectively means debugging is harder. However by leveraging the knowledge of people who have encountered similar errors before we can resolve a subset of the problems, the ones particular to versions of ruby and other gems. We have tools like debugger and application trace to help us solve problems which are specific to our application. To know more about using the debugger, please refer to the Further Reading section of the article.&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
# [http://guides.rubyonrails.org/debugging_rails_applications.html Rails Guide - Debugging Rails Applications]&lt;br /&gt;
# [http://www.sitepoint.com/debug-rails-app-ruby-debug/ Debug your rails app with ruby-debug]&lt;br /&gt;
# [http://rubyforge.org/projects/ruby-debug/ Ruby Forge - Documentation for ruby-debug]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
https://www.youtube.com/watch?v=Ee5vfe0mLb8&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70314</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w-1w65 am</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70314"/>
		<updated>2012-11-18T19:52:59Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* Most Common Error Messages in Ruby */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This is a wiki article for the material presented in the Coursera SaaS video series, [https://www.youtube.com/watch?v=Ee5vfe0mLb8 3.13 Debugging by Dr. Armando Fox and Dr. David Patterson]. We aim to cover all the material presented in the video with definitions and examples&lt;br /&gt;
===Why debugging in Rails can be tricky?===&lt;br /&gt;
*We are used to printing the error on the terminal in most applications(Example: [http://www.cplusplus.com/reference/clibrary/cstdio/stderr/ STDERR]). This may not be possible for a web application since its primary form of input and output is through HTTP requests and responses.&lt;br /&gt;
&lt;br /&gt;
*Errors early in flow might manifest itself late.&lt;br /&gt;
Consider the following hierarchy seen in a Rails application:&lt;br /&gt;
 URI -&amp;gt; Route -&amp;gt; Controller -&amp;gt; Model -&amp;gt; View -&amp;gt; Renderer&lt;br /&gt;
 &lt;br /&gt;
Here, something that goes wrong in the controller might not manifest itself until the renderer. The root cause of the error might have happened a long time ago.&lt;br /&gt;
&lt;br /&gt;
*Errors can be hard to localize/reproduce if it affects only some users or routes.&lt;br /&gt;
&lt;br /&gt;
There are several approaches that can be used for debugging based on the mode of operation, that is development mode or production mode:&lt;br /&gt;
 &lt;br /&gt;
'''Printing to terminal:'''This is useful for developers, when they are writing code they can print errors to the terminal and then examine them. We cannot use this approach in production mode.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Logging:''' This is a more general approach to debugging which can be used in both modes. The logged entries are permanent record of what the application is doing. The recorded errors are saved in a log file and can be referenced later.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interactive Debugging:''' Using this tool you can stop the application in its tracks and inspect the state of the variables or other parameters to locate the error.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the various approaches and the modes in which they can be used: &amp;lt;br&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Approach !! Development !! Production&lt;br /&gt;
|-&lt;br /&gt;
| Printing to Terminal || ✓ || &lt;br /&gt;
|-&lt;br /&gt;
| Logging || ✓ || ✓&lt;br /&gt;
|-&lt;br /&gt;
| Interactive Debugging || ✓ || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==RASP==&lt;br /&gt;
Steps to follow when faced with an error can be concisely represented by RASP according to Dr. Fox.&lt;br /&gt;
===What is RASP?===&lt;br /&gt;
RASP is an acronym which briefs the steps which a developer could follow if she were facing an error message. It stands for:&lt;br /&gt;
#'''Read''' the error message.&lt;br /&gt;
#'''Ask''' your colleague  &lt;br /&gt;
#'''Search''' using [http://stackoverflow.com/ Stack Overflow] or any other search engine.&lt;br /&gt;
#'''Post''' on [http://stackoverflow.com/ Stack Overflow] or class forum&lt;br /&gt;
&lt;br /&gt;
Reading the error message carefully is the first step in debugging. The error messages in Rails are incredibly detailed and it gives us a lot of information, reading it carefully can help us locate the file and line in which you are facing the error. But what if the line looks alright to you?&amp;lt;br&amp;gt;&lt;br /&gt;
The next step is to ask a colleague an informed question. In case you are doing pair programming, this is a good step to take. The question has to be of the form &amp;quot;I am trying to do this and I expected to get this but I got this other thing instead of foo.&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
If the previous steps fail then searching using stack overflow or Google is next, especially if its an error which is particular to a version of gems or OS.&amp;lt;br&amp;gt;&lt;br /&gt;
In case you don't find a solution to your problem the final step is to get minimal but complete information which reproduces the error message which you are experiencing and post it.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example question and solution from stack overflow:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Ques.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
As we can see the question follows the guidelines explained above. It gives minimal but complete information about the error. It does not give the entire description of the error. It is important to post minimal information so that the person who answers the question can understand your problem quickly.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Ans.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The answer is posted within an hour of posting the question. This shows that posting on stack overflow is a fast way of getting expert help with debugging.&lt;br /&gt;
&lt;br /&gt;
==Understanding Error Messages in Rails==&lt;br /&gt;
Rails usually provides a very verbose description of error messages. Dr. Fox tells us that error messages are our friends, they try to not only show us what went wrong but a great deal of detail of where it went wrong. Let us look at an example error message.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
An error message was deliberately caused by entering a route which wouldn't work. The application which we are using is the backchannel application and we are trying to find a post with id=20 (it doesn't exist). This causes rails to throw the following error  message.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;'''ActiveRecord::RecordNotFound in PostsController#show'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;Couldn't find Post with id=20&amp;lt;br&amp;gt;&lt;br /&gt;
 Rails.root: C:/Users/BruceWayne/Downloads/BackChannelApplication&amp;lt;br&amp;gt;&lt;br /&gt;
 Application Trace | Framework Trace | Full Trace&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''What is the error message trying to tell us?'''&amp;lt;br&amp;gt;&lt;br /&gt;
It tells us that ActiveRecord raised the error, and the error was raised in the show method of the Posts Controller. Rails tried to find a post with id=20 but it failed.&lt;br /&gt;
===Application Trace===&lt;br /&gt;
The application trace will give us the file, line number and the method in which the error was thrown. For the above example the application trace will look like this:&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;code&amp;gt;app/controllers/posts_controller.rb:17:in `show'&amp;lt;/code&amp;gt;&lt;br /&gt;
===Stack Trace===&lt;br /&gt;
Full stack trace shows us the entire stack trace of right when the application started until the problem is encountered. Usually stack traces are very lengthy but they can be very useful to solve problems. Here is a partial stack trace from the back channel application error which we saw before:&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;code&amp;gt;activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:341:in `find_one'&amp;lt;br&amp;gt;&lt;br /&gt;
 activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:312:in `find_with_ids'&amp;lt;br&amp;gt;&lt;br /&gt;
 activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:107:in `find'&amp;lt;br&amp;gt;&lt;br /&gt;
 C:in `find'&amp;lt;br&amp;gt;&lt;br /&gt;
 app/controllers/posts_controller.rb:17:in `show'&amp;lt;br&amp;gt;&lt;br /&gt;
 actionpack (3.2.8) lib/action_controller/metal/implicit_render.rb:4:in `send_action'&amp;lt;br&amp;gt;&lt;br /&gt;
 actionpack (3.2.8) lib/abstract_controller/base.rb:167:in `process_action'&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can see the stack trace right from where the Rails application started, we can see the calls to activerecord. It is unlikely that there would be a problem in those files. As we continue looking into the stack trace we see the find method, we can click on the link in the trace and it will take us to the line in which the error was found. Most often the first few lines of the stack trace will give us the cause behind the error.&lt;br /&gt;
===Env Dump and Session Dump===&lt;br /&gt;
Session dump gives all the information of the user's session. This is useful if the error which needs to be fixed is particular to a user or a group of users.&lt;br /&gt;
 &amp;lt;code&amp;gt;_csrf_token: &amp;quot;LiTiqHSVFOr8uT0+pFJhNCFjUc3YikuJy6F77QG+O1Y=&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 comment_id: 1&amp;lt;br&amp;gt;&lt;br /&gt;
 post_id: 1&amp;lt;br&amp;gt;&lt;br /&gt;
 session_id: &amp;quot;c562769a55b39620228ce6064aaa1637&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 user: #&amp;lt;User id: 4, name: &amp;quot;seriously&amp;quot;, username: &amp;quot;seriously&amp;quot;, email: &amp;quot;seriously@seriously.com&amp;quot;,&amp;lt;br&amp;gt; encrypted_password: &amp;quot;cb32e64bd4cb11c7424ea4ea75731450e99ed120d4bab155a42...&amp;quot;, salt: &amp;quot;DlLGMQzwgU&amp;quot;, is_admin: nil,&amp;lt;br&amp;gt; created_at: &amp;quot;2012-11-18 01:08:35&amp;quot;, updated_at: &amp;quot;2012-11-18 01:08:35&amp;quot;&amp;gt;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Environment dump gives details of the rails runtime environment. If the error is localized to users who use the same version of a host or a protocol, we could find that out using the environment dump.&lt;br /&gt;
 &amp;lt;code&amp;gt;GATEWAY_INTERFACE: &amp;quot;CGI/1.1&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT: &amp;quot;text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_CHARSET: &amp;quot;ISO-8859-1,utf-8;q=0.7,*;q=0.3&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_ENCODING: &amp;quot;gzip,deflate,sdch&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_LANGUAGE: &amp;quot;en-US,en;q=0.8&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 REMOTE_ADDR: &amp;quot;127.0.0.1&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 REMOTE_HOST: &amp;quot;Wayne-PC&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 SERVER_NAME: &amp;quot;localhost&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 SERVER_PROTOCOL: &amp;quot;HTTP/1.1&amp;quot;&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===A Very Common Error Message in Ruby===&lt;br /&gt;
&amp;lt;code&amp;gt;undefined method ‘foo’ for nil:NilClass&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Often, it means that an assignment silently failed and we didn't check for errors.&amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;code&amp;gt;@m = Movie.find_by_id(id) #could be nil&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When you try to call m.title after an assignment like the one above, it will throw this error.&lt;br /&gt;
&lt;br /&gt;
==Rails Debugger==&lt;br /&gt;
===What is a debugger?===&lt;br /&gt;
Sometimes printing errors to the console or logging is not enough to find out the root cause behind an error message. It is during these times when the debugger is a developer's best friend. The debugger helps us to step forward or backward in the code, execute or skip lines of code, examine the state of a variable or a parameter which has been passed. This will help the developer pinpoint to the actual source of the problem and fix it.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''How to install the debugger?'''&amp;lt;br&amp;gt;&lt;br /&gt;
In Rails, ruby-debug is a gem. We can install it like any other gem. To use the gem in a Rails application we need to add the following line: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;require &amp;quot;ruby-debug&amp;quot;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
in the &amp;lt;code&amp;gt;config/environments/development.rb&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby 1.9, you can use this command to install a compatible version of the debugger gem:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;gem install debugger&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''Running the debugger&amp;lt;br&amp;gt;'''&lt;br /&gt;
To use the debugger in the rails application we need to start the server with the &amp;lt;code&amp;gt;--debugger&amp;lt;/code&amp;gt; option. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;$ rails server --debugger&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we don't do this we would encounter an error like this:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;***** Debugger requested, but was not available: Start server with --debugger to enable *****&amp;lt;/code&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can invoke the debugger from any method by using the &amp;lt;code&amp;gt;debugger&amp;lt;/code&amp;gt; keyword in the method.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class PostController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    debugger&lt;br /&gt;
    @post = Post.new&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Once the debugger method is called a debugger shell is started inside the terminal window where the application server was launched, and the cursor will be placed at ruby-debug’s prompt &amp;lt;code&amp;gt;(rdb:n)&amp;lt;/code&amp;gt; where n is the thread number. The prompt will show the next line of code which is waiting to run.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Rails is a relatively new platform for development, it is continually evolving which effectively means debugging is harder. However by leveraging the knowledge of people who have encountered similar errors before we can resolve a subset of the problems, the ones particular to versions of ruby and other gems. We have tools like debugger and application trace to help us solve problems which are specific to our application. To know more about using the debugger, please refer to the Further Reading section of the article.&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
# [http://guides.rubyonrails.org/debugging_rails_applications.html Rails Guide - Debugging Rails Applications]&lt;br /&gt;
# [http://www.sitepoint.com/debug-rails-app-ruby-debug/ Debug your rails app with ruby-debug]&lt;br /&gt;
# [http://rubyforge.org/projects/ruby-debug/ Ruby Forge - Documentation for ruby-debug]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
https://www.youtube.com/watch?v=Ee5vfe0mLb8&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70313</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w-1w65 am</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70313"/>
		<updated>2012-11-18T19:50:34Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* Env Dump and Session Dump */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This is a wiki article for the material presented in the Coursera SaaS video series, [https://www.youtube.com/watch?v=Ee5vfe0mLb8 3.13 Debugging by Dr. Armando Fox and Dr. David Patterson]. We aim to cover all the material presented in the video with definitions and examples&lt;br /&gt;
===Why debugging in Rails can be tricky?===&lt;br /&gt;
*We are used to printing the error on the terminal in most applications(Example: [http://www.cplusplus.com/reference/clibrary/cstdio/stderr/ STDERR]). This may not be possible for a web application since its primary form of input and output is through HTTP requests and responses.&lt;br /&gt;
&lt;br /&gt;
*Errors early in flow might manifest itself late.&lt;br /&gt;
Consider the following hierarchy seen in a Rails application:&lt;br /&gt;
 URI -&amp;gt; Route -&amp;gt; Controller -&amp;gt; Model -&amp;gt; View -&amp;gt; Renderer&lt;br /&gt;
 &lt;br /&gt;
Here, something that goes wrong in the controller might not manifest itself until the renderer. The root cause of the error might have happened a long time ago.&lt;br /&gt;
&lt;br /&gt;
*Errors can be hard to localize/reproduce if it affects only some users or routes.&lt;br /&gt;
&lt;br /&gt;
There are several approaches that can be used for debugging based on the mode of operation, that is development mode or production mode:&lt;br /&gt;
 &lt;br /&gt;
'''Printing to terminal:'''This is useful for developers, when they are writing code they can print errors to the terminal and then examine them. We cannot use this approach in production mode.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Logging:''' This is a more general approach to debugging which can be used in both modes. The logged entries are permanent record of what the application is doing. The recorded errors are saved in a log file and can be referenced later.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interactive Debugging:''' Using this tool you can stop the application in its tracks and inspect the state of the variables or other parameters to locate the error.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the various approaches and the modes in which they can be used: &amp;lt;br&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Approach !! Development !! Production&lt;br /&gt;
|-&lt;br /&gt;
| Printing to Terminal || ✓ || &lt;br /&gt;
|-&lt;br /&gt;
| Logging || ✓ || ✓&lt;br /&gt;
|-&lt;br /&gt;
| Interactive Debugging || ✓ || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==RASP==&lt;br /&gt;
Steps to follow when faced with an error can be concisely represented by RASP according to Dr. Fox.&lt;br /&gt;
===What is RASP?===&lt;br /&gt;
RASP is an acronym which briefs the steps which a developer could follow if she were facing an error message. It stands for:&lt;br /&gt;
#'''Read''' the error message.&lt;br /&gt;
#'''Ask''' your colleague  &lt;br /&gt;
#'''Search''' using [http://stackoverflow.com/ Stack Overflow] or any other search engine.&lt;br /&gt;
#'''Post''' on [http://stackoverflow.com/ Stack Overflow] or class forum&lt;br /&gt;
&lt;br /&gt;
Reading the error message carefully is the first step in debugging. The error messages in Rails are incredibly detailed and it gives us a lot of information, reading it carefully can help us locate the file and line in which you are facing the error. But what if the line looks alright to you?&amp;lt;br&amp;gt;&lt;br /&gt;
The next step is to ask a colleague an informed question. In case you are doing pair programming, this is a good step to take. The question has to be of the form &amp;quot;I am trying to do this and I expected to get this but I got this other thing instead of foo.&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
If the previous steps fail then searching using stack overflow or Google is next, especially if its an error which is particular to a version of gems or OS.&amp;lt;br&amp;gt;&lt;br /&gt;
In case you don't find a solution to your problem the final step is to get minimal but complete information which reproduces the error message which you are experiencing and post it.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example question and solution from stack overflow:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Ques.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
As we can see the question follows the guidelines explained above. It gives minimal but complete information about the error. It does not give the entire description of the error. It is important to post minimal information so that the person who answers the question can understand your problem quickly.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Ans.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The answer is posted within an hour of posting the question. This shows that posting on stack overflow is a fast way of getting expert help with debugging.&lt;br /&gt;
&lt;br /&gt;
==Understanding Error Messages in Rails==&lt;br /&gt;
Rails usually provides a very verbose description of error messages. Dr. Fox tells us that error messages are our friends, they try to not only show us what went wrong but a great deal of detail of where it went wrong. Let us look at an example error message.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
An error message was deliberately caused by entering a route which wouldn't work. The application which we are using is the backchannel application and we are trying to find a post with id=20 (it doesn't exist). This causes rails to throw the following error  message.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;'''ActiveRecord::RecordNotFound in PostsController#show'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;Couldn't find Post with id=20&amp;lt;br&amp;gt;&lt;br /&gt;
 Rails.root: C:/Users/BruceWayne/Downloads/BackChannelApplication&amp;lt;br&amp;gt;&lt;br /&gt;
 Application Trace | Framework Trace | Full Trace&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''What is the error message trying to tell us?'''&amp;lt;br&amp;gt;&lt;br /&gt;
It tells us that ActiveRecord raised the error, and the error was raised in the show method of the Posts Controller. Rails tried to find a post with id=20 but it failed.&lt;br /&gt;
===Application Trace===&lt;br /&gt;
The application trace will give us the file, line number and the method in which the error was thrown. For the above example the application trace will look like this:&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;code&amp;gt;app/controllers/posts_controller.rb:17:in `show'&amp;lt;/code&amp;gt;&lt;br /&gt;
===Stack Trace===&lt;br /&gt;
Full stack trace shows us the entire stack trace of right when the application started until the problem is encountered. Usually stack traces are very lengthy but they can be very useful to solve problems. Here is a partial stack trace from the back channel application error which we saw before:&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;code&amp;gt;activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:341:in `find_one'&amp;lt;br&amp;gt;&lt;br /&gt;
 activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:312:in `find_with_ids'&amp;lt;br&amp;gt;&lt;br /&gt;
 activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:107:in `find'&amp;lt;br&amp;gt;&lt;br /&gt;
 C:in `find'&amp;lt;br&amp;gt;&lt;br /&gt;
 app/controllers/posts_controller.rb:17:in `show'&amp;lt;br&amp;gt;&lt;br /&gt;
 actionpack (3.2.8) lib/action_controller/metal/implicit_render.rb:4:in `send_action'&amp;lt;br&amp;gt;&lt;br /&gt;
 actionpack (3.2.8) lib/abstract_controller/base.rb:167:in `process_action'&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can see the stack trace right from where the Rails application started, we can see the calls to activerecord. It is unlikely that there would be a problem in those files. As we continue looking into the stack trace we see the find method, we can click on the link in the trace and it will take us to the line in which the error was found. Most often the first few lines of the stack trace will give us the cause behind the error.&lt;br /&gt;
===Env Dump and Session Dump===&lt;br /&gt;
Session dump gives all the information of the user's session. This is useful if the error which needs to be fixed is particular to a user or a group of users.&lt;br /&gt;
 &amp;lt;code&amp;gt;_csrf_token: &amp;quot;LiTiqHSVFOr8uT0+pFJhNCFjUc3YikuJy6F77QG+O1Y=&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 comment_id: 1&amp;lt;br&amp;gt;&lt;br /&gt;
 post_id: 1&amp;lt;br&amp;gt;&lt;br /&gt;
 session_id: &amp;quot;c562769a55b39620228ce6064aaa1637&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 user: #&amp;lt;User id: 4, name: &amp;quot;seriously&amp;quot;, username: &amp;quot;seriously&amp;quot;, email: &amp;quot;seriously@seriously.com&amp;quot;,&amp;lt;br&amp;gt; encrypted_password: &amp;quot;cb32e64bd4cb11c7424ea4ea75731450e99ed120d4bab155a42...&amp;quot;, salt: &amp;quot;DlLGMQzwgU&amp;quot;, is_admin: nil,&amp;lt;br&amp;gt; created_at: &amp;quot;2012-11-18 01:08:35&amp;quot;, updated_at: &amp;quot;2012-11-18 01:08:35&amp;quot;&amp;gt;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Environment dump gives details of the rails runtime environment. If the error is localized to users who use the same version of a host or a protocol, we could find that out using the environment dump.&lt;br /&gt;
 &amp;lt;code&amp;gt;GATEWAY_INTERFACE: &amp;quot;CGI/1.1&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT: &amp;quot;text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_CHARSET: &amp;quot;ISO-8859-1,utf-8;q=0.7,*;q=0.3&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_ENCODING: &amp;quot;gzip,deflate,sdch&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_LANGUAGE: &amp;quot;en-US,en;q=0.8&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 REMOTE_ADDR: &amp;quot;127.0.0.1&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 REMOTE_HOST: &amp;quot;Wayne-PC&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 SERVER_NAME: &amp;quot;localhost&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 SERVER_PROTOCOL: &amp;quot;HTTP/1.1&amp;quot;&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Most Common Error Messages in Ruby===&lt;br /&gt;
&lt;br /&gt;
==Rails Debugger==&lt;br /&gt;
===What is a debugger?===&lt;br /&gt;
Sometimes printing errors to the console or logging is not enough to find out the root cause behind an error message. It is during these times when the debugger is a developer's best friend. The debugger helps us to step forward or backward in the code, execute or skip lines of code, examine the state of a variable or a parameter which has been passed. This will help the developer pinpoint to the actual source of the problem and fix it.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''How to install the debugger?'''&amp;lt;br&amp;gt;&lt;br /&gt;
In Rails, ruby-debug is a gem. We can install it like any other gem. To use the gem in a Rails application we need to add the following line: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;require &amp;quot;ruby-debug&amp;quot;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
in the &amp;lt;code&amp;gt;config/environments/development.rb&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby 1.9, you can use this command to install a compatible version of the debugger gem:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;gem install debugger&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''Running the debugger&amp;lt;br&amp;gt;'''&lt;br /&gt;
To use the debugger in the rails application we need to start the server with the &amp;lt;code&amp;gt;--debugger&amp;lt;/code&amp;gt; option. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;$ rails server --debugger&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we don't do this we would encounter an error like this:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;***** Debugger requested, but was not available: Start server with --debugger to enable *****&amp;lt;/code&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can invoke the debugger from any method by using the &amp;lt;code&amp;gt;debugger&amp;lt;/code&amp;gt; keyword in the method.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class PostController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    debugger&lt;br /&gt;
    @post = Post.new&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Once the debugger method is called a debugger shell is started inside the terminal window where the application server was launched, and the cursor will be placed at ruby-debug’s prompt &amp;lt;code&amp;gt;(rdb:n)&amp;lt;/code&amp;gt; where n is the thread number. The prompt will show the next line of code which is waiting to run.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Rails is a relatively new platform for development, it is continually evolving which effectively means debugging is harder. However by leveraging the knowledge of people who have encountered similar errors before we can resolve a subset of the problems, the ones particular to versions of ruby and other gems. We have tools like debugger and application trace to help us solve problems which are specific to our application. To know more about using the debugger, please refer to the Further Reading section of the article.&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
# [http://guides.rubyonrails.org/debugging_rails_applications.html Rails Guide - Debugging Rails Applications]&lt;br /&gt;
# [http://www.sitepoint.com/debug-rails-app-ruby-debug/ Debug your rails app with ruby-debug]&lt;br /&gt;
# [http://rubyforge.org/projects/ruby-debug/ Ruby Forge - Documentation for ruby-debug]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
https://www.youtube.com/watch?v=Ee5vfe0mLb8&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70311</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w-1w65 am</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70311"/>
		<updated>2012-11-18T19:48:21Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* Env Dump and Session Dump */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This is a wiki article for the material presented in the Coursera SaaS video series, [https://www.youtube.com/watch?v=Ee5vfe0mLb8 3.13 Debugging by Dr. Armando Fox and Dr. David Patterson]. We aim to cover all the material presented in the video with definitions and examples&lt;br /&gt;
===Why debugging in Rails can be tricky?===&lt;br /&gt;
*We are used to printing the error on the terminal in most applications(Example: [http://www.cplusplus.com/reference/clibrary/cstdio/stderr/ STDERR]). This may not be possible for a web application since its primary form of input and output is through HTTP requests and responses.&lt;br /&gt;
&lt;br /&gt;
*Errors early in flow might manifest itself late.&lt;br /&gt;
Consider the following hierarchy seen in a Rails application:&lt;br /&gt;
 URI -&amp;gt; Route -&amp;gt; Controller -&amp;gt; Model -&amp;gt; View -&amp;gt; Renderer&lt;br /&gt;
 &lt;br /&gt;
Here, something that goes wrong in the controller might not manifest itself until the renderer. The root cause of the error might have happened a long time ago.&lt;br /&gt;
&lt;br /&gt;
*Errors can be hard to localize/reproduce if it affects only some users or routes.&lt;br /&gt;
&lt;br /&gt;
There are several approaches that can be used for debugging based on the mode of operation, that is development mode or production mode:&lt;br /&gt;
 &lt;br /&gt;
'''Printing to terminal:'''This is useful for developers, when they are writing code they can print errors to the terminal and then examine them. We cannot use this approach in production mode.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Logging:''' This is a more general approach to debugging which can be used in both modes. The logged entries are permanent record of what the application is doing. The recorded errors are saved in a log file and can be referenced later.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interactive Debugging:''' Using this tool you can stop the application in its tracks and inspect the state of the variables or other parameters to locate the error.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the various approaches and the modes in which they can be used: &amp;lt;br&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Approach !! Development !! Production&lt;br /&gt;
|-&lt;br /&gt;
| Printing to Terminal || ✓ || &lt;br /&gt;
|-&lt;br /&gt;
| Logging || ✓ || ✓&lt;br /&gt;
|-&lt;br /&gt;
| Interactive Debugging || ✓ || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==RASP==&lt;br /&gt;
Steps to follow when faced with an error can be concisely represented by RASP according to Dr. Fox.&lt;br /&gt;
===What is RASP?===&lt;br /&gt;
RASP is an acronym which briefs the steps which a developer could follow if she were facing an error message. It stands for:&lt;br /&gt;
#'''Read''' the error message.&lt;br /&gt;
#'''Ask''' your colleague  &lt;br /&gt;
#'''Search''' using [http://stackoverflow.com/ Stack Overflow] or any other search engine.&lt;br /&gt;
#'''Post''' on [http://stackoverflow.com/ Stack Overflow] or class forum&lt;br /&gt;
&lt;br /&gt;
Reading the error message carefully is the first step in debugging. The error messages in Rails are incredibly detailed and it gives us a lot of information, reading it carefully can help us locate the file and line in which you are facing the error. But what if the line looks alright to you?&amp;lt;br&amp;gt;&lt;br /&gt;
The next step is to ask a colleague an informed question. In case you are doing pair programming, this is a good step to take. The question has to be of the form &amp;quot;I am trying to do this and I expected to get this but I got this other thing instead of foo.&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
If the previous steps fail then searching using stack overflow or Google is next, especially if its an error which is particular to a version of gems or OS.&amp;lt;br&amp;gt;&lt;br /&gt;
In case you don't find a solution to your problem the final step is to get minimal but complete information which reproduces the error message which you are experiencing and post it.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example question and solution from stack overflow:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Ques.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
As we can see the question follows the guidelines explained above. It gives minimal but complete information about the error. It does not give the entire description of the error. It is important to post minimal information so that the person who answers the question can understand your problem quickly.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Ans.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The answer is posted within an hour of posting the question. This shows that posting on stack overflow is a fast way of getting expert help with debugging.&lt;br /&gt;
&lt;br /&gt;
==Understanding Error Messages in Rails==&lt;br /&gt;
Rails usually provides a very verbose description of error messages. Dr. Fox tells us that error messages are our friends, they try to not only show us what went wrong but a great deal of detail of where it went wrong. Let us look at an example error message.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
An error message was deliberately caused by entering a route which wouldn't work. The application which we are using is the backchannel application and we are trying to find a post with id=20 (it doesn't exist). This causes rails to throw the following error  message.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;'''ActiveRecord::RecordNotFound in PostsController#show'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;Couldn't find Post with id=20&amp;lt;br&amp;gt;&lt;br /&gt;
 Rails.root: C:/Users/BruceWayne/Downloads/BackChannelApplication&amp;lt;br&amp;gt;&lt;br /&gt;
 Application Trace | Framework Trace | Full Trace&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''What is the error message trying to tell us?'''&amp;lt;br&amp;gt;&lt;br /&gt;
It tells us that ActiveRecord raised the error, and the error was raised in the show method of the Posts Controller. Rails tried to find a post with id=20 but it failed.&lt;br /&gt;
===Application Trace===&lt;br /&gt;
The application trace will give us the file, line number and the method in which the error was thrown. For the above example the application trace will look like this:&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;code&amp;gt;app/controllers/posts_controller.rb:17:in `show'&amp;lt;/code&amp;gt;&lt;br /&gt;
===Stack Trace===&lt;br /&gt;
Full stack trace shows us the entire stack trace of right when the application started until the problem is encountered. Usually stack traces are very lengthy but they can be very useful to solve problems. Here is a partial stack trace from the back channel application error which we saw before:&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;code&amp;gt;activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:341:in `find_one'&amp;lt;br&amp;gt;&lt;br /&gt;
 activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:312:in `find_with_ids'&amp;lt;br&amp;gt;&lt;br /&gt;
 activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:107:in `find'&amp;lt;br&amp;gt;&lt;br /&gt;
 C:in `find'&amp;lt;br&amp;gt;&lt;br /&gt;
 app/controllers/posts_controller.rb:17:in `show'&amp;lt;br&amp;gt;&lt;br /&gt;
 actionpack (3.2.8) lib/action_controller/metal/implicit_render.rb:4:in `send_action'&amp;lt;br&amp;gt;&lt;br /&gt;
 actionpack (3.2.8) lib/abstract_controller/base.rb:167:in `process_action'&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can see the stack trace right from where the Rails application started, we can see the calls to activerecord. It is unlikely that there would be a problem in those files. As we continue looking into the stack trace we see the find method, we can click on the link in the trace and it will take us to the line in which the error was found. Most often the first few lines of the stack trace will give us the cause behind the error.&lt;br /&gt;
===Env Dump and Session Dump===&lt;br /&gt;
Session dump gives all the information of the user's session. This is useful if the error which needs to be fixed is particular to a user or a group of users.&lt;br /&gt;
 &amp;lt;code&amp;gt;_csrf_token: &amp;quot;LiTiqHSVFOr8uT0+pFJhNCFjUc3YikuJy6F77QG+O1Y=&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 comment_id: 1&amp;lt;br&amp;gt;&lt;br /&gt;
 post_id: 1&amp;lt;br&amp;gt;&lt;br /&gt;
 session_id: &amp;quot;c562769a55b39620228ce6064aaa1637&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 user: #&amp;lt;User id: 4, name: &amp;quot;seriously&amp;quot;, username: &amp;quot;seriously&amp;quot;, email: &amp;quot;seriously@seriously.com&amp;quot;,&amp;lt;br&amp;gt; encrypted_password: &amp;quot;cb32e64bd4cb11c7424ea4ea75731450e99ed120d4bab155a42...&amp;quot;, salt: &amp;quot;DlLGMQzwgU&amp;quot;, is_admin: nil,&amp;lt;br&amp;gt; created_at: &amp;quot;2012-11-18 01:08:35&amp;quot;, updated_at: &amp;quot;2012-11-18 01:08:35&amp;quot;&amp;gt;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Environment dump gives details of the rails runtime environment.&lt;br /&gt;
 &amp;lt;code&amp;gt;GATEWAY_INTERFACE: &amp;quot;CGI/1.1&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT: &amp;quot;text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_CHARSET: &amp;quot;ISO-8859-1,utf-8;q=0.7,*;q=0.3&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_ENCODING: &amp;quot;gzip,deflate,sdch&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_LANGUAGE: &amp;quot;en-US,en;q=0.8&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 REMOTE_ADDR: &amp;quot;127.0.0.1&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 REMOTE_HOST: &amp;quot;Wayne-PC&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 SERVER_NAME: &amp;quot;localhost&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 SERVER_PROTOCOL: &amp;quot;HTTP/1.1&amp;quot;&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Most Common Error Messages in Ruby===&lt;br /&gt;
&lt;br /&gt;
==Rails Debugger==&lt;br /&gt;
===What is a debugger?===&lt;br /&gt;
Sometimes printing errors to the console or logging is not enough to find out the root cause behind an error message. It is during these times when the debugger is a developer's best friend. The debugger helps us to step forward or backward in the code, execute or skip lines of code, examine the state of a variable or a parameter which has been passed. This will help the developer pinpoint to the actual source of the problem and fix it.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''How to install the debugger?'''&amp;lt;br&amp;gt;&lt;br /&gt;
In Rails, ruby-debug is a gem. We can install it like any other gem. To use the gem in a Rails application we need to add the following line: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;require &amp;quot;ruby-debug&amp;quot;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
in the &amp;lt;code&amp;gt;config/environments/development.rb&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby 1.9, you can use this command to install a compatible version of the debugger gem:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;gem install debugger&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''Running the debugger&amp;lt;br&amp;gt;'''&lt;br /&gt;
To use the debugger in the rails application we need to start the server with the &amp;lt;code&amp;gt;--debugger&amp;lt;/code&amp;gt; option. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;$ rails server --debugger&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we don't do this we would encounter an error like this:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;***** Debugger requested, but was not available: Start server with --debugger to enable *****&amp;lt;/code&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can invoke the debugger from any method by using the &amp;lt;code&amp;gt;debugger&amp;lt;/code&amp;gt; keyword in the method.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class PostController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    debugger&lt;br /&gt;
    @post = Post.new&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Once the debugger method is called a debugger shell is started inside the terminal window where the application server was launched, and the cursor will be placed at ruby-debug’s prompt &amp;lt;code&amp;gt;(rdb:n)&amp;lt;/code&amp;gt; where n is the thread number. The prompt will show the next line of code which is waiting to run.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Rails is a relatively new platform for development, it is continually evolving which effectively means debugging is harder. However by leveraging the knowledge of people who have encountered similar errors before we can resolve a subset of the problems, the ones particular to versions of ruby and other gems. We have tools like debugger and application trace to help us solve problems which are specific to our application. To know more about using the debugger, please refer to the Further Reading section of the article.&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
# [http://guides.rubyonrails.org/debugging_rails_applications.html Rails Guide - Debugging Rails Applications]&lt;br /&gt;
# [http://www.sitepoint.com/debug-rails-app-ruby-debug/ Debug your rails app with ruby-debug]&lt;br /&gt;
# [http://rubyforge.org/projects/ruby-debug/ Ruby Forge - Documentation for ruby-debug]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
https://www.youtube.com/watch?v=Ee5vfe0mLb8&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70310</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w-1w65 am</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70310"/>
		<updated>2012-11-18T19:47:59Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* Env Dump and Session Dump */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This is a wiki article for the material presented in the Coursera SaaS video series, [https://www.youtube.com/watch?v=Ee5vfe0mLb8 3.13 Debugging by Dr. Armando Fox and Dr. David Patterson]. We aim to cover all the material presented in the video with definitions and examples&lt;br /&gt;
===Why debugging in Rails can be tricky?===&lt;br /&gt;
*We are used to printing the error on the terminal in most applications(Example: [http://www.cplusplus.com/reference/clibrary/cstdio/stderr/ STDERR]). This may not be possible for a web application since its primary form of input and output is through HTTP requests and responses.&lt;br /&gt;
&lt;br /&gt;
*Errors early in flow might manifest itself late.&lt;br /&gt;
Consider the following hierarchy seen in a Rails application:&lt;br /&gt;
 URI -&amp;gt; Route -&amp;gt; Controller -&amp;gt; Model -&amp;gt; View -&amp;gt; Renderer&lt;br /&gt;
 &lt;br /&gt;
Here, something that goes wrong in the controller might not manifest itself until the renderer. The root cause of the error might have happened a long time ago.&lt;br /&gt;
&lt;br /&gt;
*Errors can be hard to localize/reproduce if it affects only some users or routes.&lt;br /&gt;
&lt;br /&gt;
There are several approaches that can be used for debugging based on the mode of operation, that is development mode or production mode:&lt;br /&gt;
 &lt;br /&gt;
'''Printing to terminal:'''This is useful for developers, when they are writing code they can print errors to the terminal and then examine them. We cannot use this approach in production mode.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Logging:''' This is a more general approach to debugging which can be used in both modes. The logged entries are permanent record of what the application is doing. The recorded errors are saved in a log file and can be referenced later.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interactive Debugging:''' Using this tool you can stop the application in its tracks and inspect the state of the variables or other parameters to locate the error.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the various approaches and the modes in which they can be used: &amp;lt;br&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Approach !! Development !! Production&lt;br /&gt;
|-&lt;br /&gt;
| Printing to Terminal || ✓ || &lt;br /&gt;
|-&lt;br /&gt;
| Logging || ✓ || ✓&lt;br /&gt;
|-&lt;br /&gt;
| Interactive Debugging || ✓ || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==RASP==&lt;br /&gt;
Steps to follow when faced with an error can be concisely represented by RASP according to Dr. Fox.&lt;br /&gt;
===What is RASP?===&lt;br /&gt;
RASP is an acronym which briefs the steps which a developer could follow if she were facing an error message. It stands for:&lt;br /&gt;
#'''Read''' the error message.&lt;br /&gt;
#'''Ask''' your colleague  &lt;br /&gt;
#'''Search''' using [http://stackoverflow.com/ Stack Overflow] or any other search engine.&lt;br /&gt;
#'''Post''' on [http://stackoverflow.com/ Stack Overflow] or class forum&lt;br /&gt;
&lt;br /&gt;
Reading the error message carefully is the first step in debugging. The error messages in Rails are incredibly detailed and it gives us a lot of information, reading it carefully can help us locate the file and line in which you are facing the error. But what if the line looks alright to you?&amp;lt;br&amp;gt;&lt;br /&gt;
The next step is to ask a colleague an informed question. In case you are doing pair programming, this is a good step to take. The question has to be of the form &amp;quot;I am trying to do this and I expected to get this but I got this other thing instead of foo.&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
If the previous steps fail then searching using stack overflow or Google is next, especially if its an error which is particular to a version of gems or OS.&amp;lt;br&amp;gt;&lt;br /&gt;
In case you don't find a solution to your problem the final step is to get minimal but complete information which reproduces the error message which you are experiencing and post it.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example question and solution from stack overflow:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Ques.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
As we can see the question follows the guidelines explained above. It gives minimal but complete information about the error. It does not give the entire description of the error. It is important to post minimal information so that the person who answers the question can understand your problem quickly.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Ans.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The answer is posted within an hour of posting the question. This shows that posting on stack overflow is a fast way of getting expert help with debugging.&lt;br /&gt;
&lt;br /&gt;
==Understanding Error Messages in Rails==&lt;br /&gt;
Rails usually provides a very verbose description of error messages. Dr. Fox tells us that error messages are our friends, they try to not only show us what went wrong but a great deal of detail of where it went wrong. Let us look at an example error message.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
An error message was deliberately caused by entering a route which wouldn't work. The application which we are using is the backchannel application and we are trying to find a post with id=20 (it doesn't exist). This causes rails to throw the following error  message.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;'''ActiveRecord::RecordNotFound in PostsController#show'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;Couldn't find Post with id=20&amp;lt;br&amp;gt;&lt;br /&gt;
 Rails.root: C:/Users/BruceWayne/Downloads/BackChannelApplication&amp;lt;br&amp;gt;&lt;br /&gt;
 Application Trace | Framework Trace | Full Trace&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''What is the error message trying to tell us?'''&amp;lt;br&amp;gt;&lt;br /&gt;
It tells us that ActiveRecord raised the error, and the error was raised in the show method of the Posts Controller. Rails tried to find a post with id=20 but it failed.&lt;br /&gt;
===Application Trace===&lt;br /&gt;
The application trace will give us the file, line number and the method in which the error was thrown. For the above example the application trace will look like this:&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;code&amp;gt;app/controllers/posts_controller.rb:17:in `show'&amp;lt;/code&amp;gt;&lt;br /&gt;
===Stack Trace===&lt;br /&gt;
Full stack trace shows us the entire stack trace of right when the application started until the problem is encountered. Usually stack traces are very lengthy but they can be very useful to solve problems. Here is a partial stack trace from the back channel application error which we saw before:&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;code&amp;gt;activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:341:in `find_one'&amp;lt;br&amp;gt;&lt;br /&gt;
 activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:312:in `find_with_ids'&amp;lt;br&amp;gt;&lt;br /&gt;
 activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:107:in `find'&amp;lt;br&amp;gt;&lt;br /&gt;
 C:in `find'&amp;lt;br&amp;gt;&lt;br /&gt;
 app/controllers/posts_controller.rb:17:in `show'&amp;lt;br&amp;gt;&lt;br /&gt;
 actionpack (3.2.8) lib/action_controller/metal/implicit_render.rb:4:in `send_action'&amp;lt;br&amp;gt;&lt;br /&gt;
 actionpack (3.2.8) lib/abstract_controller/base.rb:167:in `process_action'&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can see the stack trace right from where the Rails application started, we can see the calls to activerecord. It is unlikely that there would be a problem in those files. As we continue looking into the stack trace we see the find method, we can click on the link in the trace and it will take us to the line in which the error was found. Most often the first few lines of the stack trace will give us the cause behind the error.&lt;br /&gt;
===Env Dump and Session Dump===&lt;br /&gt;
Session dump gives all the information of the user's session. This is useful if the error which needs to be fixed is particular to a user or a group of users.&lt;br /&gt;
 &amp;lt;code&amp;gt;_csrf_token: &amp;quot;LiTiqHSVFOr8uT0+pFJhNCFjUc3YikuJy6F77QG+O1Y=&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 comment_id: 1&amp;lt;br&amp;gt;&lt;br /&gt;
 post_id: 1&amp;lt;br&amp;gt;&lt;br /&gt;
 session_id: &amp;quot;c562769a55b39620228ce6064aaa1637&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 user: #&amp;lt;User id: 4, name: &amp;quot;seriously&amp;quot;, username: &amp;quot;seriously&amp;quot;, email: &amp;quot;seriously@seriously.com&amp;quot;,&amp;lt;br&amp;gt; encrypted_password: &amp;quot;cb32e64bd4cb11c7424ea4ea75731450e99ed120d4bab155a42...&amp;quot;, salt: &amp;quot;DlLGMQzwgU&amp;quot;, is_admin: nil,&amp;lt;br&amp;gt; created_at: &amp;quot;2012-11-18 01:08:35&amp;quot;, updated_at: &amp;quot;2012-11-18 01:08:35&amp;quot;&amp;gt;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Environment dump gives details of the rails runtime environment.&lt;br /&gt;
 &amp;lt;code&amp;gt;GATEWAY_INTERFACE: &amp;quot;CGI/1.1&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT: &amp;quot;text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_CHARSET: &amp;quot;ISO-8859-1,utf-8;q=0.7,*;q=0.3&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_ENCODING: &amp;quot;gzip,deflate,sdch&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_LANGUAGE: &amp;quot;en-US,en;q=0.8&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 REMOTE_ADDR: &amp;quot;127.0.0.1&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 REMOTE_HOST: &amp;quot;Manoj-PC&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 SERVER_NAME: &amp;quot;localhost&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 SERVER_PROTOCOL: &amp;quot;HTTP/1.1&amp;quot;&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Most Common Error Messages in Ruby===&lt;br /&gt;
&lt;br /&gt;
==Rails Debugger==&lt;br /&gt;
===What is a debugger?===&lt;br /&gt;
Sometimes printing errors to the console or logging is not enough to find out the root cause behind an error message. It is during these times when the debugger is a developer's best friend. The debugger helps us to step forward or backward in the code, execute or skip lines of code, examine the state of a variable or a parameter which has been passed. This will help the developer pinpoint to the actual source of the problem and fix it.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''How to install the debugger?'''&amp;lt;br&amp;gt;&lt;br /&gt;
In Rails, ruby-debug is a gem. We can install it like any other gem. To use the gem in a Rails application we need to add the following line: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;require &amp;quot;ruby-debug&amp;quot;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
in the &amp;lt;code&amp;gt;config/environments/development.rb&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby 1.9, you can use this command to install a compatible version of the debugger gem:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;gem install debugger&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''Running the debugger&amp;lt;br&amp;gt;'''&lt;br /&gt;
To use the debugger in the rails application we need to start the server with the &amp;lt;code&amp;gt;--debugger&amp;lt;/code&amp;gt; option. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;$ rails server --debugger&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we don't do this we would encounter an error like this:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;***** Debugger requested, but was not available: Start server with --debugger to enable *****&amp;lt;/code&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can invoke the debugger from any method by using the &amp;lt;code&amp;gt;debugger&amp;lt;/code&amp;gt; keyword in the method.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class PostController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    debugger&lt;br /&gt;
    @post = Post.new&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Once the debugger method is called a debugger shell is started inside the terminal window where the application server was launched, and the cursor will be placed at ruby-debug’s prompt &amp;lt;code&amp;gt;(rdb:n)&amp;lt;/code&amp;gt; where n is the thread number. The prompt will show the next line of code which is waiting to run.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Rails is a relatively new platform for development, it is continually evolving which effectively means debugging is harder. However by leveraging the knowledge of people who have encountered similar errors before we can resolve a subset of the problems, the ones particular to versions of ruby and other gems. We have tools like debugger and application trace to help us solve problems which are specific to our application. To know more about using the debugger, please refer to the Further Reading section of the article.&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
# [http://guides.rubyonrails.org/debugging_rails_applications.html Rails Guide - Debugging Rails Applications]&lt;br /&gt;
# [http://www.sitepoint.com/debug-rails-app-ruby-debug/ Debug your rails app with ruby-debug]&lt;br /&gt;
# [http://rubyforge.org/projects/ruby-debug/ Ruby Forge - Documentation for ruby-debug]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
https://www.youtube.com/watch?v=Ee5vfe0mLb8&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70309</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w-1w65 am</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70309"/>
		<updated>2012-11-18T19:47:30Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* Understanding Error Messages in Rails */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This is a wiki article for the material presented in the Coursera SaaS video series, [https://www.youtube.com/watch?v=Ee5vfe0mLb8 3.13 Debugging by Dr. Armando Fox and Dr. David Patterson]. We aim to cover all the material presented in the video with definitions and examples&lt;br /&gt;
===Why debugging in Rails can be tricky?===&lt;br /&gt;
*We are used to printing the error on the terminal in most applications(Example: [http://www.cplusplus.com/reference/clibrary/cstdio/stderr/ STDERR]). This may not be possible for a web application since its primary form of input and output is through HTTP requests and responses.&lt;br /&gt;
&lt;br /&gt;
*Errors early in flow might manifest itself late.&lt;br /&gt;
Consider the following hierarchy seen in a Rails application:&lt;br /&gt;
 URI -&amp;gt; Route -&amp;gt; Controller -&amp;gt; Model -&amp;gt; View -&amp;gt; Renderer&lt;br /&gt;
 &lt;br /&gt;
Here, something that goes wrong in the controller might not manifest itself until the renderer. The root cause of the error might have happened a long time ago.&lt;br /&gt;
&lt;br /&gt;
*Errors can be hard to localize/reproduce if it affects only some users or routes.&lt;br /&gt;
&lt;br /&gt;
There are several approaches that can be used for debugging based on the mode of operation, that is development mode or production mode:&lt;br /&gt;
 &lt;br /&gt;
'''Printing to terminal:'''This is useful for developers, when they are writing code they can print errors to the terminal and then examine them. We cannot use this approach in production mode.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Logging:''' This is a more general approach to debugging which can be used in both modes. The logged entries are permanent record of what the application is doing. The recorded errors are saved in a log file and can be referenced later.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interactive Debugging:''' Using this tool you can stop the application in its tracks and inspect the state of the variables or other parameters to locate the error.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the various approaches and the modes in which they can be used: &amp;lt;br&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Approach !! Development !! Production&lt;br /&gt;
|-&lt;br /&gt;
| Printing to Terminal || ✓ || &lt;br /&gt;
|-&lt;br /&gt;
| Logging || ✓ || ✓&lt;br /&gt;
|-&lt;br /&gt;
| Interactive Debugging || ✓ || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==RASP==&lt;br /&gt;
Steps to follow when faced with an error can be concisely represented by RASP according to Dr. Fox.&lt;br /&gt;
===What is RASP?===&lt;br /&gt;
RASP is an acronym which briefs the steps which a developer could follow if she were facing an error message. It stands for:&lt;br /&gt;
#'''Read''' the error message.&lt;br /&gt;
#'''Ask''' your colleague  &lt;br /&gt;
#'''Search''' using [http://stackoverflow.com/ Stack Overflow] or any other search engine.&lt;br /&gt;
#'''Post''' on [http://stackoverflow.com/ Stack Overflow] or class forum&lt;br /&gt;
&lt;br /&gt;
Reading the error message carefully is the first step in debugging. The error messages in Rails are incredibly detailed and it gives us a lot of information, reading it carefully can help us locate the file and line in which you are facing the error. But what if the line looks alright to you?&amp;lt;br&amp;gt;&lt;br /&gt;
The next step is to ask a colleague an informed question. In case you are doing pair programming, this is a good step to take. The question has to be of the form &amp;quot;I am trying to do this and I expected to get this but I got this other thing instead of foo.&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
If the previous steps fail then searching using stack overflow or Google is next, especially if its an error which is particular to a version of gems or OS.&amp;lt;br&amp;gt;&lt;br /&gt;
In case you don't find a solution to your problem the final step is to get minimal but complete information which reproduces the error message which you are experiencing and post it.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example question and solution from stack overflow:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Ques.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
As we can see the question follows the guidelines explained above. It gives minimal but complete information about the error. It does not give the entire description of the error. It is important to post minimal information so that the person who answers the question can understand your problem quickly.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Ans.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The answer is posted within an hour of posting the question. This shows that posting on stack overflow is a fast way of getting expert help with debugging.&lt;br /&gt;
&lt;br /&gt;
==Understanding Error Messages in Rails==&lt;br /&gt;
Rails usually provides a very verbose description of error messages. Dr. Fox tells us that error messages are our friends, they try to not only show us what went wrong but a great deal of detail of where it went wrong. Let us look at an example error message.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
An error message was deliberately caused by entering a route which wouldn't work. The application which we are using is the backchannel application and we are trying to find a post with id=20 (it doesn't exist). This causes rails to throw the following error  message.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;'''ActiveRecord::RecordNotFound in PostsController#show'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;Couldn't find Post with id=20&amp;lt;br&amp;gt;&lt;br /&gt;
 Rails.root: C:/Users/BruceWayne/Downloads/BackChannelApplication&amp;lt;br&amp;gt;&lt;br /&gt;
 Application Trace | Framework Trace | Full Trace&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''What is the error message trying to tell us?'''&amp;lt;br&amp;gt;&lt;br /&gt;
It tells us that ActiveRecord raised the error, and the error was raised in the show method of the Posts Controller. Rails tried to find a post with id=20 but it failed.&lt;br /&gt;
===Application Trace===&lt;br /&gt;
The application trace will give us the file, line number and the method in which the error was thrown. For the above example the application trace will look like this:&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;code&amp;gt;app/controllers/posts_controller.rb:17:in `show'&amp;lt;/code&amp;gt;&lt;br /&gt;
===Stack Trace===&lt;br /&gt;
Full stack trace shows us the entire stack trace of right when the application started until the problem is encountered. Usually stack traces are very lengthy but they can be very useful to solve problems. Here is a partial stack trace from the back channel application error which we saw before:&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;code&amp;gt;activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:341:in `find_one'&amp;lt;br&amp;gt;&lt;br /&gt;
 activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:312:in `find_with_ids'&amp;lt;br&amp;gt;&lt;br /&gt;
 activerecord (3.2.8) lib/active_record/relation/finder_methods.rb:107:in `find'&amp;lt;br&amp;gt;&lt;br /&gt;
 C:in `find'&amp;lt;br&amp;gt;&lt;br /&gt;
 app/controllers/posts_controller.rb:17:in `show'&amp;lt;br&amp;gt;&lt;br /&gt;
 actionpack (3.2.8) lib/action_controller/metal/implicit_render.rb:4:in `send_action'&amp;lt;br&amp;gt;&lt;br /&gt;
 actionpack (3.2.8) lib/abstract_controller/base.rb:167:in `process_action'&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can see the stack trace right from where the Rails application started, we can see the calls to activerecord. It is unlikely that there would be a problem in those files. As we continue looking into the stack trace we see the find method, we can click on the link in the trace and it will take us to the line in which the error was found. Most often the first few lines of the stack trace will give us the cause behind the error.&lt;br /&gt;
===Env Dump and Session Dump===&lt;br /&gt;
Session dump gives all the information of the user's session. This is useful if the error which needs to be fixed is particular to a user or a group of users.&lt;br /&gt;
 &amp;lt;code&amp;gt;_csrf_token: &amp;quot;LiTiqHSVFOr8uT0+pFJhNCFjUc3YikuJy6F77QG+O1Y=&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 comment_id: 1&amp;lt;br&amp;gt;&lt;br /&gt;
 post_id: 1&amp;lt;br&amp;gt;&lt;br /&gt;
 session_id: &amp;quot;c562769a55b39620228ce6064aaa1637&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 user: #&amp;lt;User id: 4, name: &amp;quot;seriously&amp;quot;, username: &amp;quot;seriously&amp;quot;, email: &amp;quot;seriously@seriously.com&amp;quot;, encrypted_password: &amp;quot;cb32e64bd4cb11c7424ea4ea75731450e99ed120d4bab155a42...&amp;quot;, salt: &amp;quot;DlLGMQzwgU&amp;quot;, is_admin: nil, created_at: &amp;quot;2012-11-18 01:08:35&amp;quot;, updated_at: &amp;quot;2012-11-18 01:08:35&amp;quot;&amp;gt;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Environment dump gives details of the rails runtime environment.&lt;br /&gt;
 &amp;lt;code&amp;gt;GATEWAY_INTERFACE: &amp;quot;CGI/1.1&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT: &amp;quot;text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_CHARSET: &amp;quot;ISO-8859-1,utf-8;q=0.7,*;q=0.3&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_ENCODING: &amp;quot;gzip,deflate,sdch&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 HTTP_ACCEPT_LANGUAGE: &amp;quot;en-US,en;q=0.8&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 REMOTE_ADDR: &amp;quot;127.0.0.1&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 REMOTE_HOST: &amp;quot;Manoj-PC&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 SERVER_NAME: &amp;quot;localhost&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
 SERVER_PROTOCOL: &amp;quot;HTTP/1.1&amp;quot;&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
===Most Common Error Messages in Ruby===&lt;br /&gt;
&lt;br /&gt;
==Rails Debugger==&lt;br /&gt;
===What is a debugger?===&lt;br /&gt;
Sometimes printing errors to the console or logging is not enough to find out the root cause behind an error message. It is during these times when the debugger is a developer's best friend. The debugger helps us to step forward or backward in the code, execute or skip lines of code, examine the state of a variable or a parameter which has been passed. This will help the developer pinpoint to the actual source of the problem and fix it.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''How to install the debugger?'''&amp;lt;br&amp;gt;&lt;br /&gt;
In Rails, ruby-debug is a gem. We can install it like any other gem. To use the gem in a Rails application we need to add the following line: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;require &amp;quot;ruby-debug&amp;quot;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
in the &amp;lt;code&amp;gt;config/environments/development.rb&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby 1.9, you can use this command to install a compatible version of the debugger gem:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;gem install debugger&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''Running the debugger&amp;lt;br&amp;gt;'''&lt;br /&gt;
To use the debugger in the rails application we need to start the server with the &amp;lt;code&amp;gt;--debugger&amp;lt;/code&amp;gt; option. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;$ rails server --debugger&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we don't do this we would encounter an error like this:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;***** Debugger requested, but was not available: Start server with --debugger to enable *****&amp;lt;/code&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can invoke the debugger from any method by using the &amp;lt;code&amp;gt;debugger&amp;lt;/code&amp;gt; keyword in the method.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class PostController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    debugger&lt;br /&gt;
    @post = Post.new&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Once the debugger method is called a debugger shell is started inside the terminal window where the application server was launched, and the cursor will be placed at ruby-debug’s prompt &amp;lt;code&amp;gt;(rdb:n)&amp;lt;/code&amp;gt; where n is the thread number. The prompt will show the next line of code which is waiting to run.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Rails is a relatively new platform for development, it is continually evolving which effectively means debugging is harder. However by leveraging the knowledge of people who have encountered similar errors before we can resolve a subset of the problems, the ones particular to versions of ruby and other gems. We have tools like debugger and application trace to help us solve problems which are specific to our application. To know more about using the debugger, please refer to the Further Reading section of the article.&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
# [http://guides.rubyonrails.org/debugging_rails_applications.html Rails Guide - Debugging Rails Applications]&lt;br /&gt;
# [http://www.sitepoint.com/debug-rails-app-ruby-debug/ Debug your rails app with ruby-debug]&lt;br /&gt;
# [http://rubyforge.org/projects/ruby-debug/ Ruby Forge - Documentation for ruby-debug]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
https://www.youtube.com/watch?v=Ee5vfe0mLb8&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70280</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w-1w65 am</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70280"/>
		<updated>2012-11-18T19:17:23Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* What is RASP? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This is a wiki article for the material presented in the Coursera SaaS video series, [https://www.youtube.com/watch?v=Ee5vfe0mLb8 3.13 Debugging by Dr. Armando Fox and Dr. David Patterson]. We aim to cover all the material presented in the video with definitions and examples&lt;br /&gt;
===Why debugging in Rails can be tricky?===&lt;br /&gt;
*We are used to printing the error on the terminal in most applications(Example: [http://www.cplusplus.com/reference/clibrary/cstdio/stderr/ STDERR]). This may not be possible for a web application since its primary form of input and output is through HTTP requests and responses.&lt;br /&gt;
&lt;br /&gt;
*Errors early in flow might manifest itself late.&lt;br /&gt;
Consider the following hierarchy seen in a Rails application:&lt;br /&gt;
 URI -&amp;gt; Route -&amp;gt; Controller -&amp;gt; Model -&amp;gt; View -&amp;gt; Renderer&lt;br /&gt;
 &lt;br /&gt;
Here, something that goes wrong in the controller might not manifest itself until the renderer. The root cause of the error might have happened a long time ago.&lt;br /&gt;
&lt;br /&gt;
*Errors can be hard to localize/reproduce if it affects only some users or routes.&lt;br /&gt;
&lt;br /&gt;
There are several approaches that can be used for debugging based on the mode of operation, that is development mode or production mode:&lt;br /&gt;
 &lt;br /&gt;
'''Printing to terminal:'''This is useful for developers, when they are writing code they can print errors to the terminal and then examine them. We cannot use this approach in production mode.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Logging:''' This is a more general approach to debugging which can be used in both modes. The logged entries are permanent record of what the application is doing. The recorded errors are saved in a log file and can be referenced later.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interactive Debugging:''' Using this tool you can stop the application in its tracks and inspect the state of the variables or other parameters to locate the error.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the various approaches and the modes in which they can be used: &amp;lt;br&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Approach !! Development !! Production&lt;br /&gt;
|-&lt;br /&gt;
| Printing to Terminal || ✓ || &lt;br /&gt;
|-&lt;br /&gt;
| Logging || ✓ || ✓&lt;br /&gt;
|-&lt;br /&gt;
| Interactive Debugging || ✓ || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==RASP==&lt;br /&gt;
Steps to follow when faced with an error can be concisely represented by RASP according to Dr. Fox.&lt;br /&gt;
===What is RASP?===&lt;br /&gt;
RASP is an acronym which briefs the steps which a developer could follow if she were facing an error message. It stands for:&lt;br /&gt;
#'''Read''' the error message.&lt;br /&gt;
#'''Ask''' your colleague  &lt;br /&gt;
#'''Search''' using [http://stackoverflow.com/ Stack Overflow] or any other search engine.&lt;br /&gt;
#'''Post''' on [http://stackoverflow.com/ Stack Overflow] or class forum&lt;br /&gt;
&lt;br /&gt;
Reading the error message carefully is the first step in debugging. The error messages in Rails are incredibly detailed and it gives us a lot of information, reading it carefully can help us locate the file and line in which you are facing the error. But what if the line looks alright to you?&amp;lt;br&amp;gt;&lt;br /&gt;
The next step is to ask a colleague an informed question. In case you are doing pair programming, this is a good step to take. The question has to be of the form &amp;quot;I am trying to do this and I expected to get this but I got this other thing instead of foo.&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
If the previous steps fail then searching using stack overflow or Google is next, especially if its an error which is particular to a version of gems or OS.&amp;lt;br&amp;gt;&lt;br /&gt;
In case you don't find a solution to your problem the final step is to get minimal but complete information which reproduces the error message which you are experiencing and post it.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example question and solution from stack overflow:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Ques.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
As we can see the question follows the guidelines explained above. It gives minimal but complete information about the error. It does not give the entire description of the error. It is important to post minimal information so that the person who answers the question can understand your problem quickly.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Ans.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The answer is posted within an hour of posting the question. This shows that posting on stack overflow is a fast way of getting expert help with debugging.&lt;br /&gt;
&lt;br /&gt;
==Understanding Error Messages in Rails==&lt;br /&gt;
Rails usually provides a very verbose description of error messages. Dr. Fox tells us that error messages are our friends, they try to not only show us what went wrong but a great deal of detail of where it went wrong. Let us look at an example error message.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
An error message was deliberately caused by entering a route which wouldn't work. The application which we are using is the backchannel application and we are trying to find a post with id=20 (it doesn't exist). This causes rails to throw the following error  message.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;'''ActiveRecord::RecordNotFound in PostsController#show'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;Couldn't find Post with id=20&amp;lt;br&amp;gt;&lt;br /&gt;
 Rails.root: C:/Users/BruceWayne/Downloads/BackChannelApplication&amp;lt;br&amp;gt;&lt;br /&gt;
 Application Trace | Framework Trace | Full Trace&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
===Application Trace===&lt;br /&gt;
&lt;br /&gt;
===Full Trace===&lt;br /&gt;
&lt;br /&gt;
===Framework Trace===&lt;br /&gt;
&lt;br /&gt;
===Env Dump and Session Dump===&lt;br /&gt;
===Most Common Error Messages in Ruby===&lt;br /&gt;
&lt;br /&gt;
==Rails Debugger==&lt;br /&gt;
===What is a debugger?===&lt;br /&gt;
Sometimes printing errors to the console or logging is not enough to find out the root cause behind an error message. It is during these times when the debugger is a developer's best friend. The debugger helps us to step forward or backward in the code, execute or skip lines of code, examine the state of a variable or a parameter which has been passed. This will help the developer pinpoint to the actual source of the problem and fix it.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''How to install the debugger?'''&amp;lt;br&amp;gt;&lt;br /&gt;
In Rails, ruby-debug is a gem. We can install it like any other gem. To use the gem in a Rails application we need to add the following line: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;require &amp;quot;ruby-debug&amp;quot;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
in the &amp;lt;code&amp;gt;config/environments/development.rb&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby 1.9, you can use this command to install a compatible version of the debugger gem:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;gem install debugger&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''Running the debugger&amp;lt;br&amp;gt;'''&lt;br /&gt;
To use the debugger in the rails application we need to start the server with the &amp;lt;code&amp;gt;--debugger&amp;lt;/code&amp;gt; option. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;$ rails server --debugger&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we don't do this we would encounter an error like this:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;***** Debugger requested, but was not available: Start server with --debugger to enable *****&amp;lt;/code&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can invoke the debugger from any method by using the &amp;lt;code&amp;gt;debugger&amp;lt;/code&amp;gt; keyword in the method.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class PostController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    debugger&lt;br /&gt;
    @post = Post.new&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Once the debugger method is called a debugger shell is started inside the terminal window where the application server was launched, and the cursor will be placed at ruby-debug’s prompt &amp;lt;code&amp;gt;(rdb:n)&amp;lt;/code&amp;gt; where n is the thread number. The prompt will show the next line of code which is waiting to run.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Rails is a relatively new platform for development, it is continually evolving which effectively means debugging is harder. However by leveraging the knowledge of people who have encountered similar errors before we can resolve a subset of the problems, the ones particular to versions of ruby and other gems. We have tools like debugger and application trace to help us solve problems which are specific to our application. To know more about using the debugger, please refer to the Further Reading section of the article.&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
# [http://guides.rubyonrails.org/debugging_rails_applications.html Rails Guide - Debugging Rails Applications]&lt;br /&gt;
# [http://www.sitepoint.com/debug-rails-app-ruby-debug/ Debug your rails app with ruby-debug]&lt;br /&gt;
# [http://rubyforge.org/projects/ruby-debug/ Ruby Forge - Documentation for ruby-debug]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
https://www.youtube.com/watch?v=Ee5vfe0mLb8&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70277</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w-1w65 am</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70277"/>
		<updated>2012-11-18T19:15:45Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* Understanding Error Messages in Rails */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This is a wiki article for the material presented in the Coursera SaaS video series, [https://www.youtube.com/watch?v=Ee5vfe0mLb8 3.13 Debugging by Dr. Armando Fox and Dr. David Patterson]. We aim to cover all the material presented in the video with definitions and examples&lt;br /&gt;
===Why debugging in Rails can be tricky?===&lt;br /&gt;
*We are used to printing the error on the terminal in most applications(Example: [http://www.cplusplus.com/reference/clibrary/cstdio/stderr/ STDERR]). This may not be possible for a web application since its primary form of input and output is through HTTP requests and responses.&lt;br /&gt;
&lt;br /&gt;
*Errors early in flow might manifest itself late.&lt;br /&gt;
Consider the following hierarchy seen in a Rails application:&lt;br /&gt;
 URI -&amp;gt; Route -&amp;gt; Controller -&amp;gt; Model -&amp;gt; View -&amp;gt; Renderer&lt;br /&gt;
 &lt;br /&gt;
Here, something that goes wrong in the controller might not manifest itself until the renderer. The root cause of the error might have happened a long time ago.&lt;br /&gt;
&lt;br /&gt;
*Errors can be hard to localize/reproduce if it affects only some users or routes.&lt;br /&gt;
&lt;br /&gt;
There are several approaches that can be used for debugging based on the mode of operation, that is development mode or production mode:&lt;br /&gt;
 &lt;br /&gt;
'''Printing to terminal:'''This is useful for developers, when they are writing code they can print errors to the terminal and then examine them. We cannot use this approach in production mode.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Logging:''' This is a more general approach to debugging which can be used in both modes. The logged entries are permanent record of what the application is doing. The recorded errors are saved in a log file and can be referenced later.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interactive Debugging:''' Using this tool you can stop the application in its tracks and inspect the state of the variables or other parameters to locate the error.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the various approaches and the modes in which they can be used: &amp;lt;br&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Approach !! Development !! Production&lt;br /&gt;
|-&lt;br /&gt;
| Printing to Terminal || ✓ || &lt;br /&gt;
|-&lt;br /&gt;
| Logging || ✓ || ✓&lt;br /&gt;
|-&lt;br /&gt;
| Interactive Debugging || ✓ || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==RASP==&lt;br /&gt;
Steps to follow when faced with an error can be concisely represented by RASP according to Dr. Fox.&lt;br /&gt;
===What is RASP?===&lt;br /&gt;
RASP is an acronym which briefs the steps which a developer could follow if she were facing an error message. It stands for:&lt;br /&gt;
#'''Read''' the error message.&lt;br /&gt;
#'''Ask''' your colleague  &lt;br /&gt;
#'''Search''' using [http://stackoverflow.com/ Stack Overflow] or any other search engine.&lt;br /&gt;
#'''Post''' on [http://stackoverflow.com/ Stack Overflow] or class forum&lt;br /&gt;
&lt;br /&gt;
Reading the error message carefully is the first step in debugging. The error messages in Rails are incredibly detailed and it gives us a lot of information, reading it carefully can help us locate the file and line in which you are facing the error. But what if the line looks alright to you?&lt;br /&gt;
The next step is to ask a colleague an informed question. In case you are doing pair programming, this is a good step to take. The question has to be of the form &amp;quot;I am trying to do this and I expected to get this but I got this other thing instead of foo.&amp;quot;&lt;br /&gt;
If the previous steps fail then searching using stack overflow or Google is next, especially if its an error which is particular to a version of gems or OS&lt;br /&gt;
In case you don't find a solution to your problem the final step is to get minimal but complete information which reproduces the error message which you are experiencing and post it.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example question and solution from stack overflow:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Ques.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
As we can see the question follows the guidelines explained above. It gives minimal but complete information about the error. It does not give the entire description of the error. It is important to post minimal information so that the person who answers the question can understand your problem quickly.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Ans.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The answer is posted within an hour of posting the question. This shows that posting on stack overflow is a fast way of getting expert help with debugging.&lt;br /&gt;
&lt;br /&gt;
==Understanding Error Messages in Rails==&lt;br /&gt;
Rails usually provides a very verbose description of error messages. Dr. Fox tells us that error messages are our friends, they try to not only show us what went wrong but a great deal of detail of where it went wrong. Let us look at an example error message.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
An error message was deliberately caused by entering a route which wouldn't work. The application which we are using is the backchannel application and we are trying to find a post with id=20 (it doesn't exist). This causes rails to throw the following error  message.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;'''ActiveRecord::RecordNotFound in PostsController#show'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;Couldn't find Post with id=20&amp;lt;br&amp;gt;&lt;br /&gt;
 Rails.root: C:/Users/BruceWayne/Downloads/BackChannelApplication&amp;lt;br&amp;gt;&lt;br /&gt;
 Application Trace | Framework Trace | Full Trace&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
===Application Trace===&lt;br /&gt;
&lt;br /&gt;
===Full Trace===&lt;br /&gt;
&lt;br /&gt;
===Framework Trace===&lt;br /&gt;
&lt;br /&gt;
===Env Dump and Session Dump===&lt;br /&gt;
===Most Common Error Messages in Ruby===&lt;br /&gt;
&lt;br /&gt;
==Rails Debugger==&lt;br /&gt;
===What is a debugger?===&lt;br /&gt;
Sometimes printing errors to the console or logging is not enough to find out the root cause behind an error message. It is during these times when the debugger is a developer's best friend. The debugger helps us to step forward or backward in the code, execute or skip lines of code, examine the state of a variable or a parameter which has been passed. This will help the developer pinpoint to the actual source of the problem and fix it.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''How to install the debugger?'''&amp;lt;br&amp;gt;&lt;br /&gt;
In Rails, ruby-debug is a gem. We can install it like any other gem. To use the gem in a Rails application we need to add the following line: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;require &amp;quot;ruby-debug&amp;quot;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
in the &amp;lt;code&amp;gt;config/environments/development.rb&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby 1.9, you can use this command to install a compatible version of the debugger gem:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;gem install debugger&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''Running the debugger&amp;lt;br&amp;gt;'''&lt;br /&gt;
To use the debugger in the rails application we need to start the server with the &amp;lt;code&amp;gt;--debugger&amp;lt;/code&amp;gt; option. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;$ rails server --debugger&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we don't do this we would encounter an error like this:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;***** Debugger requested, but was not available: Start server with --debugger to enable *****&amp;lt;/code&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can invoke the debugger from any method by using the &amp;lt;code&amp;gt;debugger&amp;lt;/code&amp;gt; keyword in the method.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class PostController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    debugger&lt;br /&gt;
    @post = Post.new&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Once the debugger method is called a debugger shell is started inside the terminal window where the application server was launched, and the cursor will be placed at ruby-debug’s prompt &amp;lt;code&amp;gt;(rdb:n)&amp;lt;/code&amp;gt; where n is the thread number. The prompt will show the next line of code which is waiting to run.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Rails is a relatively new platform for development, it is continually evolving which effectively means debugging is harder. However by leveraging the knowledge of people who have encountered similar errors before we can resolve a subset of the problems, the ones particular to versions of ruby and other gems. We have tools like debugger and application trace to help us solve problems which are specific to our application. To know more about using the debugger, please refer to the Further Reading section of the article.&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
# [http://guides.rubyonrails.org/debugging_rails_applications.html Rails Guide - Debugging Rails Applications]&lt;br /&gt;
# [http://www.sitepoint.com/debug-rails-app-ruby-debug/ Debug your rails app with ruby-debug]&lt;br /&gt;
# [http://rubyforge.org/projects/ruby-debug/ Ruby Forge - Documentation for ruby-debug]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
https://www.youtube.com/watch?v=Ee5vfe0mLb8&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70272</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w-1w65 am</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70272"/>
		<updated>2012-11-18T19:13:26Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* Understanding Error Messages in Rails */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This is a wiki article for the material presented in the Coursera SaaS video series, [https://www.youtube.com/watch?v=Ee5vfe0mLb8 3.13 Debugging by Dr. Armando Fox and Dr. David Patterson]. We aim to cover all the material presented in the video with definitions and examples&lt;br /&gt;
===Why debugging in Rails can be tricky?===&lt;br /&gt;
*We are used to printing the error on the terminal in most applications(Example: [http://www.cplusplus.com/reference/clibrary/cstdio/stderr/ STDERR]). This may not be possible for a web application since its primary form of input and output is through HTTP requests and responses.&lt;br /&gt;
&lt;br /&gt;
*Errors early in flow might manifest itself late.&lt;br /&gt;
Consider the following hierarchy seen in a Rails application:&lt;br /&gt;
 URI -&amp;gt; Route -&amp;gt; Controller -&amp;gt; Model -&amp;gt; View -&amp;gt; Renderer&lt;br /&gt;
 &lt;br /&gt;
Here, something that goes wrong in the controller might not manifest itself until the renderer. The root cause of the error might have happened a long time ago.&lt;br /&gt;
&lt;br /&gt;
*Errors can be hard to localize/reproduce if it affects only some users or routes.&lt;br /&gt;
&lt;br /&gt;
There are several approaches that can be used for debugging based on the mode of operation, that is development mode or production mode:&lt;br /&gt;
 &lt;br /&gt;
'''Printing to terminal:'''This is useful for developers, when they are writing code they can print errors to the terminal and then examine them. We cannot use this approach in production mode.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Logging:''' This is a more general approach to debugging which can be used in both modes. The logged entries are permanent record of what the application is doing. The recorded errors are saved in a log file and can be referenced later.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interactive Debugging:''' Using this tool you can stop the application in its tracks and inspect the state of the variables or other parameters to locate the error.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the various approaches and the modes in which they can be used: &amp;lt;br&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Approach !! Development !! Production&lt;br /&gt;
|-&lt;br /&gt;
| Printing to Terminal || ✓ || &lt;br /&gt;
|-&lt;br /&gt;
| Logging || ✓ || ✓&lt;br /&gt;
|-&lt;br /&gt;
| Interactive Debugging || ✓ || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==RASP==&lt;br /&gt;
Steps to follow when faced with an error can be concisely represented by RASP according to Dr. Fox.&lt;br /&gt;
===What is RASP?===&lt;br /&gt;
RASP is an acronym which briefs the steps which a developer could follow if she were facing an error message. It stands for:&lt;br /&gt;
#'''Read''' the error message.&lt;br /&gt;
#'''Ask''' your colleague  &lt;br /&gt;
#'''Search''' using [http://stackoverflow.com/ Stack Overflow] or any other search engine.&lt;br /&gt;
#'''Post''' on [http://stackoverflow.com/ Stack Overflow] or class forum&lt;br /&gt;
&lt;br /&gt;
Reading the error message carefully is the first step in debugging. The error messages in Rails are incredibly detailed and it gives us a lot of information, reading it carefully can help us locate the file and line in which you are facing the error. But what if the line looks alright to you?&lt;br /&gt;
The next step is to ask a colleague an informed question. In case you are doing pair programming, this is a good step to take. The question has to be of the form &amp;quot;I am trying to do this and I expected to get this but I got this other thing instead of foo.&amp;quot;&lt;br /&gt;
If the previous steps fail then searching using stack overflow or Google is next, especially if its an error which is particular to a version of gems or OS&lt;br /&gt;
In case you don't find a solution to your problem the final step is to get minimal but complete information which reproduces the error message which you are experiencing and post it.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example question and solution from stack overflow:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Ques.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
As we can see the question follows the guidelines explained above. It gives minimal but complete information about the error. It does not give the entire description of the error. It is important to post minimal information so that the person who answers the question can understand your problem quickly.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Ans.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The answer is posted within an hour of posting the question. This shows that posting on stack overflow is a fast way of getting expert help with debugging.&lt;br /&gt;
&lt;br /&gt;
==Understanding Error Messages in Rails==&lt;br /&gt;
Rails usually provides a very verbose description of error messages. Dr. Fox tells us that error messages are our friends, they try to not only show us what went wrong but a great deal of detail of where it went wrong. Let us look at an example error message.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
 An error message was deliberately caused by entering a route which wouldn't work. The application which we are using is the back   channel application and we are trying to find a post with id=20 (it doesn't exist). This causes rails to throw the following error  message.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;'''ActiveRecord::RecordNotFound in PostsController#show'''&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;Couldn't find Post with id=20&amp;lt;br&amp;gt;&lt;br /&gt;
 Rails.root: C:/Users/BruceWayne/Downloads/BackChannelApplication&amp;lt;br&amp;gt;&lt;br /&gt;
 Application Trace | Framework Trace | Full Trace&amp;lt;br&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
===Application Trace===&lt;br /&gt;
&lt;br /&gt;
===Full Trace===&lt;br /&gt;
&lt;br /&gt;
===Framework Trace===&lt;br /&gt;
&lt;br /&gt;
===Env Dump and Session Dump===&lt;br /&gt;
===Most Common Error Messages in Ruby===&lt;br /&gt;
&lt;br /&gt;
==Rails Debugger==&lt;br /&gt;
===What is a debugger?===&lt;br /&gt;
Sometimes printing errors to the console or logging is not enough to find out the root cause behind an error message. It is during these times when the debugger is a developer's best friend. The debugger helps us to step forward or backward in the code, execute or skip lines of code, examine the state of a variable or a parameter which has been passed. This will help the developer pinpoint to the actual source of the problem and fix it.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''How to install the debugger?'''&amp;lt;br&amp;gt;&lt;br /&gt;
In Rails, ruby-debug is a gem. We can install it like any other gem. To use the gem in a Rails application we need to add the following line: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;require &amp;quot;ruby-debug&amp;quot;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
in the &amp;lt;code&amp;gt;config/environments/development.rb&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby 1.9, you can use this command to install a compatible version of the debugger gem:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;gem install debugger&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''Running the debugger&amp;lt;br&amp;gt;'''&lt;br /&gt;
To use the debugger in the rails application we need to start the server with the &amp;lt;code&amp;gt;--debugger&amp;lt;/code&amp;gt; option. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;$ rails server --debugger&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we don't do this we would encounter an error like this:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;***** Debugger requested, but was not available: Start server with --debugger to enable *****&amp;lt;/code&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can invoke the debugger from any method by using the &amp;lt;code&amp;gt;debugger&amp;lt;/code&amp;gt; keyword in the method.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class PostController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    debugger&lt;br /&gt;
    @post = Post.new&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Once the debugger method is called a debugger shell is started inside the terminal window where the application server was launched, and the cursor will be placed at ruby-debug’s prompt &amp;lt;code&amp;gt;(rdb:n)&amp;lt;/code&amp;gt; where n is the thread number. The prompt will show the next line of code which is waiting to run.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Rails is a relatively new platform for development, it is continually evolving which effectively means debugging is harder. However by leveraging the knowledge of people who have encountered similar errors before we can resolve a subset of the problems, the ones particular to versions of ruby and other gems. We have tools like debugger and application trace to help us solve problems which are specific to our application. To know more about using the debugger, please refer to the Further Reading section of the article.&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
# [http://guides.rubyonrails.org/debugging_rails_applications.html Rails Guide - Debugging Rails Applications]&lt;br /&gt;
# [http://www.sitepoint.com/debug-rails-app-ruby-debug/ Debug your rails app with ruby-debug]&lt;br /&gt;
# [http://rubyforge.org/projects/ruby-debug/ Ruby Forge - Documentation for ruby-debug]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
https://www.youtube.com/watch?v=Ee5vfe0mLb8&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70253</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w-1w65 am</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70253"/>
		<updated>2012-11-18T18:17:10Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* Conclusion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This is a wiki article for the material presented in the Coursera SaaS video series, [https://www.youtube.com/watch?v=Ee5vfe0mLb8 3.13 Debugging by Dr. Armando Fox and Dr. David Patterson]. We aim to cover all the material presented in the video with definitions and examples&lt;br /&gt;
===Why debugging in Rails can be tricky?===&lt;br /&gt;
*We are used to printing the error on the terminal in most applications(Example: [http://www.cplusplus.com/reference/clibrary/cstdio/stderr/ STDERR]). This may not be possible for a web application since its primary form of input and output is through HTTP requests and responses.&lt;br /&gt;
&lt;br /&gt;
*Errors early in flow might manifest itself late.&lt;br /&gt;
Consider the following hierarchy seen in a Rails application:&lt;br /&gt;
 URI -&amp;gt; Route -&amp;gt; Controller -&amp;gt; Model -&amp;gt; View -&amp;gt; Renderer&lt;br /&gt;
 &lt;br /&gt;
Here, something that goes wrong in the controller might not manifest itself until the renderer. The root cause of the error might have happened a long time ago.&lt;br /&gt;
&lt;br /&gt;
*Errors can be hard to localize/reproduce if it affects only some users or routes.&lt;br /&gt;
&lt;br /&gt;
There are several approaches that can be used for debugging based on the mode of operation, that is development mode or production mode:&lt;br /&gt;
 &lt;br /&gt;
'''Printing to terminal:'''This is useful for developers, when they are writing code they can print errors to the terminal and then examine them. We cannot use this approach in production mode.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Logging:''' This is a more general approach to debugging which can be used in both modes. The logged entries are permanent record of what the application is doing. The recorded errors are saved in a log file and can be referenced later.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interactive Debugging:''' Using this tool you can stop the application in its tracks and inspect the state of the variables or other parameters to locate the error.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the various approaches and the modes in which they can be used: &amp;lt;br&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Approach !! Development !! Production&lt;br /&gt;
|-&lt;br /&gt;
| Printing to Terminal || ✓ || &lt;br /&gt;
|-&lt;br /&gt;
| Logging || ✓ || ✓&lt;br /&gt;
|-&lt;br /&gt;
| Interactive Debugging || ✓ || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==RASP==&lt;br /&gt;
Steps to follow when faced with an error can be concisely represented by RASP according to Dr. Fox.&lt;br /&gt;
===What is RASP?===&lt;br /&gt;
RASP is an acronym which briefs the steps which a developer could follow if she were facing an error message. It stands for:&lt;br /&gt;
#'''Read''' the error message.&lt;br /&gt;
#'''Ask''' your colleague  &lt;br /&gt;
#'''Search''' using [http://stackoverflow.com/ Stack Overflow] or any other search engine.&lt;br /&gt;
#'''Post''' on [http://stackoverflow.com/ Stack Overflow] or class forum&lt;br /&gt;
&lt;br /&gt;
Reading the error message carefully is the first step in debugging. The error messages in Rails are incredibly detailed and it gives us a lot of information, reading it carefully can help us locate the file and line in which you are facing the error. But what if the line looks alright to you?&lt;br /&gt;
The next step is to ask a colleague an informed question. In case you are doing pair programming, this is a good step to take. The question has to be of the form &amp;quot;I am trying to do this and I expected to get this but I got this other thing instead of foo.&amp;quot;&lt;br /&gt;
If the previous steps fail then searching using stack overflow or Google is next, especially if its an error which is particular to a version of gems or OS&lt;br /&gt;
In case you don't find a solution to your problem the final step is to get minimal but complete information which reproduces the error message which you are experiencing and post it.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example question and solution from stack overflow:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Ques.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
As we can see the question follows the guidelines explained above. It gives minimal but complete information about the error. It does not give the entire description of the error. It is important to post minimal information so that the person who answers the question can understand your problem quickly.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Ans.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The answer is posted within an hour of posting the question. This shows that posting on stack overflow is a fast way of getting expert help with debugging.&lt;br /&gt;
&lt;br /&gt;
==Understanding Error Messages in Rails==&lt;br /&gt;
&lt;br /&gt;
===Application Trace===&lt;br /&gt;
&lt;br /&gt;
===Full Trace===&lt;br /&gt;
&lt;br /&gt;
===Framework Trace===&lt;br /&gt;
&lt;br /&gt;
===Env Dump and Session Dump===&lt;br /&gt;
===Most Common Error Messages in Ruby===&lt;br /&gt;
&lt;br /&gt;
==Rails Debugger==&lt;br /&gt;
===What is a debugger?===&lt;br /&gt;
Sometimes printing errors to the console or logging is not enough to find out the root cause behind an error message. It is during these times when the debugger is a developer's best friend. The debugger helps us to step forward or backward in the code, execute or skip lines of code, examine the state of a variable or a parameter which has been passed. This will help the developer pinpoint to the actual source of the problem and fix it.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''How to install the debugger?'''&amp;lt;br&amp;gt;&lt;br /&gt;
In Rails, ruby-debug is a gem. We can install it like any other gem. To use the gem in a Rails application we need to add the following line: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;require &amp;quot;ruby-debug&amp;quot;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
in the &amp;lt;code&amp;gt;config/environments/development.rb&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby 1.9, you can use this command to install a compatible version of the debugger gem:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;gem install debugger&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''Running the debugger&amp;lt;br&amp;gt;'''&lt;br /&gt;
To use the debugger in the rails application we need to start the server with the &amp;lt;code&amp;gt;--debugger&amp;lt;/code&amp;gt; option. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;$ rails server --debugger&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we don't do this we would encounter an error like this:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;***** Debugger requested, but was not available: Start server with --debugger to enable *****&amp;lt;/code&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can invoke the debugger from any method by using the &amp;lt;code&amp;gt;debugger&amp;lt;/code&amp;gt; keyword in the method.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class PostController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    debugger&lt;br /&gt;
    @post = Post.new&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Once the debugger method is called a debugger shell is started inside the terminal window where the application server was launched, and the cursor will be placed at ruby-debug’s prompt &amp;lt;code&amp;gt;(rdb:n)&amp;lt;/code&amp;gt; where n is the thread number. The prompt will show the next line of code which is waiting to run.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Rails is a relatively new platform for development, it is continually evolving which effectively means debugging is harder. However by leveraging the knowledge of people who have encountered similar errors before we can resolve a subset of the problems, the ones particular to versions of ruby and other gems. We have tools like debugger and application trace to help us solve problems which are specific to our application. To know more about using the debugger, please refer to the Further Reading section of the article.&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
# [http://guides.rubyonrails.org/debugging_rails_applications.html Rails Guide - Debugging Rails Applications]&lt;br /&gt;
# [http://www.sitepoint.com/debug-rails-app-ruby-debug/ Debug your rails app with ruby-debug]&lt;br /&gt;
# [http://rubyforge.org/projects/ruby-debug/ Ruby Forge - Documentation for ruby-debug]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
https://www.youtube.com/watch?v=Ee5vfe0mLb8&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70244</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w-1w65 am</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70244"/>
		<updated>2012-11-18T18:04:30Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* What is RASP */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This is a wiki article for the material presented in the Coursera SaaS video series, [https://www.youtube.com/watch?v=Ee5vfe0mLb8 3.13 Debugging by Dr. Armando Fox and Dr. David Patterson]. We aim to cover all the material presented in the video with definitions and examples&lt;br /&gt;
===Why debugging in Rails can be tricky?===&lt;br /&gt;
*We are used to printing the error on the terminal in most applications(Example: [http://www.cplusplus.com/reference/clibrary/cstdio/stderr/ STDERR]). This may not be possible for a web application since its primary form of input and output is through HTTP requests and responses.&lt;br /&gt;
&lt;br /&gt;
*Errors early in flow might manifest itself late.&lt;br /&gt;
Consider the following hierarchy seen in a Rails application:&lt;br /&gt;
 URI -&amp;gt; Route -&amp;gt; Controller -&amp;gt; Model -&amp;gt; View -&amp;gt; Renderer&lt;br /&gt;
 &lt;br /&gt;
Here, something that goes wrong in the controller might not manifest itself until the renderer. The root cause of the error might have happened a long time ago.&lt;br /&gt;
&lt;br /&gt;
*Errors can be hard to localize/reproduce if it affects only some users or routes.&lt;br /&gt;
&lt;br /&gt;
There are several approaches that can be used for debugging based on the mode of operation, that is development mode or production mode:&lt;br /&gt;
 &lt;br /&gt;
'''Printing to terminal:'''This is useful for developers, when they are writing code they can print errors to the terminal and then examine them. We cannot use this approach in production mode.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Logging:''' This is a more general approach to debugging which can be used in both modes. The logged entries are permanent record of what the application is doing. The recorded errors are saved in a log file and can be referenced later.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interactive Debugging:''' Using this tool you can stop the application in its tracks and inspect the state of the variables or other parameters to locate the error.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the various approaches and the modes in which they can be used: &amp;lt;br&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Approach !! Development !! Production&lt;br /&gt;
|-&lt;br /&gt;
| Printing to Terminal || ✓ || &lt;br /&gt;
|-&lt;br /&gt;
| Logging || ✓ || ✓&lt;br /&gt;
|-&lt;br /&gt;
| Interactive Debugging || ✓ || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==RASP==&lt;br /&gt;
Steps to follow when faced with an error can be concisely represented by RASP according to Dr. Fox.&lt;br /&gt;
===What is RASP?===&lt;br /&gt;
RASP is an acronym which briefs the steps which a developer could follow if she were facing an error message. It stands for:&lt;br /&gt;
#'''Read''' the error message.&lt;br /&gt;
#'''Ask''' your colleague  &lt;br /&gt;
#'''Search''' using [http://stackoverflow.com/ Stack Overflow] or any other search engine.&lt;br /&gt;
#'''Post''' on [http://stackoverflow.com/ Stack Overflow] or class forum&lt;br /&gt;
&lt;br /&gt;
Reading the error message carefully is the first step in debugging. The error messages in Rails are incredibly detailed and it gives us a lot of information, reading it carefully can help us locate the file and line in which you are facing the error. But what if the line looks alright to you?&lt;br /&gt;
The next step is to ask a colleague an informed question. In case you are doing pair programming, this is a good step to take. The question has to be of the form &amp;quot;I am trying to do this and I expected to get this but I got this other thing instead of foo.&amp;quot;&lt;br /&gt;
If the previous steps fail then searching using stack overflow or Google is next, especially if its an error which is particular to a version of gems or OS&lt;br /&gt;
In case you don't find a solution to your problem the final step is to get minimal but complete information which reproduces the error message which you are experiencing and post it.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example question and solution from stack overflow:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Ques.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
As we can see the question follows the guidelines explained above. It gives minimal but complete information about the error. It does not give the entire description of the error. It is important to post minimal information so that the person who answers the question can understand your problem quickly.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Ans.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The answer is posted within an hour of posting the question. This shows that posting on stack overflow is a fast way of getting expert help with debugging.&lt;br /&gt;
&lt;br /&gt;
==Understanding Error Messages in Rails==&lt;br /&gt;
&lt;br /&gt;
===Application Trace===&lt;br /&gt;
&lt;br /&gt;
===Full Trace===&lt;br /&gt;
&lt;br /&gt;
===Framework Trace===&lt;br /&gt;
&lt;br /&gt;
===Env Dump and Session Dump===&lt;br /&gt;
===Most Common Error Messages in Ruby===&lt;br /&gt;
&lt;br /&gt;
==Rails Debugger==&lt;br /&gt;
===What is a debugger?===&lt;br /&gt;
Sometimes printing errors to the console or logging is not enough to find out the root cause behind an error message. It is during these times when the debugger is a developer's best friend. The debugger helps us to step forward or backward in the code, execute or skip lines of code, examine the state of a variable or a parameter which has been passed. This will help the developer pinpoint to the actual source of the problem and fix it.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''How to install the debugger?'''&amp;lt;br&amp;gt;&lt;br /&gt;
In Rails, ruby-debug is a gem. We can install it like any other gem. To use the gem in a Rails application we need to add the following line: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;require &amp;quot;ruby-debug&amp;quot;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
in the &amp;lt;code&amp;gt;config/environments/development.rb&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby 1.9, you can use this command to install a compatible version of the debugger gem:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;gem install debugger&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''Running the debugger&amp;lt;br&amp;gt;'''&lt;br /&gt;
To use the debugger in the rails application we need to start the server with the &amp;lt;code&amp;gt;--debugger&amp;lt;/code&amp;gt; option. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;$ rails server --debugger&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we don't do this we would encounter an error like this:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;***** Debugger requested, but was not available: Start server with --debugger to enable *****&amp;lt;/code&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can invoke the debugger from any method by using the &amp;lt;code&amp;gt;debugger&amp;lt;/code&amp;gt; keyword in the method.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class PostController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    debugger&lt;br /&gt;
    @post = Post.new&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Once the debugger method is called a debugger shell is started inside the terminal window where the application server was launched, and the cursor will be placed at ruby-debug’s prompt &amp;lt;code&amp;gt;(rdb:n)&amp;lt;/code&amp;gt; where n is the thread number. The prompt will show the next line of code which is waiting to run.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
==Further Reading==&lt;br /&gt;
# [http://guides.rubyonrails.org/debugging_rails_applications.html Rails Guide - Debugging Rails Applications]&lt;br /&gt;
# [http://www.sitepoint.com/debug-rails-app-ruby-debug/ Debug your rails app with ruby-debug]&lt;br /&gt;
# [http://rubyforge.org/projects/ruby-debug/ Ruby Forge - Documentation for ruby-debug]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
https://www.youtube.com/watch?v=Ee5vfe0mLb8&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70243</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w-1w65 am</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70243"/>
		<updated>2012-11-18T18:04:14Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* RASP */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This is a wiki article for the material presented in the Coursera SaaS video series, [https://www.youtube.com/watch?v=Ee5vfe0mLb8 3.13 Debugging by Dr. Armando Fox and Dr. David Patterson]. We aim to cover all the material presented in the video with definitions and examples&lt;br /&gt;
===Why debugging in Rails can be tricky?===&lt;br /&gt;
*We are used to printing the error on the terminal in most applications(Example: [http://www.cplusplus.com/reference/clibrary/cstdio/stderr/ STDERR]). This may not be possible for a web application since its primary form of input and output is through HTTP requests and responses.&lt;br /&gt;
&lt;br /&gt;
*Errors early in flow might manifest itself late.&lt;br /&gt;
Consider the following hierarchy seen in a Rails application:&lt;br /&gt;
 URI -&amp;gt; Route -&amp;gt; Controller -&amp;gt; Model -&amp;gt; View -&amp;gt; Renderer&lt;br /&gt;
 &lt;br /&gt;
Here, something that goes wrong in the controller might not manifest itself until the renderer. The root cause of the error might have happened a long time ago.&lt;br /&gt;
&lt;br /&gt;
*Errors can be hard to localize/reproduce if it affects only some users or routes.&lt;br /&gt;
&lt;br /&gt;
There are several approaches that can be used for debugging based on the mode of operation, that is development mode or production mode:&lt;br /&gt;
 &lt;br /&gt;
'''Printing to terminal:'''This is useful for developers, when they are writing code they can print errors to the terminal and then examine them. We cannot use this approach in production mode.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Logging:''' This is a more general approach to debugging which can be used in both modes. The logged entries are permanent record of what the application is doing. The recorded errors are saved in a log file and can be referenced later.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interactive Debugging:''' Using this tool you can stop the application in its tracks and inspect the state of the variables or other parameters to locate the error.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the various approaches and the modes in which they can be used: &amp;lt;br&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Approach !! Development !! Production&lt;br /&gt;
|-&lt;br /&gt;
| Printing to Terminal || ✓ || &lt;br /&gt;
|-&lt;br /&gt;
| Logging || ✓ || ✓&lt;br /&gt;
|-&lt;br /&gt;
| Interactive Debugging || ✓ || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==RASP==&lt;br /&gt;
Steps to follow when faced with an error can be concisely represented by RASP according to Dr. Fox.&lt;br /&gt;
===What is RASP===&lt;br /&gt;
RASP is an acronym which briefs the steps which a developer could follow if she were facing an error message. It stands for:&lt;br /&gt;
#'''Read''' the error message.&lt;br /&gt;
#'''Ask''' your colleague  &lt;br /&gt;
#'''Search''' using [http://stackoverflow.com/ Stack Overflow] or any other search engine.&lt;br /&gt;
#'''Post''' on [http://stackoverflow.com/ Stack Overflow] or class forum&lt;br /&gt;
&lt;br /&gt;
Reading the error message carefully is the first step in debugging. The error messages in Rails are incredibly detailed and it gives us a lot of information, reading it carefully can help us locate the file and line in which you are facing the error. But what if the line looks alright to you?&lt;br /&gt;
The next step is to ask a colleague an informed question. In case you are doing pair programming, this is a good step to take. The question has to be of the form &amp;quot;I am trying to do this and I expected to get this but I got this other thing instead of foo.&amp;quot;&lt;br /&gt;
If the previous steps fail then searching using stack overflow or Google is next, especially if its an error which is particular to a version of gems or OS&lt;br /&gt;
In case you don't find a solution to your problem the final step is to get minimal but complete information which reproduces the error message which you are experiencing and post it.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example question and solution from stack overflow:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Ques.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
As we can see the question follows the guidelines explained above. It gives minimal but complete information about the error. It does not give the entire description of the error. It is important to post minimal information so that the person who answers the question can understand your problem quickly.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Ans.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The answer is posted within an hour of posting the question. This shows that posting on stack overflow is a fast way of getting expert help with debugging.&lt;br /&gt;
&lt;br /&gt;
==Understanding Error Messages in Rails==&lt;br /&gt;
&lt;br /&gt;
===Application Trace===&lt;br /&gt;
&lt;br /&gt;
===Full Trace===&lt;br /&gt;
&lt;br /&gt;
===Framework Trace===&lt;br /&gt;
&lt;br /&gt;
===Env Dump and Session Dump===&lt;br /&gt;
===Most Common Error Messages in Ruby===&lt;br /&gt;
&lt;br /&gt;
==Rails Debugger==&lt;br /&gt;
===What is a debugger?===&lt;br /&gt;
Sometimes printing errors to the console or logging is not enough to find out the root cause behind an error message. It is during these times when the debugger is a developer's best friend. The debugger helps us to step forward or backward in the code, execute or skip lines of code, examine the state of a variable or a parameter which has been passed. This will help the developer pinpoint to the actual source of the problem and fix it.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''How to install the debugger?'''&amp;lt;br&amp;gt;&lt;br /&gt;
In Rails, ruby-debug is a gem. We can install it like any other gem. To use the gem in a Rails application we need to add the following line: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;require &amp;quot;ruby-debug&amp;quot;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
in the &amp;lt;code&amp;gt;config/environments/development.rb&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby 1.9, you can use this command to install a compatible version of the debugger gem:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;gem install debugger&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''Running the debugger&amp;lt;br&amp;gt;'''&lt;br /&gt;
To use the debugger in the rails application we need to start the server with the &amp;lt;code&amp;gt;--debugger&amp;lt;/code&amp;gt; option. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;$ rails server --debugger&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we don't do this we would encounter an error like this:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;***** Debugger requested, but was not available: Start server with --debugger to enable *****&amp;lt;/code&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can invoke the debugger from any method by using the &amp;lt;code&amp;gt;debugger&amp;lt;/code&amp;gt; keyword in the method.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class PostController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    debugger&lt;br /&gt;
    @post = Post.new&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Once the debugger method is called a debugger shell is started inside the terminal window where the application server was launched, and the cursor will be placed at ruby-debug’s prompt &amp;lt;code&amp;gt;(rdb:n)&amp;lt;/code&amp;gt; where n is the thread number. The prompt will show the next line of code which is waiting to run.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
==Further Reading==&lt;br /&gt;
# [http://guides.rubyonrails.org/debugging_rails_applications.html Rails Guide - Debugging Rails Applications]&lt;br /&gt;
# [http://www.sitepoint.com/debug-rails-app-ruby-debug/ Debug your rails app with ruby-debug]&lt;br /&gt;
# [http://rubyforge.org/projects/ruby-debug/ Ruby Forge - Documentation for ruby-debug]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
https://www.youtube.com/watch?v=Ee5vfe0mLb8&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70239</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w-1w65 am</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70239"/>
		<updated>2012-11-18T18:01:36Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* Rails Debugger */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This is a wiki article for the material presented in the Coursera SaaS video series, [https://www.youtube.com/watch?v=Ee5vfe0mLb8 3.13 Debugging by Dr. Armando Fox and Dr. David Patterson]. We aim to cover all the material presented in the video with definitions and examples&lt;br /&gt;
===Why debugging in Rails can be tricky?===&lt;br /&gt;
*We are used to printing the error on the terminal in most applications(Example: [http://www.cplusplus.com/reference/clibrary/cstdio/stderr/ STDERR]). This may not be possible for a web application since its primary form of input and output is through HTTP requests and responses.&lt;br /&gt;
&lt;br /&gt;
*Errors early in flow might manifest itself late.&lt;br /&gt;
Consider the following hierarchy seen in a Rails application:&lt;br /&gt;
 URI -&amp;gt; Route -&amp;gt; Controller -&amp;gt; Model -&amp;gt; View -&amp;gt; Renderer&lt;br /&gt;
 &lt;br /&gt;
Here, something that goes wrong in the controller might not manifest itself until the renderer. The root cause of the error might have happened a long time ago.&lt;br /&gt;
&lt;br /&gt;
*Errors can be hard to localize/reproduce if it affects only some users or routes.&lt;br /&gt;
&lt;br /&gt;
There are several approaches that can be used for debugging based on the mode of operation, that is development mode or production mode:&lt;br /&gt;
 &lt;br /&gt;
'''Printing to terminal:'''This is useful for developers, when they are writing code they can print errors to the terminal and then examine them. We cannot use this approach in production mode.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Logging:''' This is a more general approach to debugging which can be used in both modes. The logged entries are permanent record of what the application is doing. The recorded errors are saved in a log file and can be referenced later.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interactive Debugging:''' Using this tool you can stop the application in its tracks and inspect the state of the variables or other parameters to locate the error.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the various approaches and the modes in which they can be used: &amp;lt;br&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Approach !! Development !! Production&lt;br /&gt;
|-&lt;br /&gt;
| Printing to Terminal || ✓ || &lt;br /&gt;
|-&lt;br /&gt;
| Logging || ✓ || ✓&lt;br /&gt;
|-&lt;br /&gt;
| Interactive Debugging || ✓ || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==RASP==&lt;br /&gt;
RASP is an acronym which briefs the steps which a developer could follow if she were facing an error message. It stands for:&lt;br /&gt;
#'''Read''' the error message.&lt;br /&gt;
#'''Ask''' your colleague  &lt;br /&gt;
#'''Search''' using [http://stackoverflow.com/ Stack Overflow] or any other search engine.&lt;br /&gt;
#'''Post''' on [http://stackoverflow.com/ Stack Overflow] or class forum&lt;br /&gt;
&lt;br /&gt;
Reading the error message carefully is the first step in debugging. The error messages in Rails are incredibly detailed and it gives us a lot of information, reading it carefully can help us locate the file and line in which you are facing the error. But what if the line looks alright to you?&lt;br /&gt;
The next step is to ask a colleague an informed question. In case you are doing pair programming, this is a good step to take. The question has to be of the form &amp;quot;I am trying to do this and I expected to get this but I got this other thing instead of foo.&amp;quot;&lt;br /&gt;
If the previous steps fail then searching using stack overflow or Google is next, especially if its an error which is particular to a version of gems or OS&lt;br /&gt;
In case you don't find a solution to your problem the final step is to get minimal but complete information which reproduces the error message which you are experiencing and post it.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example question and solution from stack overflow:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Ques.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
As we can see the question follows the guidelines explained above. It gives minimal but complete information about the error. It does not give the entire description of the error. It is important to post minimal information so that the person who answers the question can understand your problem quickly.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Ans.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The answer is posted within an hour of posting the question. This shows that posting on stack overflow is a fast way of getting expert help with debugging.&lt;br /&gt;
&lt;br /&gt;
==Understanding Error Messages in Rails==&lt;br /&gt;
&lt;br /&gt;
===Application Trace===&lt;br /&gt;
&lt;br /&gt;
===Full Trace===&lt;br /&gt;
&lt;br /&gt;
===Framework Trace===&lt;br /&gt;
&lt;br /&gt;
===Env Dump and Session Dump===&lt;br /&gt;
===Most Common Error Messages in Ruby===&lt;br /&gt;
&lt;br /&gt;
==Rails Debugger==&lt;br /&gt;
===What is a debugger?===&lt;br /&gt;
Sometimes printing errors to the console or logging is not enough to find out the root cause behind an error message. It is during these times when the debugger is a developer's best friend. The debugger helps us to step forward or backward in the code, execute or skip lines of code, examine the state of a variable or a parameter which has been passed. This will help the developer pinpoint to the actual source of the problem and fix it.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''How to install the debugger?'''&amp;lt;br&amp;gt;&lt;br /&gt;
In Rails, ruby-debug is a gem. We can install it like any other gem. To use the gem in a Rails application we need to add the following line: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;require &amp;quot;ruby-debug&amp;quot;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
in the &amp;lt;code&amp;gt;config/environments/development.rb&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby 1.9, you can use this command to install a compatible version of the debugger gem:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;gem install debugger&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''Running the debugger&amp;lt;br&amp;gt;'''&lt;br /&gt;
To use the debugger in the rails application we need to start the server with the &amp;lt;code&amp;gt;--debugger&amp;lt;/code&amp;gt; option. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;$ rails server --debugger&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we don't do this we would encounter an error like this:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;***** Debugger requested, but was not available: Start server with --debugger to enable *****&amp;lt;/code&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can invoke the debugger from any method by using the &amp;lt;code&amp;gt;debugger&amp;lt;/code&amp;gt; keyword in the method.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class PostController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    debugger&lt;br /&gt;
    @post = Post.new&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Once the debugger method is called a debugger shell is started inside the terminal window where the application server was launched, and the cursor will be placed at ruby-debug’s prompt &amp;lt;code&amp;gt;(rdb:n)&amp;lt;/code&amp;gt; where n is the thread number. The prompt will show the next line of code which is waiting to run.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
==Further Reading==&lt;br /&gt;
# [http://guides.rubyonrails.org/debugging_rails_applications.html Rails Guide - Debugging Rails Applications]&lt;br /&gt;
# [http://www.sitepoint.com/debug-rails-app-ruby-debug/ Debug your rails app with ruby-debug]&lt;br /&gt;
# [http://rubyforge.org/projects/ruby-debug/ Ruby Forge - Documentation for ruby-debug]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
https://www.youtube.com/watch?v=Ee5vfe0mLb8&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70235</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w-1w65 am</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70235"/>
		<updated>2012-11-18T17:59:45Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This is a wiki article for the material presented in the Coursera SaaS video series, [https://www.youtube.com/watch?v=Ee5vfe0mLb8 3.13 Debugging by Dr. Armando Fox and Dr. David Patterson]. We aim to cover all the material presented in the video with definitions and examples&lt;br /&gt;
===Why debugging in Rails can be tricky?===&lt;br /&gt;
*We are used to printing the error on the terminal in most applications(Example: [http://www.cplusplus.com/reference/clibrary/cstdio/stderr/ STDERR]). This may not be possible for a web application since its primary form of input and output is through HTTP requests and responses.&lt;br /&gt;
&lt;br /&gt;
*Errors early in flow might manifest itself late.&lt;br /&gt;
Consider the following hierarchy seen in a Rails application:&lt;br /&gt;
 URI -&amp;gt; Route -&amp;gt; Controller -&amp;gt; Model -&amp;gt; View -&amp;gt; Renderer&lt;br /&gt;
 &lt;br /&gt;
Here, something that goes wrong in the controller might not manifest itself until the renderer. The root cause of the error might have happened a long time ago.&lt;br /&gt;
&lt;br /&gt;
*Errors can be hard to localize/reproduce if it affects only some users or routes.&lt;br /&gt;
&lt;br /&gt;
There are several approaches that can be used for debugging based on the mode of operation, that is development mode or production mode:&lt;br /&gt;
 &lt;br /&gt;
'''Printing to terminal:'''This is useful for developers, when they are writing code they can print errors to the terminal and then examine them. We cannot use this approach in production mode.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Logging:''' This is a more general approach to debugging which can be used in both modes. The logged entries are permanent record of what the application is doing. The recorded errors are saved in a log file and can be referenced later.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interactive Debugging:''' Using this tool you can stop the application in its tracks and inspect the state of the variables or other parameters to locate the error.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the various approaches and the modes in which they can be used: &amp;lt;br&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Approach !! Development !! Production&lt;br /&gt;
|-&lt;br /&gt;
| Printing to Terminal || ✓ || &lt;br /&gt;
|-&lt;br /&gt;
| Logging || ✓ || ✓&lt;br /&gt;
|-&lt;br /&gt;
| Interactive Debugging || ✓ || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==RASP==&lt;br /&gt;
RASP is an acronym which briefs the steps which a developer could follow if she were facing an error message. It stands for:&lt;br /&gt;
#'''Read''' the error message.&lt;br /&gt;
#'''Ask''' your colleague  &lt;br /&gt;
#'''Search''' using [http://stackoverflow.com/ Stack Overflow] or any other search engine.&lt;br /&gt;
#'''Post''' on [http://stackoverflow.com/ Stack Overflow] or class forum&lt;br /&gt;
&lt;br /&gt;
Reading the error message carefully is the first step in debugging. The error messages in Rails are incredibly detailed and it gives us a lot of information, reading it carefully can help us locate the file and line in which you are facing the error. But what if the line looks alright to you?&lt;br /&gt;
The next step is to ask a colleague an informed question. In case you are doing pair programming, this is a good step to take. The question has to be of the form &amp;quot;I am trying to do this and I expected to get this but I got this other thing instead of foo.&amp;quot;&lt;br /&gt;
If the previous steps fail then searching using stack overflow or Google is next, especially if its an error which is particular to a version of gems or OS&lt;br /&gt;
In case you don't find a solution to your problem the final step is to get minimal but complete information which reproduces the error message which you are experiencing and post it.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example question and solution from stack overflow:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Ques.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
As we can see the question follows the guidelines explained above. It gives minimal but complete information about the error. It does not give the entire description of the error. It is important to post minimal information so that the person who answers the question can understand your problem quickly.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Ans.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The answer is posted within an hour of posting the question. This shows that posting on stack overflow is a fast way of getting expert help with debugging.&lt;br /&gt;
&lt;br /&gt;
==Understanding Error Messages in Rails==&lt;br /&gt;
&lt;br /&gt;
===Application Trace===&lt;br /&gt;
&lt;br /&gt;
===Full Trace===&lt;br /&gt;
&lt;br /&gt;
===Framework Trace===&lt;br /&gt;
&lt;br /&gt;
===Env Dump and Session Dump===&lt;br /&gt;
===Most Common Error Messages in Ruby===&lt;br /&gt;
&lt;br /&gt;
==Rails Debugger==&lt;br /&gt;
===What is a debugger?===&lt;br /&gt;
Sometimes printing errors to the console or logging is not enough to find out the root cause behind an error message. It is during these times when the debugger is a developer's best friend. The debugger helps us to step forward or backward in the code, execute or skip lines of code, examine the state of a variable or a parameter which has been passed. This will help the developer pinpoint to the actual source of the problem and fix it.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''How to install the debugger?'''&amp;lt;br&amp;gt;&lt;br /&gt;
In Rails, ruby-debug is a gem. We can install it like any other gem. To use the gem in a Rails application we need to add the following line: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;require &amp;quot;ruby-debug&amp;quot;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
in the &amp;lt;code&amp;gt;config/environments/development.rb&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby 1.9, you can use this command to install a compatible version of the debugger gem:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;gem install debugger&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''Running the debugger&amp;lt;br&amp;gt;'''&lt;br /&gt;
To use the debugger in the rails application we need to start the server with the &amp;lt;code&amp;gt;--debugger&amp;lt;/code&amp;gt; option. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;$ rails server --debugger&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we don't do this we would encounter an error like this:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;***** Debugger requested, but was not available: Start server with --debugger to enable *****&amp;lt;/code&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can invoke the debugger from any method by using the &amp;lt;code&amp;gt;debugger&amp;lt;/code&amp;gt; keyword in the method.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class PostsController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    debugger&lt;br /&gt;
    @post = Post.new&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Once the debugger method is called a debugger shell is started inside the terminal window where the application server was launched, and the cursor will be placed at ruby-debug’s prompt &amp;lt;code&amp;gt;(rdb:n)&amp;lt;/code&amp;gt; where n is the thread number. The prompt will show the next line of code which is waiting to run.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
==Further Reading==&lt;br /&gt;
# [http://guides.rubyonrails.org/debugging_rails_applications.html Rails Guide - Debugging Rails Applications]&lt;br /&gt;
# [http://www.sitepoint.com/debug-rails-app-ruby-debug/ Debug your rails app with ruby-debug]&lt;br /&gt;
# [http://rubyforge.org/projects/ruby-debug/ Ruby Forge - Documentation for ruby-debug]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
https://www.youtube.com/watch?v=Ee5vfe0mLb8&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70234</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w-1w65 am</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70234"/>
		<updated>2012-11-18T17:59:31Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This is a wiki article for the material presented in the Coursera SaaS video series, [https://www.youtube.com/watch?v=Ee5vfe0mLb8 3.13 Debugging by Dr. Armando Fox and Dr. David Patterson]. We aim to cover all the material presented in the video with definitions and examples&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; &lt;br /&gt;
===Why debugging in Rails can be tricky?===&lt;br /&gt;
*We are used to printing the error on the terminal in most applications(Example: [http://www.cplusplus.com/reference/clibrary/cstdio/stderr/ STDERR]). This may not be possible for a web application since its primary form of input and output is through HTTP requests and responses.&lt;br /&gt;
&lt;br /&gt;
*Errors early in flow might manifest itself late.&lt;br /&gt;
Consider the following hierarchy seen in a Rails application:&lt;br /&gt;
 URI -&amp;gt; Route -&amp;gt; Controller -&amp;gt; Model -&amp;gt; View -&amp;gt; Renderer&lt;br /&gt;
 &lt;br /&gt;
Here, something that goes wrong in the controller might not manifest itself until the renderer. The root cause of the error might have happened a long time ago.&lt;br /&gt;
&lt;br /&gt;
*Errors can be hard to localize/reproduce if it affects only some users or routes.&lt;br /&gt;
&lt;br /&gt;
There are several approaches that can be used for debugging based on the mode of operation, that is development mode or production mode:&lt;br /&gt;
 &lt;br /&gt;
'''Printing to terminal:'''This is useful for developers, when they are writing code they can print errors to the terminal and then examine them. We cannot use this approach in production mode.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Logging:''' This is a more general approach to debugging which can be used in both modes. The logged entries are permanent record of what the application is doing. The recorded errors are saved in a log file and can be referenced later.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interactive Debugging:''' Using this tool you can stop the application in its tracks and inspect the state of the variables or other parameters to locate the error.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the various approaches and the modes in which they can be used: &amp;lt;br&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Approach !! Development !! Production&lt;br /&gt;
|-&lt;br /&gt;
| Printing to Terminal || ✓ || &lt;br /&gt;
|-&lt;br /&gt;
| Logging || ✓ || ✓&lt;br /&gt;
|-&lt;br /&gt;
| Interactive Debugging || ✓ || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==RASP==&lt;br /&gt;
RASP is an acronym which briefs the steps which a developer could follow if she were facing an error message. It stands for:&lt;br /&gt;
#'''Read''' the error message.&lt;br /&gt;
#'''Ask''' your colleague  &lt;br /&gt;
#'''Search''' using [http://stackoverflow.com/ Stack Overflow] or any other search engine.&lt;br /&gt;
#'''Post''' on [http://stackoverflow.com/ Stack Overflow] or class forum&lt;br /&gt;
&lt;br /&gt;
Reading the error message carefully is the first step in debugging. The error messages in Rails are incredibly detailed and it gives us a lot of information, reading it carefully can help us locate the file and line in which you are facing the error. But what if the line looks alright to you?&lt;br /&gt;
The next step is to ask a colleague an informed question. In case you are doing pair programming, this is a good step to take. The question has to be of the form &amp;quot;I am trying to do this and I expected to get this but I got this other thing instead of foo.&amp;quot;&lt;br /&gt;
If the previous steps fail then searching using stack overflow or Google is next, especially if its an error which is particular to a version of gems or OS&lt;br /&gt;
In case you don't find a solution to your problem the final step is to get minimal but complete information which reproduces the error message which you are experiencing and post it.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example question and solution from stack overflow:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Ques.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
As we can see the question follows the guidelines explained above. It gives minimal but complete information about the error. It does not give the entire description of the error. It is important to post minimal information so that the person who answers the question can understand your problem quickly.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Ans.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The answer is posted within an hour of posting the question. This shows that posting on stack overflow is a fast way of getting expert help with debugging.&lt;br /&gt;
&lt;br /&gt;
==Understanding Error Messages in Rails==&lt;br /&gt;
&lt;br /&gt;
===Application Trace===&lt;br /&gt;
&lt;br /&gt;
===Full Trace===&lt;br /&gt;
&lt;br /&gt;
===Framework Trace===&lt;br /&gt;
&lt;br /&gt;
===Env Dump and Session Dump===&lt;br /&gt;
===Most Common Error Messages in Ruby===&lt;br /&gt;
&lt;br /&gt;
==Rails Debugger==&lt;br /&gt;
===What is a debugger?===&lt;br /&gt;
Sometimes printing errors to the console or logging is not enough to find out the root cause behind an error message. It is during these times when the debugger is a developer's best friend. The debugger helps us to step forward or backward in the code, execute or skip lines of code, examine the state of a variable or a parameter which has been passed. This will help the developer pinpoint to the actual source of the problem and fix it.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''How to install the debugger?'''&amp;lt;br&amp;gt;&lt;br /&gt;
In Rails, ruby-debug is a gem. We can install it like any other gem. To use the gem in a Rails application we need to add the following line: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;require &amp;quot;ruby-debug&amp;quot;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
in the &amp;lt;code&amp;gt;config/environments/development.rb&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby 1.9, you can use this command to install a compatible version of the debugger gem:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;gem install debugger&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''Running the debugger&amp;lt;br&amp;gt;'''&lt;br /&gt;
To use the debugger in the rails application we need to start the server with the &amp;lt;code&amp;gt;--debugger&amp;lt;/code&amp;gt; option. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;$ rails server --debugger&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we don't do this we would encounter an error like this:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;***** Debugger requested, but was not available: Start server with --debugger to enable *****&amp;lt;/code&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can invoke the debugger from any method by using the &amp;lt;code&amp;gt;debugger&amp;lt;/code&amp;gt; keyword in the method.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class PostsController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    debugger&lt;br /&gt;
    @post = Post.new&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Once the debugger method is called a debugger shell is started inside the terminal window where the application server was launched, and the cursor will be placed at ruby-debug’s prompt &amp;lt;code&amp;gt;(rdb:n)&amp;lt;/code&amp;gt; where n is the thread number. The prompt will show the next line of code which is waiting to run.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
==Further Reading==&lt;br /&gt;
# [http://guides.rubyonrails.org/debugging_rails_applications.html Rails Guide - Debugging Rails Applications]&lt;br /&gt;
# [http://www.sitepoint.com/debug-rails-app-ruby-debug/ Debug your rails app with ruby-debug]&lt;br /&gt;
# [http://rubyforge.org/projects/ruby-debug/ Ruby Forge - Documentation for ruby-debug]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
https://www.youtube.com/watch?v=Ee5vfe0mLb8&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70231</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w-1w65 am</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70231"/>
		<updated>2012-11-18T17:58:45Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* Further Reading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This is a wiki article for the material presented in the Coursera SaaS video series, [https://www.youtube.com/watch?v=Ee5vfe0mLb8 3.13 Debugging by Dr. Armando Fox and Dr. David Patterson]. We aim to cover all the material presented in the video with definitions and examples&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; &lt;br /&gt;
'''Why debugging in Rails can be tricky?'''&amp;lt;br&amp;gt;&lt;br /&gt;
*We are used to printing the error on the terminal in most applications(Example: [http://www.cplusplus.com/reference/clibrary/cstdio/stderr/ STDERR]). This may not be possible for a web application since its primary form of input and output is through HTTP requests and responses.&lt;br /&gt;
&lt;br /&gt;
*Errors early in flow might manifest itself late.&lt;br /&gt;
Consider the following hierarchy seen in a Rails application:&lt;br /&gt;
 URI -&amp;gt; Route -&amp;gt; Controller -&amp;gt; Model -&amp;gt; View -&amp;gt; Renderer&lt;br /&gt;
 &lt;br /&gt;
Here, something that goes wrong in the controller might not manifest itself until the renderer. The root cause of the error might have happened a long time ago.&lt;br /&gt;
&lt;br /&gt;
*Errors can be hard to localize/reproduce if it affects only some users or routes.&lt;br /&gt;
&lt;br /&gt;
There are several approaches that can be used for debugging based on the mode of operation, that is development mode or production mode:&lt;br /&gt;
 &lt;br /&gt;
'''Printing to terminal:'''This is useful for developers, when they are writing code they can print errors to the terminal and then examine them. We cannot use this approach in production mode.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Logging:''' This is a more general approach to debugging which can be used in both modes. The logged entries are permanent record of what the application is doing. The recorded errors are saved in a log file and can be referenced later.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interactive Debugging:''' Using this tool you can stop the application in its tracks and inspect the state of the variables or other parameters to locate the error.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the various approaches and the modes in which they can be used: &amp;lt;br&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Approach !! Development !! Production&lt;br /&gt;
|-&lt;br /&gt;
| Printing to Terminal || ✓ || &lt;br /&gt;
|-&lt;br /&gt;
| Logging || ✓ || ✓&lt;br /&gt;
|-&lt;br /&gt;
| Interactive Debugging || ✓ || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==RASP==&lt;br /&gt;
RASP is an acronym which briefs the steps which a developer could follow if she were facing an error message. It stands for:&lt;br /&gt;
#'''Read''' the error message.&lt;br /&gt;
#'''Ask''' your colleague  &lt;br /&gt;
#'''Search''' using [http://stackoverflow.com/ Stack Overflow] or any other search engine.&lt;br /&gt;
#'''Post''' on [http://stackoverflow.com/ Stack Overflow] or class forum&lt;br /&gt;
&lt;br /&gt;
Reading the error message carefully is the first step in debugging. The error messages in Rails are incredibly detailed and it gives us a lot of information, reading it carefully can help us locate the file and line in which you are facing the error. But what if the line looks alright to you?&lt;br /&gt;
The next step is to ask a colleague an informed question. In case you are doing pair programming, this is a good step to take. The question has to be of the form &amp;quot;I am trying to do this and I expected to get this but I got this other thing instead of foo.&amp;quot;&lt;br /&gt;
If the previous steps fail then searching using stack overflow or Google is next, especially if its an error which is particular to a version of gems or OS&lt;br /&gt;
In case you don't find a solution to your problem the final step is to get minimal but complete information which reproduces the error message which you are experiencing and post it.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example question and solution from stack overflow:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Ques.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
As we can see the question follows the guidelines explained above. It gives minimal but complete information about the error. It does not give the entire description of the error. It is important to post minimal information so that the person who answers the question can understand your problem quickly.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Ans.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The answer is posted within an hour of posting the question. This shows that posting on stack overflow is a fast way of getting expert help with debugging.&lt;br /&gt;
&lt;br /&gt;
==Understanding Error Messages in Rails==&lt;br /&gt;
&lt;br /&gt;
===Application Trace===&lt;br /&gt;
&lt;br /&gt;
===Full Trace===&lt;br /&gt;
&lt;br /&gt;
===Framework Trace===&lt;br /&gt;
&lt;br /&gt;
===Env Dump and Session Dump===&lt;br /&gt;
===Most Common Error Messages in Ruby===&lt;br /&gt;
&lt;br /&gt;
==Rails Debugger==&lt;br /&gt;
===What is a debugger?===&lt;br /&gt;
Sometimes printing errors to the console or logging is not enough to find out the root cause behind an error message. It is during these times when the debugger is a developer's best friend. The debugger helps us to step forward or backward in the code, execute or skip lines of code, examine the state of a variable or a parameter which has been passed. This will help the developer pinpoint to the actual source of the problem and fix it.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''How to install the debugger?'''&amp;lt;br&amp;gt;&lt;br /&gt;
In Rails, ruby-debug is a gem. We can install it like any other gem. To use the gem in a Rails application we need to add the following line: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;require &amp;quot;ruby-debug&amp;quot;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
in the &amp;lt;code&amp;gt;config/environments/development.rb&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby 1.9, you can use this command to install a compatible version of the debugger gem:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;gem install debugger&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''Running the debugger&amp;lt;br&amp;gt;'''&lt;br /&gt;
To use the debugger in the rails application we need to start the server with the &amp;lt;code&amp;gt;--debugger&amp;lt;/code&amp;gt; option. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;$ rails server --debugger&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we don't do this we would encounter an error like this:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;***** Debugger requested, but was not available: Start server with --debugger to enable *****&amp;lt;/code&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can invoke the debugger from any method by using the &amp;lt;code&amp;gt;debugger&amp;lt;/code&amp;gt; keyword in the method.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class PostsController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    debugger&lt;br /&gt;
    @post = Post.new&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Once the debugger method is called a debugger shell is started inside the terminal window where the application server was launched, and the cursor will be placed at ruby-debug’s prompt &amp;lt;code&amp;gt;(rdb:n)&amp;lt;/code&amp;gt; where n is the thread number. The prompt will show the next line of code which is waiting to run.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
==Further Reading==&lt;br /&gt;
# [http://guides.rubyonrails.org/debugging_rails_applications.html Rails Guide - Debugging Rails Applications]&lt;br /&gt;
# [http://www.sitepoint.com/debug-rails-app-ruby-debug/ Debug your rails app with ruby-debug]&lt;br /&gt;
# [http://rubyforge.org/projects/ruby-debug/ Ruby Forge - Documentation for ruby-debug]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
https://www.youtube.com/watch?v=Ee5vfe0mLb8&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70227</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w-1w65 am</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70227"/>
		<updated>2012-11-18T17:54:26Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* What is a debugger? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This is a wiki article for the material presented in the Coursera SaaS video series, [https://www.youtube.com/watch?v=Ee5vfe0mLb8 3.13 Debugging by Dr. Armando Fox and Dr. David Patterson]. We aim to cover all the material presented in the video with definitions and examples&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; &lt;br /&gt;
'''Why debugging in Rails can be tricky?'''&amp;lt;br&amp;gt;&lt;br /&gt;
*We are used to printing the error on the terminal in most applications(Example: [http://www.cplusplus.com/reference/clibrary/cstdio/stderr/ STDERR]). This may not be possible for a web application since its primary form of input and output is through HTTP requests and responses.&lt;br /&gt;
&lt;br /&gt;
*Errors early in flow might manifest itself late.&lt;br /&gt;
Consider the following hierarchy seen in a Rails application:&lt;br /&gt;
 URI -&amp;gt; Route -&amp;gt; Controller -&amp;gt; Model -&amp;gt; View -&amp;gt; Renderer&lt;br /&gt;
 &lt;br /&gt;
Here, something that goes wrong in the controller might not manifest itself until the renderer. The root cause of the error might have happened a long time ago.&lt;br /&gt;
&lt;br /&gt;
*Errors can be hard to localize/reproduce if it affects only some users or routes.&lt;br /&gt;
&lt;br /&gt;
There are several approaches that can be used for debugging based on the mode of operation, that is development mode or production mode:&lt;br /&gt;
 &lt;br /&gt;
'''Printing to terminal:'''This is useful for developers, when they are writing code they can print errors to the terminal and then examine them. We cannot use this approach in production mode.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Logging:''' This is a more general approach to debugging which can be used in both modes. The logged entries are permanent record of what the application is doing. The recorded errors are saved in a log file and can be referenced later.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interactive Debugging:''' Using this tool you can stop the application in its tracks and inspect the state of the variables or other parameters to locate the error.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the various approaches and the modes in which they can be used: &amp;lt;br&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Approach !! Development !! Production&lt;br /&gt;
|-&lt;br /&gt;
| Printing to Terminal || ✓ || &lt;br /&gt;
|-&lt;br /&gt;
| Logging || ✓ || ✓&lt;br /&gt;
|-&lt;br /&gt;
| Interactive Debugging || ✓ || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==RASP==&lt;br /&gt;
RASP is an acronym which briefs the steps which a developer could follow if she were facing an error message. It stands for:&lt;br /&gt;
#'''Read''' the error message.&lt;br /&gt;
#'''Ask''' your colleague  &lt;br /&gt;
#'''Search''' using [http://stackoverflow.com/ Stack Overflow] or any other search engine.&lt;br /&gt;
#'''Post''' on [http://stackoverflow.com/ Stack Overflow] or class forum&lt;br /&gt;
&lt;br /&gt;
Reading the error message carefully is the first step in debugging. The error messages in Rails are incredibly detailed and it gives us a lot of information, reading it carefully can help us locate the file and line in which you are facing the error. But what if the line looks alright to you?&lt;br /&gt;
The next step is to ask a colleague an informed question. In case you are doing pair programming, this is a good step to take. The question has to be of the form &amp;quot;I am trying to do this and I expected to get this but I got this other thing instead of foo.&amp;quot;&lt;br /&gt;
If the previous steps fail then searching using stack overflow or Google is next, especially if its an error which is particular to a version of gems or OS&lt;br /&gt;
In case you don't find a solution to your problem the final step is to get minimal but complete information which reproduces the error message which you are experiencing and post it.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example question and solution from stack overflow:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Ques.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
As we can see the question follows the guidelines explained above. It gives minimal but complete information about the error. It does not give the entire description of the error. It is important to post minimal information so that the person who answers the question can understand your problem quickly.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Ans.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The answer is posted within an hour of posting the question. This shows that posting on stack overflow is a fast way of getting expert help with debugging.&lt;br /&gt;
&lt;br /&gt;
==Understanding Error Messages in Rails==&lt;br /&gt;
&lt;br /&gt;
===Application Trace===&lt;br /&gt;
&lt;br /&gt;
===Full Trace===&lt;br /&gt;
&lt;br /&gt;
===Framework Trace===&lt;br /&gt;
&lt;br /&gt;
===Env Dump and Session Dump===&lt;br /&gt;
===Most Common Error Messages in Ruby===&lt;br /&gt;
&lt;br /&gt;
==Rails Debugger==&lt;br /&gt;
===What is a debugger?===&lt;br /&gt;
Sometimes printing errors to the console or logging is not enough to find out the root cause behind an error message. It is during these times when the debugger is a developer's best friend. The debugger helps us to step forward or backward in the code, execute or skip lines of code, examine the state of a variable or a parameter which has been passed. This will help the developer pinpoint to the actual source of the problem and fix it.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''How to install the debugger?'''&amp;lt;br&amp;gt;&lt;br /&gt;
In Rails, ruby-debug is a gem. We can install it like any other gem. To use the gem in a Rails application we need to add the following line: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;require &amp;quot;ruby-debug&amp;quot;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
in the &amp;lt;code&amp;gt;config/environments/development.rb&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby 1.9, you can use this command to install a compatible version of the debugger gem:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;gem install debugger&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''Running the debugger&amp;lt;br&amp;gt;'''&lt;br /&gt;
To use the debugger in the rails application we need to start the server with the &amp;lt;code&amp;gt;--debugger&amp;lt;/code&amp;gt; option. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;$ rails server --debugger&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we don't do this we would encounter an error like this:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;***** Debugger requested, but was not available: Start server with --debugger to enable *****&amp;lt;/code&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can invoke the debugger from any method by using the &amp;lt;code&amp;gt;debugger&amp;lt;/code&amp;gt; keyword in the method.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class PostsController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    debugger&lt;br /&gt;
    @post = Post.new&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Once the debugger method is called a debugger shell is started inside the terminal window where the application server was launched, and the cursor will be placed at ruby-debug’s prompt &amp;lt;code&amp;gt;(rdb:n)&amp;lt;/code&amp;gt; where n is the thread number. The prompt will show the next line of code which is waiting to run.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
==Further Reading==&lt;br /&gt;
==References==&lt;br /&gt;
https://www.youtube.com/watch?v=Ee5vfe0mLb8&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70224</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w-1w65 am</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70224"/>
		<updated>2012-11-18T17:50:51Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* Rails Debugger */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This is a wiki article for the material presented in the Coursera SaaS video series, [https://www.youtube.com/watch?v=Ee5vfe0mLb8 3.13 Debugging by Dr. Armando Fox and Dr. David Patterson]. We aim to cover all the material presented in the video with definitions and examples&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; &lt;br /&gt;
'''Why debugging in Rails can be tricky?'''&amp;lt;br&amp;gt;&lt;br /&gt;
*We are used to printing the error on the terminal in most applications(Example: [http://www.cplusplus.com/reference/clibrary/cstdio/stderr/ STDERR]). This may not be possible for a web application since its primary form of input and output is through HTTP requests and responses.&lt;br /&gt;
&lt;br /&gt;
*Errors early in flow might manifest itself late.&lt;br /&gt;
Consider the following hierarchy seen in a Rails application:&lt;br /&gt;
 URI -&amp;gt; Route -&amp;gt; Controller -&amp;gt; Model -&amp;gt; View -&amp;gt; Renderer&lt;br /&gt;
 &lt;br /&gt;
Here, something that goes wrong in the controller might not manifest itself until the renderer. The root cause of the error might have happened a long time ago.&lt;br /&gt;
&lt;br /&gt;
*Errors can be hard to localize/reproduce if it affects only some users or routes.&lt;br /&gt;
&lt;br /&gt;
There are several approaches that can be used for debugging based on the mode of operation, that is development mode or production mode:&lt;br /&gt;
 &lt;br /&gt;
'''Printing to terminal:'''This is useful for developers, when they are writing code they can print errors to the terminal and then examine them. We cannot use this approach in production mode.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Logging:''' This is a more general approach to debugging which can be used in both modes. The logged entries are permanent record of what the application is doing. The recorded errors are saved in a log file and can be referenced later.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interactive Debugging:''' Using this tool you can stop the application in its tracks and inspect the state of the variables or other parameters to locate the error.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the various approaches and the modes in which they can be used: &amp;lt;br&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Approach !! Development !! Production&lt;br /&gt;
|-&lt;br /&gt;
| Printing to Terminal || ✓ || &lt;br /&gt;
|-&lt;br /&gt;
| Logging || ✓ || ✓&lt;br /&gt;
|-&lt;br /&gt;
| Interactive Debugging || ✓ || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==RASP==&lt;br /&gt;
RASP is an acronym which briefs the steps which a developer could follow if she were facing an error message. It stands for:&lt;br /&gt;
#'''Read''' the error message.&lt;br /&gt;
#'''Ask''' your colleague  &lt;br /&gt;
#'''Search''' using [http://stackoverflow.com/ Stack Overflow] or any other search engine.&lt;br /&gt;
#'''Post''' on [http://stackoverflow.com/ Stack Overflow] or class forum&lt;br /&gt;
&lt;br /&gt;
Reading the error message carefully is the first step in debugging. The error messages in Rails are incredibly detailed and it gives us a lot of information, reading it carefully can help us locate the file and line in which you are facing the error. But what if the line looks alright to you?&lt;br /&gt;
The next step is to ask a colleague an informed question. In case you are doing pair programming, this is a good step to take. The question has to be of the form &amp;quot;I am trying to do this and I expected to get this but I got this other thing instead of foo.&amp;quot;&lt;br /&gt;
If the previous steps fail then searching using stack overflow or Google is next, especially if its an error which is particular to a version of gems or OS&lt;br /&gt;
In case you don't find a solution to your problem the final step is to get minimal but complete information which reproduces the error message which you are experiencing and post it.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example question and solution from stack overflow:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Ques.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
As we can see the question follows the guidelines explained above. It gives minimal but complete information about the error. It does not give the entire description of the error. It is important to post minimal information so that the person who answers the question can understand your problem quickly.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Ans.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The answer is posted within an hour of posting the question. This shows that posting on stack overflow is a fast way of getting expert help with debugging.&lt;br /&gt;
&lt;br /&gt;
==Understanding Error Messages in Rails==&lt;br /&gt;
&lt;br /&gt;
===Application Trace===&lt;br /&gt;
&lt;br /&gt;
===Full Trace===&lt;br /&gt;
&lt;br /&gt;
===Framework Trace===&lt;br /&gt;
&lt;br /&gt;
===Env Dump and Session Dump===&lt;br /&gt;
===Most Common Error Messages in Ruby===&lt;br /&gt;
&lt;br /&gt;
==Rails Debugger==&lt;br /&gt;
===What is a debugger?===&lt;br /&gt;
Sometimes printing errors to the console or logging is not enough to find out the root cause behind an error message. It is during these times when the debugger is a developer's best friend. The debugger helps us to step forward or backward in the code, execute or skip lines of code, examine the state of a variable or a parameter which has been passed. This will help the developer pinpoint to the actual source of the problem and fix it.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''How to install the debugger?'''&amp;lt;br&amp;gt;&lt;br /&gt;
In Rails, ruby-debug is a gem. We can install it like any other gem. To use the gem in a Rails application we need to add the following line: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;require &amp;quot;ruby-debug&amp;quot;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
in the &amp;lt;code&amp;gt;config/environments/development.rb&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby 1.9, you can use this command to install a compatible version of the debugger gem:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;gem install debugger&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''Running the debugger&amp;lt;br&amp;gt;'''&lt;br /&gt;
To use the debugger in the rails application we need to start the server with the &amp;lt;code&amp;gt;--debugger&amp;lt;/code&amp;gt; option. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;$ rails server --debugger&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we don't do this we would encounter an error like this:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;***** Debugger requested, but was not available: Start server with --debugger to enable *****&amp;lt;/code&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can invoke the debugger from any method by using the &amp;lt;code&amp;gt;debugger&amp;lt;/code&amp;gt; keyword in the method.&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class PostsController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    debugger&lt;br /&gt;
    @post = Post.new&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
==Further Reading==&lt;br /&gt;
==References==&lt;br /&gt;
https://www.youtube.com/watch?v=Ee5vfe0mLb8&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70222</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w-1w65 am</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70222"/>
		<updated>2012-11-18T17:48:34Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* Interactive Debugger */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This is a wiki article for the material presented in the Coursera SaaS video series, [https://www.youtube.com/watch?v=Ee5vfe0mLb8 3.13 Debugging by Dr. Armando Fox and Dr. David Patterson]. We aim to cover all the material presented in the video with definitions and examples&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; &lt;br /&gt;
'''Why debugging in Rails can be tricky?'''&amp;lt;br&amp;gt;&lt;br /&gt;
*We are used to printing the error on the terminal in most applications(Example: [http://www.cplusplus.com/reference/clibrary/cstdio/stderr/ STDERR]). This may not be possible for a web application since its primary form of input and output is through HTTP requests and responses.&lt;br /&gt;
&lt;br /&gt;
*Errors early in flow might manifest itself late.&lt;br /&gt;
Consider the following hierarchy seen in a Rails application:&lt;br /&gt;
 URI -&amp;gt; Route -&amp;gt; Controller -&amp;gt; Model -&amp;gt; View -&amp;gt; Renderer&lt;br /&gt;
 &lt;br /&gt;
Here, something that goes wrong in the controller might not manifest itself until the renderer. The root cause of the error might have happened a long time ago.&lt;br /&gt;
&lt;br /&gt;
*Errors can be hard to localize/reproduce if it affects only some users or routes.&lt;br /&gt;
&lt;br /&gt;
There are several approaches that can be used for debugging based on the mode of operation, that is development mode or production mode:&lt;br /&gt;
 &lt;br /&gt;
'''Printing to terminal:'''This is useful for developers, when they are writing code they can print errors to the terminal and then examine them. We cannot use this approach in production mode.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Logging:''' This is a more general approach to debugging which can be used in both modes. The logged entries are permanent record of what the application is doing. The recorded errors are saved in a log file and can be referenced later.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interactive Debugging:''' Using this tool you can stop the application in its tracks and inspect the state of the variables or other parameters to locate the error.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the various approaches and the modes in which they can be used: &amp;lt;br&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Approach !! Development !! Production&lt;br /&gt;
|-&lt;br /&gt;
| Printing to Terminal || ✓ || &lt;br /&gt;
|-&lt;br /&gt;
| Logging || ✓ || ✓&lt;br /&gt;
|-&lt;br /&gt;
| Interactive Debugging || ✓ || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==RASP==&lt;br /&gt;
RASP is an acronym which briefs the steps which a developer could follow if she were facing an error message. It stands for:&lt;br /&gt;
#'''Read''' the error message.&lt;br /&gt;
#'''Ask''' your colleague  &lt;br /&gt;
#'''Search''' using [http://stackoverflow.com/ Stack Overflow] or any other search engine.&lt;br /&gt;
#'''Post''' on [http://stackoverflow.com/ Stack Overflow] or class forum&lt;br /&gt;
&lt;br /&gt;
Reading the error message carefully is the first step in debugging. The error messages in Rails are incredibly detailed and it gives us a lot of information, reading it carefully can help us locate the file and line in which you are facing the error. But what if the line looks alright to you?&lt;br /&gt;
The next step is to ask a colleague an informed question. In case you are doing pair programming, this is a good step to take. The question has to be of the form &amp;quot;I am trying to do this and I expected to get this but I got this other thing instead of foo.&amp;quot;&lt;br /&gt;
If the previous steps fail then searching using stack overflow or Google is next, especially if its an error which is particular to a version of gems or OS&lt;br /&gt;
In case you don't find a solution to your problem the final step is to get minimal but complete information which reproduces the error message which you are experiencing and post it.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example question and solution from stack overflow:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Ques.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
As we can see the question follows the guidelines explained above. It gives minimal but complete information about the error. It does not give the entire description of the error. It is important to post minimal information so that the person who answers the question can understand your problem quickly.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Ans.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The answer is posted within an hour of posting the question. This shows that posting on stack overflow is a fast way of getting expert help with debugging.&lt;br /&gt;
&lt;br /&gt;
==Understanding Error Messages in Rails==&lt;br /&gt;
&lt;br /&gt;
===Application Trace===&lt;br /&gt;
&lt;br /&gt;
===Full Trace===&lt;br /&gt;
&lt;br /&gt;
===Framework Trace===&lt;br /&gt;
&lt;br /&gt;
===Env Dump and Session Dump===&lt;br /&gt;
===Most Common Error Messages in Ruby===&lt;br /&gt;
&lt;br /&gt;
==Rails Debugger==&lt;br /&gt;
===What is a debugger?===&lt;br /&gt;
Sometimes printing errors to the console or logging is not enough to find out the root cause behind an error message. It is during these times when the debugger is a developer's best friend. The debugger helps us to step forward or backward in the code, execute or skip lines of code, examine the state of a variable or a parameter which has been passed. This will help the developer pinpoint to the actual source of the problem and fix it.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''How to install the debugger?'''&amp;lt;br&amp;gt;&lt;br /&gt;
In Rails, ruby-debug is a gem. We can install it like any other gem. To use the gem in a Rails application we need to add the following line: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;require &amp;quot;ruby-debug&amp;quot;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
in the &amp;lt;code&amp;gt;config/environments/development.rb&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To use the debugger in the rails application we need to start the server with the &amp;lt;code&amp;gt;--debugger&amp;lt;/code&amp;gt; option. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;$ rails server --debugger&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we don't do this we would encounter an error like this:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;***** Debugger requested, but was not available: Start server with --debugger to enable *****&amp;lt;/code&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can invoke the debugger from any method by using the &amp;lt;code&amp;gt;debugger&amp;lt;/code&amp;gt; keyword in the method.&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class PostsController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    debugger&lt;br /&gt;
    @post = Post.new&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
==Further Reading==&lt;br /&gt;
==References==&lt;br /&gt;
https://www.youtube.com/watch?v=Ee5vfe0mLb8&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70220</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w-1w65 am</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70220"/>
		<updated>2012-11-18T17:47:52Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* What is an interactive debugger? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This is a wiki article for the material presented in the Coursera SaaS video series, [https://www.youtube.com/watch?v=Ee5vfe0mLb8 3.13 Debugging by Dr. Armando Fox and Dr. David Patterson]. We aim to cover all the material presented in the video with definitions and examples&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; &lt;br /&gt;
'''Why debugging in Rails can be tricky?'''&amp;lt;br&amp;gt;&lt;br /&gt;
*We are used to printing the error on the terminal in most applications(Example: [http://www.cplusplus.com/reference/clibrary/cstdio/stderr/ STDERR]). This may not be possible for a web application since its primary form of input and output is through HTTP requests and responses.&lt;br /&gt;
&lt;br /&gt;
*Errors early in flow might manifest itself late.&lt;br /&gt;
Consider the following hierarchy seen in a Rails application:&lt;br /&gt;
 URI -&amp;gt; Route -&amp;gt; Controller -&amp;gt; Model -&amp;gt; View -&amp;gt; Renderer&lt;br /&gt;
 &lt;br /&gt;
Here, something that goes wrong in the controller might not manifest itself until the renderer. The root cause of the error might have happened a long time ago.&lt;br /&gt;
&lt;br /&gt;
*Errors can be hard to localize/reproduce if it affects only some users or routes.&lt;br /&gt;
&lt;br /&gt;
There are several approaches that can be used for debugging based on the mode of operation, that is development mode or production mode:&lt;br /&gt;
 &lt;br /&gt;
'''Printing to terminal:'''This is useful for developers, when they are writing code they can print errors to the terminal and then examine them. We cannot use this approach in production mode.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Logging:''' This is a more general approach to debugging which can be used in both modes. The logged entries are permanent record of what the application is doing. The recorded errors are saved in a log file and can be referenced later.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interactive Debugging:''' Using this tool you can stop the application in its tracks and inspect the state of the variables or other parameters to locate the error.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the various approaches and the modes in which they can be used: &amp;lt;br&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Approach !! Development !! Production&lt;br /&gt;
|-&lt;br /&gt;
| Printing to Terminal || ✓ || &lt;br /&gt;
|-&lt;br /&gt;
| Logging || ✓ || ✓&lt;br /&gt;
|-&lt;br /&gt;
| Interactive Debugging || ✓ || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==RASP==&lt;br /&gt;
RASP is an acronym which briefs the steps which a developer could follow if she were facing an error message. It stands for:&lt;br /&gt;
#'''Read''' the error message.&lt;br /&gt;
#'''Ask''' your colleague  &lt;br /&gt;
#'''Search''' using [http://stackoverflow.com/ Stack Overflow] or any other search engine.&lt;br /&gt;
#'''Post''' on [http://stackoverflow.com/ Stack Overflow] or class forum&lt;br /&gt;
&lt;br /&gt;
Reading the error message carefully is the first step in debugging. The error messages in Rails are incredibly detailed and it gives us a lot of information, reading it carefully can help us locate the file and line in which you are facing the error. But what if the line looks alright to you?&lt;br /&gt;
The next step is to ask a colleague an informed question. In case you are doing pair programming, this is a good step to take. The question has to be of the form &amp;quot;I am trying to do this and I expected to get this but I got this other thing instead of foo.&amp;quot;&lt;br /&gt;
If the previous steps fail then searching using stack overflow or Google is next, especially if its an error which is particular to a version of gems or OS&lt;br /&gt;
In case you don't find a solution to your problem the final step is to get minimal but complete information which reproduces the error message which you are experiencing and post it.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example question and solution from stack overflow:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Ques.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
As we can see the question follows the guidelines explained above. It gives minimal but complete information about the error. It does not give the entire description of the error. It is important to post minimal information so that the person who answers the question can understand your problem quickly.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Ans.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The answer is posted within an hour of posting the question. This shows that posting on stack overflow is a fast way of getting expert help with debugging.&lt;br /&gt;
&lt;br /&gt;
==Understanding Error Messages in Rails==&lt;br /&gt;
&lt;br /&gt;
===Application Trace===&lt;br /&gt;
&lt;br /&gt;
===Full Trace===&lt;br /&gt;
&lt;br /&gt;
===Framework Trace===&lt;br /&gt;
&lt;br /&gt;
===Env Dump and Session Dump===&lt;br /&gt;
===Most Common Error Messages in Ruby===&lt;br /&gt;
&lt;br /&gt;
==Interactive Debugger==&lt;br /&gt;
===What is a debugger?===&lt;br /&gt;
Sometimes printing errors to the console or logging is not enough to find out the root cause behind an error message. It is during these times when the debugger is a developer's best friend. The debugger helps us to step forward or backward in the code, execute or skip lines of code, examine the state of a variable or a parameter which has been passed. This will help the developer pinpoint to the actual source of the problem and fix it.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''How to install the debugger?'''&amp;lt;br&amp;gt;&lt;br /&gt;
In Rails, ruby-debug is a gem. We can install it like any other gem. To use the gem in a Rails application we need to add the following line: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;require &amp;quot;ruby-debug&amp;quot;&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
in the &amp;lt;code&amp;gt;config/environments/development.rb&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To use the debugger in the rails application we need to start the server with the &amp;lt;code&amp;gt;--debugger&amp;lt;/code&amp;gt; option. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;$ rails server --debugger&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we don't do this we would encounter an error like this:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;***** Debugger requested, but was not available: Start server with --debugger to enable *****&amp;lt;/code&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can invoke the debugger from any method by using the &amp;lt;code&amp;gt;debugger&amp;lt;/code&amp;gt; keyword in the method.&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class PostsController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    debugger&lt;br /&gt;
    @post = Post.new&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
==Further Reading==&lt;br /&gt;
==References==&lt;br /&gt;
https://www.youtube.com/watch?v=Ee5vfe0mLb8&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70001</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w-1w65 am</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70001"/>
		<updated>2012-11-18T01:17:37Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This is a wiki article for the material presented in the Coursera SaaS video series, [https://www.youtube.com/watch?v=Ee5vfe0mLb8 3.13 Debugging by Dr. Armando Fox and Dr. David Patterson]. We aim to cover all the material presented in the video with definitions and examples&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; &lt;br /&gt;
'''Why debugging in Rails can be tricky?'''&amp;lt;br&amp;gt;&lt;br /&gt;
*We are used to printing the error on the terminal in most applications(Example: [http://www.cplusplus.com/reference/clibrary/cstdio/stderr/ STDERR]). This may not be possible for a web application since its primary form of input and output is through HTTP requests and responses.&lt;br /&gt;
&lt;br /&gt;
*Errors early in flow might manifest itself late.&lt;br /&gt;
Consider the following hierarchy seen in a Rails application:&lt;br /&gt;
 URI -&amp;gt; Route -&amp;gt; Controller -&amp;gt; Model -&amp;gt; View -&amp;gt; Renderer&lt;br /&gt;
 &lt;br /&gt;
Here, something that goes wrong in the controller might not manifest itself until the renderer. The root cause of the error might have happened a long time ago.&lt;br /&gt;
&lt;br /&gt;
*Errors can be hard to localize/reproduce if it affects only some users or routes.&lt;br /&gt;
&lt;br /&gt;
There are several approaches that can be used for debugging based on the mode of operation, that is development mode or production mode:&lt;br /&gt;
 &lt;br /&gt;
'''Printing to terminal:'''This is useful for developers, when they are writing code they can print errors to the terminal and then examine them. We cannot use this approach in production mode.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Logging:''' This is a more general approach to debugging which can be used in both modes. The logged entries are permanent record of what the application is doing. The recorded errors are saved in a log file and can be referenced later.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interactive Debugging:''' Using this tool you can stop the application in its tracks and inspect the state of the variables or other parameters to locate the error.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the various approaches and the modes in which they can be used: &amp;lt;br&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Approach !! Development !! Production&lt;br /&gt;
|-&lt;br /&gt;
| Printing to Terminal || ✓ || &lt;br /&gt;
|-&lt;br /&gt;
| Logging || ✓ || ✓&lt;br /&gt;
|-&lt;br /&gt;
| Interactive Debugging || ✓ || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==RASP==&lt;br /&gt;
RASP is an acronym which briefs the steps which a developer could follow if she were facing an error message. It stands for:&lt;br /&gt;
#'''Read''' the error message.&lt;br /&gt;
#'''Ask''' your colleague  &lt;br /&gt;
#'''Search''' using [http://stackoverflow.com/ Stack Overflow] or any other search engine.&lt;br /&gt;
#'''Post''' on [http://stackoverflow.com/ Stack Overflow] or class forum&lt;br /&gt;
&lt;br /&gt;
Reading the error message carefully is the first step in debugging. The error messages in Rails are incredibly detailed and it gives us a lot of information, reading it carefully can help us locate the file and line in which you are facing the error. But what if the line looks alright to you?&lt;br /&gt;
The next step is to ask a colleague an informed question. In case you are doing pair programming, this is a good step to take. The question has to be of the form &amp;quot;I am trying to do this and I expected to get this but I got this other thing instead of foo.&amp;quot;&lt;br /&gt;
If the previous steps fail then searching using stack overflow or Google is next, especially if its an error which is particular to a version of gems or OS&lt;br /&gt;
In case you don't find a solution to your problem the final step is to get minimal but complete information which reproduces the error message which you are experiencing and post it.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example question and solution from stack overflow:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Ques.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
As we can see the question follows the guidelines explained above. It gives minimal but complete information about the error. It does not give the entire description of the error. It is important to post minimal information so that the person who answers the question can understand your problem quickly.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Ans.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The answer is posted within an hour of posting the question. This shows that posting on stack overflow is a fast way of getting expert help with debugging.&lt;br /&gt;
&lt;br /&gt;
==Understanding Error Messages in Rails==&lt;br /&gt;
&lt;br /&gt;
===Application Trace===&lt;br /&gt;
&lt;br /&gt;
===Full Trace===&lt;br /&gt;
&lt;br /&gt;
===Framework Trace===&lt;br /&gt;
&lt;br /&gt;
===Env Dump and Session Dump===&lt;br /&gt;
===Most Common Error Messages in Ruby===&lt;br /&gt;
&lt;br /&gt;
==Interactive Debugger==&lt;br /&gt;
===What is an interactive debugger?===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
==Further Reading==&lt;br /&gt;
==References==&lt;br /&gt;
https://www.youtube.com/watch?v=Ee5vfe0mLb8&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70000</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w-1w65 am</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=70000"/>
		<updated>2012-11-18T01:16:22Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This is a wiki article for the material presented in the Coursera SaaS video series, [https://www.youtube.com/watch?v=Ee5vfe0mLb8 3.13 Debugging by Dr. Armando Fox and Dr. David Patterson]. We aim to cover all the material presented in the video with definitions and examples&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; &lt;br /&gt;
'''Why debugging in Rails can be tricky?'''&amp;lt;br&amp;gt;&lt;br /&gt;
*We are used to printing the error on the terminal in most applications(Example: STDERR). This may not be possible for a web application since its primary form of input and output is through HTTP requests and responses.&lt;br /&gt;
&lt;br /&gt;
*Errors early in flow might manifest itself late.&lt;br /&gt;
Consider the following hierarchy seen in a Rails application:&lt;br /&gt;
 URI -&amp;gt; Route -&amp;gt; Controller -&amp;gt; Model -&amp;gt; View -&amp;gt; Renderer&lt;br /&gt;
 &lt;br /&gt;
Here, something that goes wrong in the controller might not manifest itself until the renderer. The root cause of the error might have happened a long time ago.&lt;br /&gt;
&lt;br /&gt;
*Errors can be hard to localize/reproduce if it affects only some users or routes.&lt;br /&gt;
&lt;br /&gt;
There are several approaches that can be used for debugging based on the mode of operation, that is development mode or production mode:&lt;br /&gt;
 &lt;br /&gt;
'''Printing to terminal:'''This is useful for developers, when they are writing code they can print errors to the terminal and then examine them. We cannot use this approach in production mode.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Logging:''' This is a more general approach to debugging which can be used in both modes. The logged entries are permanent record of what the application is doing. The recorded errors are saved in a log file and can be referenced later.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interactive Debugging:''' Using this tool you can stop the application in its tracks and inspect the state of the variables or other parameters to locate the error.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the various approaches and the modes in which they can be used: &amp;lt;br&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Approach !! Development !! Production&lt;br /&gt;
|-&lt;br /&gt;
| Printing to Terminal || ✓ || &lt;br /&gt;
|-&lt;br /&gt;
| Logging || ✓ || ✓&lt;br /&gt;
|-&lt;br /&gt;
| Interactive Debugging || ✓ || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==RASP==&lt;br /&gt;
RASP is an acronym which briefs the steps which a developer could follow if she were facing an error message. It stands for:&lt;br /&gt;
#'''Read''' the error message.&lt;br /&gt;
#'''Ask''' your colleague  &lt;br /&gt;
#'''Search''' using [http://stackoverflow.com/ Stack Overflow] or any other search engine.&lt;br /&gt;
#'''Post''' on [http://stackoverflow.com/ Stack Overflow] or class forum&lt;br /&gt;
&lt;br /&gt;
Reading the error message carefully is the first step in debugging. The error messages in Rails are incredibly detailed and it gives us a lot of information, reading it carefully can help us locate the file and line in which you are facing the error. But what if the line looks alright to you?&lt;br /&gt;
The next step is to ask a colleague an informed question. In case you are doing pair programming, this is a good step to take. The question has to be of the form &amp;quot;I am trying to do this and I expected to get this but I got this other thing instead of foo.&amp;quot;&lt;br /&gt;
If the previous steps fail then searching using stack overflow or Google is next, especially if its an error which is particular to a version of gems or OS&lt;br /&gt;
In case you don't find a solution to your problem the final step is to get minimal but complete information which reproduces the error message which you are experiencing and post it.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example question and solution from stack overflow:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Ques.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
As we can see the question follows the guidelines explained above. It gives minimal but complete information about the error. It does not give the entire description of the error. It is important to post minimal information so that the person who answers the question can understand your problem quickly.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Ans.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The answer is posted within an hour of posting the question. This shows that posting on stack overflow is a fast way of getting expert help with debugging.&lt;br /&gt;
&lt;br /&gt;
==Understanding Error Messages in Rails==&lt;br /&gt;
&lt;br /&gt;
===Application Trace===&lt;br /&gt;
&lt;br /&gt;
===Full Trace===&lt;br /&gt;
&lt;br /&gt;
===Framework Trace===&lt;br /&gt;
&lt;br /&gt;
===Env Dump and Session Dump===&lt;br /&gt;
===Most Common Error Messages in Ruby===&lt;br /&gt;
&lt;br /&gt;
==Interactive Debugger==&lt;br /&gt;
===What is an interactive debugger?===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
==Further Reading==&lt;br /&gt;
==References==&lt;br /&gt;
https://www.youtube.com/watch?v=Ee5vfe0mLb8&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=69999</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w-1w65 am</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=69999"/>
		<updated>2012-11-18T01:15:25Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* Application Trace */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This is a wiki article for the material presented in the Coursera SaaS video series, 3.13 Debugging by Dr. Armando Fox and Dr. David Patterson. We aim to cover all the material presented in the video with definitions and examples&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; &lt;br /&gt;
'''Why debugging in Rails can be tricky?'''&amp;lt;br&amp;gt;&lt;br /&gt;
*We are used to printing the error on the terminal in most applications(Example: STDERR). This may not be possible for a web application since its primary form of input and output is through HTTP requests and responses.&lt;br /&gt;
&lt;br /&gt;
*Errors early in flow might manifest itself late.&lt;br /&gt;
Consider the following hierarchy seen in a Rails application:&lt;br /&gt;
 URI -&amp;gt; Route -&amp;gt; Controller -&amp;gt; Model -&amp;gt; View -&amp;gt; Renderer&lt;br /&gt;
 &lt;br /&gt;
Here, something that goes wrong in the controller might not manifest itself until the renderer. The root cause of the error might have happened a long time ago.&lt;br /&gt;
&lt;br /&gt;
*Errors can be hard to localize/reproduce if it affects only some users or routes.&lt;br /&gt;
&lt;br /&gt;
There are several approaches that can be used for debugging based on the mode of operation, that is development mode or production mode:&lt;br /&gt;
 &lt;br /&gt;
'''Printing to terminal:'''This is useful for developers, when they are writing code they can print errors to the terminal and then examine them. We cannot use this approach in production mode.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Logging:''' This is a more general approach to debugging which can be used in both modes. The logged entries are permanent record of what the application is doing. The recorded errors are saved in a log file and can be referenced later.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interactive Debugging:''' Using this tool you can stop the application in its tracks and inspect the state of the variables or other parameters to locate the error.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the various approaches and the modes in which they can be used: &amp;lt;br&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Approach !! Development !! Production&lt;br /&gt;
|-&lt;br /&gt;
| Printing to Terminal || ✓ || &lt;br /&gt;
|-&lt;br /&gt;
| Logging || ✓ || ✓&lt;br /&gt;
|-&lt;br /&gt;
| Interactive Debugging || ✓ || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==RASP==&lt;br /&gt;
RASP is an acronym which briefs the steps which a developer could follow if she were facing an error message. It stands for:&lt;br /&gt;
#'''Read''' the error message.&lt;br /&gt;
#'''Ask''' your colleague  &lt;br /&gt;
#'''Search''' using [http://stackoverflow.com/ Stack Overflow] or any other search engine.&lt;br /&gt;
#'''Post''' on [http://stackoverflow.com/ Stack Overflow] or class forum&lt;br /&gt;
&lt;br /&gt;
Reading the error message carefully is the first step in debugging. The error messages in Rails are incredibly detailed and it gives us a lot of information, reading it carefully can help us locate the file and line in which you are facing the error. But what if the line looks alright to you?&lt;br /&gt;
The next step is to ask a colleague an informed question. In case you are doing pair programming, this is a good step to take. The question has to be of the form &amp;quot;I am trying to do this and I expected to get this but I got this other thing instead of foo.&amp;quot;&lt;br /&gt;
If the previous steps fail then searching using stack overflow or Google is next, especially if its an error which is particular to a version of gems or OS&lt;br /&gt;
In case you don't find a solution to your problem the final step is to get minimal but complete information which reproduces the error message which you are experiencing and post it.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example question and solution from stack overflow:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Ques.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
As we can see the question follows the guidelines explained above. It gives minimal but complete information about the error. It does not give the entire description of the error. It is important to post minimal information so that the person who answers the question can understand your problem quickly.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Ans.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The answer is posted within an hour of posting the question. This shows that posting on stack overflow is a fast way of getting expert help with debugging.&lt;br /&gt;
&lt;br /&gt;
==Understanding Error Messages in Rails==&lt;br /&gt;
&lt;br /&gt;
===Application Trace===&lt;br /&gt;
&lt;br /&gt;
===Full Trace===&lt;br /&gt;
&lt;br /&gt;
===Framework Trace===&lt;br /&gt;
&lt;br /&gt;
===Env Dump and Session Dump===&lt;br /&gt;
===Most Common Error Messages in Ruby===&lt;br /&gt;
&lt;br /&gt;
==Interactive Debugger==&lt;br /&gt;
===What is an interactive debugger?===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
==Further Reading==&lt;br /&gt;
==References==&lt;br /&gt;
https://www.youtube.com/watch?v=Ee5vfe0mLb8&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=69998</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w-1w65 am</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=69998"/>
		<updated>2012-11-18T01:10:47Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* Full Trace */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This is a wiki article for the material presented in the Coursera SaaS video series, 3.13 Debugging by Dr. Armando Fox and Dr. David Patterson. We aim to cover all the material presented in the video with definitions and examples&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; &lt;br /&gt;
'''Why debugging in Rails can be tricky?'''&amp;lt;br&amp;gt;&lt;br /&gt;
*We are used to printing the error on the terminal in most applications(Example: STDERR). This may not be possible for a web application since its primary form of input and output is through HTTP requests and responses.&lt;br /&gt;
&lt;br /&gt;
*Errors early in flow might manifest itself late.&lt;br /&gt;
Consider the following hierarchy seen in a Rails application:&lt;br /&gt;
 URI -&amp;gt; Route -&amp;gt; Controller -&amp;gt; Model -&amp;gt; View -&amp;gt; Renderer&lt;br /&gt;
 &lt;br /&gt;
Here, something that goes wrong in the controller might not manifest itself until the renderer. The root cause of the error might have happened a long time ago.&lt;br /&gt;
&lt;br /&gt;
*Errors can be hard to localize/reproduce if it affects only some users or routes.&lt;br /&gt;
&lt;br /&gt;
There are several approaches that can be used for debugging based on the mode of operation, that is development mode or production mode:&lt;br /&gt;
 &lt;br /&gt;
'''Printing to terminal:'''This is useful for developers, when they are writing code they can print errors to the terminal and then examine them. We cannot use this approach in production mode.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Logging:''' This is a more general approach to debugging which can be used in both modes. The logged entries are permanent record of what the application is doing. The recorded errors are saved in a log file and can be referenced later.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interactive Debugging:''' Using this tool you can stop the application in its tracks and inspect the state of the variables or other parameters to locate the error.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the various approaches and the modes in which they can be used: &amp;lt;br&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Approach !! Development !! Production&lt;br /&gt;
|-&lt;br /&gt;
| Printing to Terminal || ✓ || &lt;br /&gt;
|-&lt;br /&gt;
| Logging || ✓ || ✓&lt;br /&gt;
|-&lt;br /&gt;
| Interactive Debugging || ✓ || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==RASP==&lt;br /&gt;
RASP is an acronym which briefs the steps which a developer could follow if she were facing an error message. It stands for:&lt;br /&gt;
#'''Read''' the error message.&lt;br /&gt;
#'''Ask''' your colleague  &lt;br /&gt;
#'''Search''' using [http://stackoverflow.com/ Stack Overflow] or any other search engine.&lt;br /&gt;
#'''Post''' on [http://stackoverflow.com/ Stack Overflow] or class forum&lt;br /&gt;
&lt;br /&gt;
Reading the error message carefully is the first step in debugging. The error messages in Rails are incredibly detailed and it gives us a lot of information, reading it carefully can help us locate the file and line in which you are facing the error. But what if the line looks alright to you?&lt;br /&gt;
The next step is to ask a colleague an informed question. In case you are doing pair programming, this is a good step to take. The question has to be of the form &amp;quot;I am trying to do this and I expected to get this but I got this other thing instead of foo.&amp;quot;&lt;br /&gt;
If the previous steps fail then searching using stack overflow or Google is next, especially if its an error which is particular to a version of gems or OS&lt;br /&gt;
In case you don't find a solution to your problem the final step is to get minimal but complete information which reproduces the error message which you are experiencing and post it.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example question and solution from stack overflow:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Ques.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
As we can see the question follows the guidelines explained above. It gives minimal but complete information about the error. It does not give the entire description of the error. It is important to post minimal information so that the person who answers the question can understand your problem quickly.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Ans.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The answer is posted within an hour of posting the question. This shows that posting on stack overflow is a fast way of getting expert help with debugging.&lt;br /&gt;
&lt;br /&gt;
==Understanding Error Messages in Rails==&lt;br /&gt;
&lt;br /&gt;
===Application Trace===&lt;br /&gt;
===Full Trace===&lt;br /&gt;
&lt;br /&gt;
===Framework Trace===&lt;br /&gt;
&lt;br /&gt;
===Env Dump and Session Dump===&lt;br /&gt;
===Most Common Error Messages in Ruby===&lt;br /&gt;
&lt;br /&gt;
==Interactive Debugger==&lt;br /&gt;
===What is an interactive debugger?===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
==Further Reading==&lt;br /&gt;
==References==&lt;br /&gt;
https://www.youtube.com/watch?v=Ee5vfe0mLb8&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=69997</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w-1w65 am</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=69997"/>
		<updated>2012-11-18T01:10:29Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* Back Trace */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This is a wiki article for the material presented in the Coursera SaaS video series, 3.13 Debugging by Dr. Armando Fox and Dr. David Patterson. We aim to cover all the material presented in the video with definitions and examples&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; &lt;br /&gt;
'''Why debugging in Rails can be tricky?'''&amp;lt;br&amp;gt;&lt;br /&gt;
*We are used to printing the error on the terminal in most applications(Example: STDERR). This may not be possible for a web application since its primary form of input and output is through HTTP requests and responses.&lt;br /&gt;
&lt;br /&gt;
*Errors early in flow might manifest itself late.&lt;br /&gt;
Consider the following hierarchy seen in a Rails application:&lt;br /&gt;
 URI -&amp;gt; Route -&amp;gt; Controller -&amp;gt; Model -&amp;gt; View -&amp;gt; Renderer&lt;br /&gt;
 &lt;br /&gt;
Here, something that goes wrong in the controller might not manifest itself until the renderer. The root cause of the error might have happened a long time ago.&lt;br /&gt;
&lt;br /&gt;
*Errors can be hard to localize/reproduce if it affects only some users or routes.&lt;br /&gt;
&lt;br /&gt;
There are several approaches that can be used for debugging based on the mode of operation, that is development mode or production mode:&lt;br /&gt;
 &lt;br /&gt;
'''Printing to terminal:'''This is useful for developers, when they are writing code they can print errors to the terminal and then examine them. We cannot use this approach in production mode.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Logging:''' This is a more general approach to debugging which can be used in both modes. The logged entries are permanent record of what the application is doing. The recorded errors are saved in a log file and can be referenced later.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interactive Debugging:''' Using this tool you can stop the application in its tracks and inspect the state of the variables or other parameters to locate the error.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the various approaches and the modes in which they can be used: &amp;lt;br&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Approach !! Development !! Production&lt;br /&gt;
|-&lt;br /&gt;
| Printing to Terminal || ✓ || &lt;br /&gt;
|-&lt;br /&gt;
| Logging || ✓ || ✓&lt;br /&gt;
|-&lt;br /&gt;
| Interactive Debugging || ✓ || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==RASP==&lt;br /&gt;
RASP is an acronym which briefs the steps which a developer could follow if she were facing an error message. It stands for:&lt;br /&gt;
#'''Read''' the error message.&lt;br /&gt;
#'''Ask''' your colleague  &lt;br /&gt;
#'''Search''' using [http://stackoverflow.com/ Stack Overflow] or any other search engine.&lt;br /&gt;
#'''Post''' on [http://stackoverflow.com/ Stack Overflow] or class forum&lt;br /&gt;
&lt;br /&gt;
Reading the error message carefully is the first step in debugging. The error messages in Rails are incredibly detailed and it gives us a lot of information, reading it carefully can help us locate the file and line in which you are facing the error. But what if the line looks alright to you?&lt;br /&gt;
The next step is to ask a colleague an informed question. In case you are doing pair programming, this is a good step to take. The question has to be of the form &amp;quot;I am trying to do this and I expected to get this but I got this other thing instead of foo.&amp;quot;&lt;br /&gt;
If the previous steps fail then searching using stack overflow or Google is next, especially if its an error which is particular to a version of gems or OS&lt;br /&gt;
In case you don't find a solution to your problem the final step is to get minimal but complete information which reproduces the error message which you are experiencing and post it.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example question and solution from stack overflow:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Ques.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
As we can see the question follows the guidelines explained above. It gives minimal but complete information about the error. It does not give the entire description of the error. It is important to post minimal information so that the person who answers the question can understand your problem quickly.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Ans.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The answer is posted within an hour of posting the question. This shows that posting on stack overflow is a fast way of getting expert help with debugging.&lt;br /&gt;
&lt;br /&gt;
==Understanding Error Messages in Rails==&lt;br /&gt;
&lt;br /&gt;
===Application Trace===&lt;br /&gt;
===Full Trace===&lt;br /&gt;
&lt;br /&gt;
===Full Trace===&lt;br /&gt;
===Env Dump and Session Dump===&lt;br /&gt;
===Most Common Error Messages in Ruby===&lt;br /&gt;
&lt;br /&gt;
==Interactive Debugger==&lt;br /&gt;
===What is an interactive debugger?===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
==Further Reading==&lt;br /&gt;
==References==&lt;br /&gt;
https://www.youtube.com/watch?v=Ee5vfe0mLb8&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=69987</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w-1w65 am</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=69987"/>
		<updated>2012-11-17T23:59:59Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* RASP */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This is a wiki article for the material presented in the Coursera SaaS video series, 3.13 Debugging by Dr. Armando Fox and Dr. David Patterson. We aim to cover all the material presented in the video with definitions and examples&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; &lt;br /&gt;
'''Why debugging in Rails can be tricky?'''&amp;lt;br&amp;gt;&lt;br /&gt;
*We are used to printing the error on the terminal in most applications(Example: STDERR). This may not be possible for a web application since its primary form of input and output is through HTTP requests and responses.&lt;br /&gt;
&lt;br /&gt;
*Errors early in flow might manifest itself late.&lt;br /&gt;
Consider the following hierarchy seen in a Rails application:&lt;br /&gt;
 URI -&amp;gt; Route -&amp;gt; Controller -&amp;gt; Model -&amp;gt; View -&amp;gt; Renderer&lt;br /&gt;
 &lt;br /&gt;
Here, something that goes wrong in the controller might not manifest itself until the renderer. The root cause of the error might have happened a long time ago.&lt;br /&gt;
&lt;br /&gt;
*Errors can be hard to localize/reproduce if it affects only some users or routes.&lt;br /&gt;
&lt;br /&gt;
There are several approaches that can be used for debugging based on the mode of operation, that is development mode or production mode:&lt;br /&gt;
 &lt;br /&gt;
'''Printing to terminal:'''This is useful for developers, when they are writing code they can print errors to the terminal and then examine them. We cannot use this approach in production mode.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Logging:''' This is a more general approach to debugging which can be used in both modes. The logged entries are permanent record of what the application is doing. The recorded errors are saved in a log file and can be referenced later.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interactive Debugging:''' Using this tool you can stop the application in its tracks and inspect the state of the variables or other parameters to locate the error.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the various approaches and the modes in which they can be used: &amp;lt;br&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Approach !! Development !! Production&lt;br /&gt;
|-&lt;br /&gt;
| Printing to Terminal || ✓ || &lt;br /&gt;
|-&lt;br /&gt;
| Logging || ✓ || ✓&lt;br /&gt;
|-&lt;br /&gt;
| Interactive Debugging || ✓ || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==RASP==&lt;br /&gt;
RASP is an acronym which briefs the steps which a developer could follow if she were facing an error message. It stands for:&lt;br /&gt;
#'''Read''' the error message.&lt;br /&gt;
#'''Ask''' your colleague  &lt;br /&gt;
#'''Search''' using [http://stackoverflow.com/ Stack Overflow] or any other search engine.&lt;br /&gt;
#'''Post''' on [http://stackoverflow.com/ Stack Overflow] or class forum&lt;br /&gt;
&lt;br /&gt;
Reading the error message carefully is the first step in debugging. The error messages in Rails are incredibly detailed and it gives us a lot of information, reading it carefully can help us locate the file and line in which you are facing the error. But what if the line looks alright to you?&lt;br /&gt;
The next step is to ask a colleague an informed question. In case you are doing pair programming, this is a good step to take. The question has to be of the form &amp;quot;I am trying to do this and I expected to get this but I got this other thing instead of foo.&amp;quot;&lt;br /&gt;
If the previous steps fail then searching using stack overflow or Google is next, especially if its an error which is particular to a version of gems or OS&lt;br /&gt;
In case you don't find a solution to your problem the final step is to get minimal but complete information which reproduces the error message which you are experiencing and post it.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example question and solution from stack overflow:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Ques.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
As we can see the question follows the guidelines explained above. It gives minimal but complete information about the error. It does not give the entire description of the error. It is important to post minimal information so that the person who answers the question can understand your problem quickly.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Ans.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The answer is posted within an hour of posting the question. This shows that posting on stack overflow is a fast way of getting expert help with debugging.&lt;br /&gt;
&lt;br /&gt;
==Understanding Error Messages in Rails==&lt;br /&gt;
&lt;br /&gt;
===Application Trace===&lt;br /&gt;
===Back Trace===&lt;br /&gt;
===Full Trace===&lt;br /&gt;
===Env Dump and Session Dump===&lt;br /&gt;
===Most Common Error Messages in Ruby===&lt;br /&gt;
&lt;br /&gt;
==Interactive Debugger==&lt;br /&gt;
===What is an interactive debugger?===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
==Further Reading==&lt;br /&gt;
==References==&lt;br /&gt;
https://www.youtube.com/watch?v=Ee5vfe0mLb8&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Ans.png&amp;diff=69986</id>
		<title>File:Ans.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Ans.png&amp;diff=69986"/>
		<updated>2012-11-17T23:58:37Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Ques.png&amp;diff=69985</id>
		<title>File:Ques.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Ques.png&amp;diff=69985"/>
		<updated>2012-11-17T23:58:10Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=69983</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w-1w65 am</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=69983"/>
		<updated>2012-11-17T23:51:02Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* RASP */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This is a wiki article for the material presented in the Coursera SaaS video series, 3.13 Debugging by Dr. Armando Fox and Dr. David Patterson. We aim to cover all the material presented in the video with definitions and examples&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; &lt;br /&gt;
'''Why debugging in Rails can be tricky?'''&amp;lt;br&amp;gt;&lt;br /&gt;
*We are used to printing the error on the terminal in most applications(Example: STDERR). This may not be possible for a web application since its primary form of input and output is through HTTP requests and responses.&lt;br /&gt;
&lt;br /&gt;
*Errors early in flow might manifest itself late.&lt;br /&gt;
Consider the following hierarchy seen in a Rails application:&lt;br /&gt;
 URI -&amp;gt; Route -&amp;gt; Controller -&amp;gt; Model -&amp;gt; View -&amp;gt; Renderer&lt;br /&gt;
 &lt;br /&gt;
Here, something that goes wrong in the controller might not manifest itself until the renderer. The root cause of the error might have happened a long time ago.&lt;br /&gt;
&lt;br /&gt;
*Errors can be hard to localize/reproduce if it affects only some users or routes.&lt;br /&gt;
&lt;br /&gt;
There are several approaches that can be used for debugging based on the mode of operation, that is development mode or production mode:&lt;br /&gt;
 &lt;br /&gt;
'''Printing to terminal:'''This is useful for developers, when they are writing code they can print errors to the terminal and then examine them. We cannot use this approach in production mode.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Logging:''' This is a more general approach to debugging which can be used in both modes. The logged entries are permanent record of what the application is doing. The recorded errors are saved in a log file and can be referenced later.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interactive Debugging:''' Using this tool you can stop the application in its tracks and inspect the state of the variables or other parameters to locate the error.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the various approaches and the modes in which they can be used: &amp;lt;br&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Approach !! Development !! Production&lt;br /&gt;
|-&lt;br /&gt;
| Printing to Terminal || ✓ || &lt;br /&gt;
|-&lt;br /&gt;
| Logging || ✓ || ✓&lt;br /&gt;
|-&lt;br /&gt;
| Interactive Debugging || ✓ || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==RASP==&lt;br /&gt;
RASP is an acronym which briefs the steps which a developer could follow if she were facing an error message. It stands for:&lt;br /&gt;
#'''Read''' the error message.&lt;br /&gt;
#'''Ask''' your colleague  &lt;br /&gt;
#'''Search''' using [http://stackoverflow.com/ Stack Overflow] or any other search engine.&lt;br /&gt;
#'''Post''' on [http://stackoverflow.com/ Stack Overflow] or class forum&lt;br /&gt;
&lt;br /&gt;
Reading the error message carefully is the first step in debugging. The error messages in Rails are incredibly detailed and it gives us a lot of information, reading it carefully can help us locate the file and line in which you are facing the error. But what if the line looks alright to you?&lt;br /&gt;
The next step is to ask a colleague an informed question. In case you are doing pair programming, this is a good step to take. The question has to be of the form &amp;quot;I am trying to do this and I expected to get this but I got this other thing instead of foo.&amp;quot;&lt;br /&gt;
If the previous steps fail then searching using stack overflow or Google is next, especially if its an error which is particular to a version of gems or OS&lt;br /&gt;
In case you don't find a solution to your problem the final step is to get minimal but complete information which reproduces the error message which you are experiencing and post it.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example question and solution from stack overflow:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:question.jpg]]&lt;br /&gt;
As we can see the question follows the guidelines explained above. It gives minimal but complete information about the error. It does not give the entire description of the error. It is important to post minimal information so that the person who answers the question can understand your problem quickly.&lt;br /&gt;
[[File:answer.jpg]]&lt;br /&gt;
The answer is posted within half an hour of posting the question. This shows that this is a fast way of getting expert help with debugging.&lt;br /&gt;
&lt;br /&gt;
==Understanding Error Messages in Rails==&lt;br /&gt;
&lt;br /&gt;
===Application Trace===&lt;br /&gt;
===Back Trace===&lt;br /&gt;
===Full Trace===&lt;br /&gt;
===Env Dump and Session Dump===&lt;br /&gt;
===Most Common Error Messages in Ruby===&lt;br /&gt;
&lt;br /&gt;
==Interactive Debugger==&lt;br /&gt;
===What is an interactive debugger?===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
==Further Reading==&lt;br /&gt;
==References==&lt;br /&gt;
https://www.youtube.com/watch?v=Ee5vfe0mLb8&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Answer.jpg&amp;diff=69982</id>
		<title>File:Answer.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Answer.jpg&amp;diff=69982"/>
		<updated>2012-11-17T23:37:40Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Question.jpg&amp;diff=69981</id>
		<title>File:Question.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Question.jpg&amp;diff=69981"/>
		<updated>2012-11-17T23:36:42Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=69979</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w-1w65 am</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=69979"/>
		<updated>2012-11-17T23:00:02Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This is a wiki article for the material presented in the Coursera SaaS video series, 3.13 Debugging by Dr. Armando Fox and Dr. David Patterson. We aim to cover all the material presented in the video with definitions and examples&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; &lt;br /&gt;
'''Why debugging in Rails can be tricky?'''&amp;lt;br&amp;gt;&lt;br /&gt;
*We are used to printing the error on the terminal in most applications(Example: STDERR). This may not be possible for a web application since its primary form of input and output is through HTTP requests and responses.&lt;br /&gt;
&lt;br /&gt;
*Errors early in flow might manifest itself late.&lt;br /&gt;
Consider the following hierarchy seen in a Rails application:&lt;br /&gt;
 URI -&amp;gt; Route -&amp;gt; Controller -&amp;gt; Model -&amp;gt; View -&amp;gt; Renderer&lt;br /&gt;
 &lt;br /&gt;
Here, something that goes wrong in the controller might not manifest itself until the renderer. The root cause of the error might have happened a long time ago.&lt;br /&gt;
&lt;br /&gt;
*Errors can be hard to localize/reproduce if it affects only some users or routes.&lt;br /&gt;
&lt;br /&gt;
There are several approaches that can be used for debugging based on the mode of operation, that is development mode or production mode:&lt;br /&gt;
 &lt;br /&gt;
'''Printing to terminal:'''This is useful for developers, when they are writing code they can print errors to the terminal and then examine them. We cannot use this approach in production mode.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Logging:''' This is a more general approach to debugging which can be used in both modes. The logged entries are permanent record of what the application is doing. The recorded errors are saved in a log file and can be referenced later.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Interactive Debugging:''' Using this tool you can stop the application in its tracks and inspect the state of the variables or other parameters to locate the error.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the various approaches and the modes in which they can be used: &amp;lt;br&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Approach !! Development !! Production&lt;br /&gt;
|-&lt;br /&gt;
| Printing to Terminal || ✓ || &lt;br /&gt;
|-&lt;br /&gt;
| Logging || ✓ || ✓&lt;br /&gt;
|-&lt;br /&gt;
| Interactive Debugging || ✓ || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==RASP==&lt;br /&gt;
&lt;br /&gt;
===Tips to deal with an error===&lt;br /&gt;
i) Read the error message carefully.&lt;br /&gt;
&lt;br /&gt;
ii) Ask your colleague an informed question in case you are doing pair programming. &lt;br /&gt;
&lt;br /&gt;
iii) Search using StackOverflow or Google&lt;br /&gt;
Especially if its an error which is particular to a version of gems or OS&lt;br /&gt;
&lt;br /&gt;
iv) Post on StackOverflow or class forum&lt;br /&gt;
Get minimal but complete information which reproduces the error message which you are experiencing and post it.&lt;br /&gt;
&lt;br /&gt;
==Understanding Error Messages in Rails==&lt;br /&gt;
&lt;br /&gt;
===Application Trace===&lt;br /&gt;
===Back Trace===&lt;br /&gt;
===Full Trace===&lt;br /&gt;
===Env Dump and Session Dump===&lt;br /&gt;
===Most Common Error Messages in Ruby===&lt;br /&gt;
&lt;br /&gt;
==Interactive Debugger==&lt;br /&gt;
===What is an interactive debugger?===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
==Further Reading==&lt;br /&gt;
==References==&lt;br /&gt;
https://www.youtube.com/watch?v=Ee5vfe0mLb8&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=69579</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w-1w65 am</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w-1w65_am&amp;diff=69579"/>
		<updated>2012-11-16T16:46:00Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: Created page with &amp;quot;==Introduction== ===Why debugging in SaaS/Rails is hard?=== ===Definitions===  ==RASP==  ===Steps of RASP===  ==Understanding Error Messages in Rails==  ===Application Trace=== =...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
===Why debugging in SaaS/Rails is hard?===&lt;br /&gt;
===Definitions===&lt;br /&gt;
&lt;br /&gt;
==RASP==&lt;br /&gt;
&lt;br /&gt;
===Steps of RASP===&lt;br /&gt;
&lt;br /&gt;
==Understanding Error Messages in Rails==&lt;br /&gt;
&lt;br /&gt;
===Application Trace===&lt;br /&gt;
===Back Trace===&lt;br /&gt;
===Full Trace===&lt;br /&gt;
===Env Dump and Session Dump===&lt;br /&gt;
===Most Common Error Messages in Ruby===&lt;br /&gt;
&lt;br /&gt;
==Interactive Debugger==&lt;br /&gt;
===What is an interactive debugger?===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
==Further Reading==&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012&amp;diff=69578</id>
		<title>CSC/ECE 517 Fall 2012</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012&amp;diff=69578"/>
		<updated>2012-11-16T16:41:15Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*[[CSC/ECE_517_Fall_2012/Table_Of_Contents]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 n xx]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w1 rk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w20 pp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w5 su]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w6 pp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w4 aj]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w7 am]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w8 aa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w9 av]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w10 pk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w11 ap]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1a 1w12 mv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w14 gv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w17 ir]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w18 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w22 an]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w21 aa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w21 wi]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w31 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1a 1w16 br]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1a 1w23 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w24 nr]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w15 rt]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w3 pl]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w32 cm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w5 dp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w37 ss]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w67 ks]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w27 ms]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w29 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w33 op]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w19 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w34 vd]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w35 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w30 rp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w58 am]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w47 sk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w69 mv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w44 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w45 is]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w53 kc]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w40 ar]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w39 sn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w54 go]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w56 ms]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w64 nn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w66 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w40 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w42 js]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w46 sm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w71 gs]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w63 dv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w55 ms]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w57 mp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w52 an]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch1b 1w38 nm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w60 ac]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w62 rb]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w29 st]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w3_sm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w30 an]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w17 pt]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w31 up]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w9 ms]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w19 is]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w26 aj]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w5 dp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w16 dp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w8 vp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w18 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w3 jm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w23 sr]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w11_aa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w15 rr]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w33 pv]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w20_aa]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w14_bb]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w21_ap]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w13_sm]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w4_sa]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w25_nr]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w12_sv]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w7_ma]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w6_ar]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w32_mk]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w10_rc]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w70_sm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w67_sk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w40_sn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w22_sk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w-1w65_am]]&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w56_ms&amp;diff=67507</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w56 ms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w56_ms&amp;diff=67507"/>
		<updated>2012-10-11T02:27:20Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
===What is Object Oriented Programming?===&lt;br /&gt;
Wikipedia defines [http://en.wikipedia.org/wiki/Object-oriented_programming Object-oriented programming (OOP)] as a programming paradigm that uses objects and their interactions to design applications and computer programs. &lt;br /&gt;
The primary programming concepts in OOP are:&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Abstraction_(computer_science) Abstraction] - hiding all but the necessary data about an object in order to reduce complexity and increase efficiency.&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Polymorphism_(computer_science) Polymorphism ] - characteristic of being able to assign a different meaning to a particular function or &amp;quot;operator&amp;quot; in different contexts.&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Encapsulation_(object-oriented_programming) Encapsulation] - hide the implementation details of a class from other objects.&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Inheritance_(computer_science) Inheritance] - form new classes using existing class definitions.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] is pure object-oriented language! i.e to Ruby, everything appears as an object. Every value in Ruby is an object, even the most primitive things: strings, numbers and even true and false. Ruby is so true to being object oriented that even a class is an object that is an instance of the ‘C’lass class. &lt;br /&gt;
In object-oriented code, we model concepts from the real world. During this modeling process you’ll different items to be represented. In Ruby, classes are defined to represent each of these items. Objects, which are instances of a class are nothing but different kinds of that item in terms of Ruby. &lt;br /&gt;
&lt;br /&gt;
Now let’s look at some basic object oriented concepts in Ruby.&lt;br /&gt;
&lt;br /&gt;
==Object==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_(computer_science) Objects] are basic building blocks of a Ruby OOP program. Every basic item, when being represented, can be given its own properties and actions. Object-oriented programming calls properties by the name instance variables , whose names starts with @, and actions are known as methods. &lt;br /&gt;
A '''class''' is a template for an '''object''', and an '''object''' is an instance of the class. Objects are created by calling a constructor, a special method associated with a class. The constructor in Ruby is called initialize. Constructors do not return any values. Constructors can be parameterized too, to contain values that initialize the instance method. This is also called the '''initialize method'''. For example,&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Example:&amp;lt;br&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;class Account&amp;lt;br&amp;gt;&lt;br /&gt;
  # constructor used when Account.new(...) called&amp;lt;br&amp;gt;&lt;br /&gt;
  def initialize(starting_balance=0) # optional argument&amp;lt;br&amp;gt;&lt;br /&gt;
    @balance = starting_balance&amp;lt;br&amp;gt;&lt;br /&gt;
  end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
account1 = Account.new 10&lt;br /&gt;
&amp;lt;/FONT&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Here the constructor, when invoked will create an object of type ‘Account’ represented by the name account1nitialize the instance variable balance to 10. Each object gets its own set of instance variables.&lt;br /&gt;
Different objects communicate together through methods. Each object can receive messages, send messages and process data.&lt;br /&gt;
&lt;br /&gt;
==Class==&lt;br /&gt;
A [http://www.ruby-doc.org/core-1.9.3/Class.html  class] can be defined as a blueprint for a data type. It defines the state and behaviour of the class, that is, what an object of the class will consist of and what operations can be performed on such an object. A class represents the real world entity.&lt;br /&gt;
&lt;br /&gt;
A class definition starts with the keyword class followed by the class name and is delimited with an end. For example we defined the BankAccount class using the keyword class as follows:&lt;br /&gt;
&lt;br /&gt;
Example:&amp;lt;br&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;class BankAccount&amp;lt;br&amp;gt;&lt;br /&gt;
  attr_accessor :name, :balance&amp;lt;br&amp;gt;&lt;br /&gt;
  def deposit(amt)&amp;lt;br&amp;gt;&lt;br /&gt;
    @balance+=amt&amp;lt;br&amp;gt;&lt;br /&gt;
  end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/FONT&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
The class BankAccount, contains instance variables(defined later) name and balance that defines the state of an object of the class and a method deposit that defines the behavior.  &lt;br /&gt;
Here, the name (BankAccount) must begin with a capital letter. By convention, names that contain more than one word run together with each word capitalized and no separating characters (CamelCase).&lt;br /&gt;
&lt;br /&gt;
==Inheritance==&lt;br /&gt;
One of the most important concepts in object-oriented programming is that of inheritance. Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application. The newly formed class is called the derived class or the sub-class, the class that we derive from is called base class or the super-class.&lt;br /&gt;
Although, inheritance provides an opportunity to reuse the code functionality and hasten  implementation time, Ruby does not support Multiple level of inheritances. However, this functionality can be implemented using another feature called [http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html mixins]. A mixin is like a specialized implementation of multiple inheritance in which only the interface portion is inherited.&lt;br /&gt;
The syntax for extending a class is by adding a “&amp;lt;” character and the name of the superclass to the class statement.&lt;br /&gt;
Example :&amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;class Account&amp;lt;br&amp;gt;&lt;br /&gt;
  # constructor used when Account.new(...) called&amp;lt;br&amp;gt;&lt;br /&gt;
  def initialize(starting_balance=0) # optional argument&amp;lt;br&amp;gt;&lt;br /&gt;
    @balance = starting_balance&amp;lt;br&amp;gt;&lt;br /&gt;
  end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class SharedAccount &amp;lt; Account&amp;lt;br&amp;gt;&lt;br /&gt;
 # adding another instance variable “common_fund” and an instance method “share”&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
def share(common=0) # optional argument&amp;lt;br&amp;gt;&lt;br /&gt;
    @common_fund = common&amp;lt;br&amp;gt;&lt;br /&gt;
    print &amp;quot;Total Balance : #{@balance + @common_fund}&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
  end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&lt;br /&gt;
a = SharedAccount.new 10&amp;lt;br&amp;gt;&lt;br /&gt;
a.share(20)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Output : Total Balance : 30&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/FONT&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
The above, will make use of both base class and derived class instance variables.&lt;br /&gt;
&lt;br /&gt;
==Instance Variables and Accessor Methods==&lt;br /&gt;
&lt;br /&gt;
===Instance Variables===&lt;br /&gt;
An instance variable begins with the symbol “@” in Ruby. It is different from a local variable because its scope is confined to the object to which self refers. Instance variables are invisible outside of the object. The only way we can access them or observer them is by writing methods to get or set the value of them. Instance variables have the value “nil” until they are initialized.&lt;br /&gt;
Instance variables do not need to be declared. In fact we can also access instance variables without declaring or initializing it, this will not raise an exception. However a warning will be issued if we run it using the –w switch.&lt;br /&gt;
Every instance variable is dynamically appended to an object in the first assignment.&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;@balance -&amp;gt; instance variable&amp;lt;/FONT&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
===Accessor Methods===&lt;br /&gt;
As stated previously, we cannot access instance variables from anywhere outside an object. Hence we need to define methods to access them. They are generally called as getter and setter methods.&lt;br /&gt;
The getter method is used to return the value of the instance variable. It would be defined as:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def balance &amp;lt;br&amp;gt;&lt;br /&gt;
@balance &amp;lt;br&amp;gt;&lt;br /&gt;
end &amp;lt;br&amp;gt;&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
The setter method is used to set the value of the instance variable. Setter methods always end with the “=” sign.  It would be defined as:&amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def balance= (bal) &amp;lt;br&amp;gt;&lt;br /&gt;
@balance = bal &amp;lt;br&amp;gt;&lt;br /&gt;
end &amp;lt;br&amp;gt;&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Instead of writing getter and setter methods for each class, we can use the attr_accessor function. The attr_accessor is a method call which uses metaprogramming to generate the getter and setter methods dynamically at run time.&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Example: &amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;attr_accessor :balance&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
This is equivalent to&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
def balance&amp;lt;br&amp;gt;&lt;br /&gt;
@balance&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
def balance= (bal)&amp;lt;br&amp;gt;&lt;br /&gt;
@balance = bal&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We can also generate getter and setter methods for more than one instance variable.&amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
attr_accessor :balance, :new_balance&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We can also use &amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;attr_reader&amp;lt;/FONT&amp;gt; if we only want to generate the getter function. Similarly we can use the method call &amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;attr_writer&amp;lt;/FONT&amp;gt; for generating just the setter function.&lt;br /&gt;
&lt;br /&gt;
==Instance Methods==&lt;br /&gt;
Instance methods work with instances of the class. So in order to use instance methods we have to create an instance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example: &amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def deposit&amp;lt;br&amp;gt;&lt;br /&gt;
@balance += amount&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt; &amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
You can include the definition of an instance method within the class like this: &lt;br /&gt;
Example: &amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;Class SavingsAccount &amp;lt; Account&amp;lt;br&amp;gt;&lt;br /&gt;
def deposit&amp;lt;br&amp;gt;@balance += amount&amp;lt;br&amp;gt; end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt; &amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Or you can also define it later. Since Ruby is a dynamic programming language we are allowed to reopen a class and add methods to it. For instance to add the deposit method after closing the class:&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;&lt;br /&gt;
Class SavingsAccount &amp;lt; Account&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&lt;br /&gt;
SAcc = SavingsAccount.new&amp;lt;br&amp;gt;&lt;br /&gt;
def SAcc.deposit&amp;lt;br&amp;gt;&lt;br /&gt;
@balance += amount&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
The save and update methods used in Rails are actually instance methods.&lt;br /&gt;
&lt;br /&gt;
There are two types of methods in Ruby: Safe methods and destructive methods. They are called as safe and destructive depending on whether they modify the input parameters passed to them. The destructive methods end with the “!” symbol, so that they can warn the programmer when he is writing the code. “&amp;lt;&amp;lt;” is another example of a destructive method.&lt;br /&gt;
&lt;br /&gt;
==Class Variables and Class Methods==&lt;br /&gt;
===Class Variables===&lt;br /&gt;
A class variable begins with the symbol “@@” in Ruby. Once we define a class variable it is set for the class and all of its subclasses.&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;@@bank_name = “MyBank.com”&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
We need to add a getter method to access the class variable from outside the class. This would look like:&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def self.bank_name&amp;lt;br&amp;gt;&lt;br /&gt;
@@bank_name&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
puts SavingsAccount.bank_name =&amp;gt; “MyBank.com” &amp;lt;br&amp;gt; &amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===Class Methods===&lt;br /&gt;
Class methods are equivalent to static methods in Java. Class methods only exist in the class that defined them. So we cannot call a class method with an instance variable, because the class method does not exist in the instance variable.&lt;br /&gt;
There are multiple ways of defining class methods.&amp;lt;br&amp;gt;&lt;br /&gt;
*&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def SavingsAccount.bank_name&amp;lt;/FONT&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def self.bank_name&amp;lt;/FONT&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;class &amp;lt;&amp;lt; self &amp;lt;br&amp;gt; def bank_name&amp;lt;/FONT&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Method 1 we use the class name followed by a dot followed by the class method name. In Method 2 we use the keyword [http://stackoverflow.com/questions/6669527/use-of-ruby-self-keyword self]. In Ruby self gives you access to the current object, when defined within a class it refers to the current class. Method 2 is frequently used to define a class method.&lt;br /&gt;
In the third method we are actually building an anonymous class for the current object (referred by self) using the &amp;lt;&amp;lt; notation. We are doing exactly what we did in Method 2, it is uncommon to see the use of Method 3.&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
[http://www.ruby-doc.org/docs/ProgrammingRuby/ Programming Ruby: The Pragmatic Programmer's Guide]: An excellent textbook for learning and understanding Ruby&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.ruby-lang.org/en/documentation/quickstart/ Ruby in 20 minutes] : An online tutorial for getting a hang of Ruby.&amp;lt;br&amp;gt;&lt;br /&gt;
[http://tryruby.org/levels/1/challenges/0 Try Ruby]: Try Ruby online without installing it on your machine&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Classes Wikibooks Programming Ruby]: A wikibook link for Programming Ruby&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object-oriented_programming1]http://en.wikipedia.org/wiki/Object-oriented_programming&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.ruby-doc.org/docs/ProgrammingRuby/html/2]http://www.ruby-doc.org/docs/ProgrammingRuby/html/&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rubyfleebie.com/understanding-class-methods-in-ruby/3]http://www.rubyfleebie.com/understanding-class-methods-in-ruby/&amp;lt;br&amp;gt;&lt;br /&gt;
[http://stackoverflow.com/questions/2084490/ruby-class-variables4]http://stackoverflow.com/questions/2084490/ruby-class-variables&amp;lt;br&amp;gt;&lt;br /&gt;
[http://railstips.org/blog/archives/2009/05/11/class-and-instance-methods-in-ruby/5]http://railstips.org/blog/archives/2009/05/11/class-and-instance-methods-in-ruby/&amp;lt;br&amp;gt;&lt;br /&gt;
[http://railsguru.org/2010/04/quick-ruby-tutorials-3-class-and-instance-methods6]http://railsguru.org/2010/04/quick-ruby-tutorials-3-class-and-instance-methods/&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rubyist.net/~slagell/ruby/instancevars.html7]http://www.rubyist.net/~slagell/ruby/instancevars.html&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rubyist.net/~slagell/ruby/accessors.html8]http://www.rubyist.net/~slagell/ruby/accessors.html&amp;lt;br&amp;gt;&lt;br /&gt;
[http://rubylearning.com/satishtalim/ruby_inheritance.html9]http://rubylearning.com/satishtalim/ruby_inheritance.html&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.tutorialspoint.com/ruby/ruby_object_oriented.htm10]http://www.tutorialspoint.com/ruby/ruby_object_oriented.htm&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.ruby-lang.org/en/about/11]http://www.ruby-lang.org/en/about/&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rubyist.net/~slagell/ruby/objinitialization.html12]http://www.rubyist.net/~slagell/ruby/objinitialization.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w56_ms&amp;diff=67506</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w56 ms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w56_ms&amp;diff=67506"/>
		<updated>2012-10-11T02:25:27Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* Further Reading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
===What is Object Oriented Programming?===&lt;br /&gt;
Wikipedia defines [http://en.wikipedia.org/wiki/Object-oriented_programming Object-oriented programming (OOP)] as a programming paradigm that uses objects and their interactions to design applications and computer programs. &lt;br /&gt;
The primary programming concepts in OOP are:&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Abstraction_(computer_science) Abstraction] - hiding all but the necessary data about an object in order to reduce complexity and increase efficiency.&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Polymorphism_(computer_science) Polymorphism ] - characteristic of being able to assign a different meaning to a particular function or &amp;quot;operator&amp;quot; in different contexts.&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Encapsulation_(object-oriented_programming) Encapsulation] - hide the implementation details of a class from other objects.&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Inheritance_(computer_science) Inheritance] - form new classes using existing class definitions.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] is pure object-oriented language! i.e to Ruby, everything appears as an object. Every value in Ruby is an object, even the most primitive things: strings, numbers and even true and false. Ruby is so true to being object oriented that even a class is an object that is an instance of the ‘C’lass class. &lt;br /&gt;
In object-oriented code, we model concepts from the real world. During this modeling process you’ll different items to be represented. In Ruby, classes are defined to represent each of these items. Objects, which are instances of a class are nothing but different kinds of that item in terms of Ruby. &lt;br /&gt;
&lt;br /&gt;
Now let’s look at some basic object oriented concepts in Ruby.&lt;br /&gt;
&lt;br /&gt;
==Object==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_(computer_science) Objects] are basic building blocks of a Ruby OOP program. Every basic item, when being represented, can be given its own properties and actions. Object-oriented programming calls properties by the name instance variables , whose names starts with @, and actions are known as methods. &lt;br /&gt;
A '''class''' is a template for an '''object''', and an '''object''' is an instance of the class. Objects are created by calling a constructor, a special method associated with a class. The constructor in Ruby is called initialize. Constructors do not return any values. Constructors can be parameterized too, to contain values that initialize the instance method. This is also called the '''initialize method'''. For example,&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Example:&amp;lt;br&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;class Account&amp;lt;br&amp;gt;&lt;br /&gt;
  # constructor used when Account.new(...) called&amp;lt;br&amp;gt;&lt;br /&gt;
  def initialize(starting_balance=0) # optional argument&amp;lt;br&amp;gt;&lt;br /&gt;
    @balance = starting_balance&amp;lt;br&amp;gt;&lt;br /&gt;
  end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
account1 = Account.new 10&lt;br /&gt;
&amp;lt;/FONT&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Here the constructor, when invoked will create an object of type ‘Account’ represented by the name account1nitialize the instance variable balance to 10. Each object gets its own set of instance variables.&lt;br /&gt;
Different objects communicate together through methods. Each object can receive messages, send messages and process data.&lt;br /&gt;
&lt;br /&gt;
==Class==&lt;br /&gt;
A [http://www.ruby-doc.org/core-1.9.3/Class.html  class] can be defined as a blueprint for a data type. It defines the state and behaviour of the class, that is, what an object of the class will consist of and what operations can be performed on such an object. A class represents the real world entity.&lt;br /&gt;
&lt;br /&gt;
A class definition starts with the keyword class followed by the class name and is delimited with an end. For example we defined the BankAccount class using the keyword class as follows:&lt;br /&gt;
&lt;br /&gt;
Example:&amp;lt;br&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;class BankAccount&amp;lt;br&amp;gt;&lt;br /&gt;
  attr_accessor :name, :balance&amp;lt;br&amp;gt;&lt;br /&gt;
  def deposit(amt)&amp;lt;br&amp;gt;&lt;br /&gt;
    @balance+=amt&amp;lt;br&amp;gt;&lt;br /&gt;
  end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/FONT&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
The class BankAccount, contains instance variables(defined later) name and balance that defines the state of an object of the class and a method deposit that defines the behavior.  &lt;br /&gt;
Here, the name (BankAccount) must begin with a capital letter. By convention, names that contain more than one word run together with each word capitalized and no separating characters (CamelCase).&lt;br /&gt;
&lt;br /&gt;
==Inheritance==&lt;br /&gt;
One of the most important concepts in object-oriented programming is that of inheritance. Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application. The newly formed class is called the derived class or the sub-class, the class that we derive from is called base class or the super-class.&lt;br /&gt;
Although, inheritance provides an opportunity to reuse the code functionality and hasten  implementation time, Ruby does not support Multiple level of inheritances. However, this functionality can be implemented using another feature called [http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html mixins]. A mixin is like a specialized implementation of multiple inheritance in which only the interface portion is inherited.&lt;br /&gt;
The syntax for extending a class is by adding a “&amp;lt;” character and the name of the superclass to the class statement.&lt;br /&gt;
Example :&amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;class Account&amp;lt;br&amp;gt;&lt;br /&gt;
  # constructor used when Account.new(...) called&amp;lt;br&amp;gt;&lt;br /&gt;
  def initialize(starting_balance=0) # optional argument&amp;lt;br&amp;gt;&lt;br /&gt;
    @balance = starting_balance&amp;lt;br&amp;gt;&lt;br /&gt;
  end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class SharedAccount &amp;lt; Account&amp;lt;br&amp;gt;&lt;br /&gt;
 # adding another instance variable “common_fund” and an instance method “share”&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
def share(common=0) # optional argument&amp;lt;br&amp;gt;&lt;br /&gt;
    @common_fund = common&amp;lt;br&amp;gt;&lt;br /&gt;
    print &amp;quot;Total Balance : #{@balance + @common_fund}&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
  end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&lt;br /&gt;
a = SharedAccount.new 10&amp;lt;br&amp;gt;&lt;br /&gt;
a.share(20)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Output : Total Balance : 30&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/FONT&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
The above, will make use of both base class and derived class instance variables.&lt;br /&gt;
&lt;br /&gt;
==Instance Variables and Accessor Methods==&lt;br /&gt;
&lt;br /&gt;
===Instance Variables===&lt;br /&gt;
An instance variable begins with the symbol “@” in Ruby. It is different from a local variable because its scope is confined to the object to which self refers. Instance variables are invisible outside of the object. The only way we can access them or observer them is by writing methods to get or set the value of them. Instance variables have the value “nil” until they are initialized.&lt;br /&gt;
Instance variables do not need to be declared. In fact we can also access instance variables without declaring or initializing it, this will not raise an exception. However a warning will be issued if we run it using the –w switch.&lt;br /&gt;
Every instance variable is dynamically appended to an object in the first assignment.&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;@balance -&amp;gt; instance variable&amp;lt;/FONT&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
===Accessor Methods===&lt;br /&gt;
As stated previously, we cannot access instance variables from anywhere outside an object. Hence we need to define methods to access them. They are generally called as getter and setter methods.&lt;br /&gt;
The getter method is used to return the value of the instance variable. It would be defined as:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def balance &amp;lt;br&amp;gt;&lt;br /&gt;
@balance &amp;lt;br&amp;gt;&lt;br /&gt;
end &amp;lt;br&amp;gt;&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
The setter method is used to set the value of the instance variable. Setter methods always end with the “=” sign.  It would be defined as:&amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def balance= (bal) &amp;lt;br&amp;gt;&lt;br /&gt;
@balance = bal &amp;lt;br&amp;gt;&lt;br /&gt;
end &amp;lt;br&amp;gt;&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Instead of writing getter and setter methods for each class, we can use the attr_accessor function. The attr_accessor is a method call which uses metaprogramming to generate the getter and setter methods dynamically at run time.&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Example: &amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;attr_accessor :balance&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
This is equivalent to&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
def balance&amp;lt;br&amp;gt;&lt;br /&gt;
@balance&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
def balance= (bal)&amp;lt;br&amp;gt;&lt;br /&gt;
@balance = bal&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We can also generate getter and setter methods for more than one instance variable.&amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
attr_accessor :balance, :new_balance&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We can also use &amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;attr_reader&amp;lt;/FONT&amp;gt; if we only want to generate the getter function. Similarly we can use the method call &amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;attr_writer&amp;lt;/FONT&amp;gt; for generating just the setter function.&lt;br /&gt;
&lt;br /&gt;
==Instance Methods==&lt;br /&gt;
Instance methods work with instances of the class. So in order to use instance methods we have to create an instance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example: &amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def deposit&amp;lt;br&amp;gt;&lt;br /&gt;
@balance += amount&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt; &amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
You can include the definition of an instance method within the class like this: &lt;br /&gt;
Example: &amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;Class SavingsAccount &amp;lt; Account&amp;lt;br&amp;gt;&lt;br /&gt;
def deposit&amp;lt;br&amp;gt;@balance += amount&amp;lt;br&amp;gt; end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt; &amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Or you can also define it later. Since Ruby is a dynamic programming language we are allowed to reopen a class and add methods to it. For instance to add the deposit method after closing the class:&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;&lt;br /&gt;
Class SavingsAccount &amp;lt; Account&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&lt;br /&gt;
SAcc = SavingsAccount.new&amp;lt;br&amp;gt;&lt;br /&gt;
def SAcc.deposit&amp;lt;br&amp;gt;&lt;br /&gt;
@balance += amount&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
The save and update methods used in Rails are actually instance methods.&lt;br /&gt;
&lt;br /&gt;
There are two types of methods in Ruby: Safe methods and destructive methods. They are called as safe and destructive depending on whether they modify the input parameters passed to them. The destructive methods end with the “!” symbol, so that they can warn the programmer when he is writing the code. “&amp;lt;&amp;lt;” is another example of a destructive method.&lt;br /&gt;
&lt;br /&gt;
==Class Variables and Class Methods==&lt;br /&gt;
===Class Variables===&lt;br /&gt;
A class variable begins with the symbol “@@” in Ruby. Once we define a class variable it is set for the class and all of its subclasses.&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;@@bank_name = “MyBank.com”&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
We need to add a getter method to access the class variable from outside the class. This would look like:&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def self.bank_name&amp;lt;br&amp;gt;&lt;br /&gt;
@@bank_name&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
puts SavingsAccount.bank_name =&amp;gt; “MyBank.com” &amp;lt;br&amp;gt; &amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===Class Methods===&lt;br /&gt;
Class methods are equivalent to static methods in Java. Class methods only exist in the class that defined them. So we cannot call a class method with an instance variable, because the class method does not exist in the instance variable.&lt;br /&gt;
There are multiple ways of defining class methods.&amp;lt;br&amp;gt;&lt;br /&gt;
*&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def SavingsAccount.bank_name&amp;lt;/FONT&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def self.bank_name&amp;lt;/FONT&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;class &amp;lt;&amp;lt; self &amp;lt;br&amp;gt; def bank_name&amp;lt;/FONT&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Method 1 we use the class name followed by a dot followed by the class method name. In Method 2 we use the keyword [http://stackoverflow.com/questions/6669527/use-of-ruby-self-keyword self]. In Ruby self gives you access to the current object, when defined within a class it refers to the current class. Method 2 is frequently used to define a class method.&lt;br /&gt;
In the third method we are actually building an anonymous class for the current object (referred by self) using the &amp;lt;&amp;lt; notation. We are doing exactly what we did in Method 2, it is uncommon to see the use of Method 3.&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
[http://www.ruby-doc.org/docs/ProgrammingRuby/ Programming Ruby: The Pragmatic Programmer's Guide]: An excellent textbook for learning and understanding Ruby&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.ruby-lang.org/en/documentation/quickstart/ Ruby in 20 minutes] : An online tutorial for getting a hang of Ruby.&amp;lt;br&amp;gt;&lt;br /&gt;
[http://tryruby.org/levels/1/challenges/0 Try Ruby]: Try Ruby online without installing it on your machine&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Classes Wikibooks Programming Ruby]: A wikibook link for Programming Ruby&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object-oriented_programming1]http://en.wikipedia.org/wiki/Object-oriented_programming&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.ruby-doc.org/docs/ProgrammingRuby/html/2]http://www.ruby-doc.org/docs/ProgrammingRuby/html/&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rubyfleebie.com/understanding-class-methods-in-ruby/3]http://www.rubyfleebie.com/understanding-class-methods-in-ruby/&amp;lt;br&amp;gt;&lt;br /&gt;
[http://stackoverflow.com/questions/2084490/ruby-class-variables4]http://stackoverflow.com/questions/2084490/ruby-class-variables&amp;lt;br&amp;gt;&lt;br /&gt;
[http://railstips.org/blog/archives/2009/05/11/class-and-instance-methods-in-ruby/5]http://railstips.org/blog/archives/2009/05/11/class-and-instance-methods-in-ruby/&amp;lt;br&amp;gt;&lt;br /&gt;
[http://railsguru.org/2010/04/quick-ruby-tutorials-3-class-and-instance-methods6]http://railsguru.org/2010/04/quick-ruby-tutorials-3-class-and-instance-methods/&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rubyist.net/~slagell/ruby/instancevars.html7]http://www.rubyist.net/~slagell/ruby/instancevars.html&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rubyist.net/~slagell/ruby/accessors.html8]http://www.rubyist.net/~slagell/ruby/accessors.html&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w56_ms&amp;diff=67494</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w56 ms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w56_ms&amp;diff=67494"/>
		<updated>2012-10-11T01:52:15Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* Further Reading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
===What is Object Oriented Programming?===&lt;br /&gt;
Wikipedia defines [http://en.wikipedia.org/wiki/Object-oriented_programming Object-oriented programming (OOP)] as a programming paradigm that uses objects and their interactions to design applications and computer programs. &lt;br /&gt;
The primary programming concepts in OOP are:&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Abstraction_(computer_science) Abstraction] - hiding all but the necessary data about an object in order to reduce complexity and increase efficiency.&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Polymorphism_(computer_science) Polymorphism ] - characteristic of being able to assign a different meaning to a particular function or &amp;quot;operator&amp;quot; in different contexts.&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Encapsulation_(object-oriented_programming) Encapsulation] - hide the implementation details of a class from other objects.&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Inheritance_(computer_science) Inheritance] - form new classes using existing class definitions.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] is pure object-oriented language! i.e to Ruby, everything appears as an object. Every value in Ruby is an object, even the most primitive things: strings, numbers and even true and false. Ruby is so true to being object oriented that even a class is an object that is an instance of the ‘C’lass class. &lt;br /&gt;
In object-oriented code, we model concepts from the real world. During this modeling process you’ll different items to be represented. In Ruby, classes are defined to represent each of these items. Objects, which are instances of a class are nothing but different kinds of that item in terms of Ruby. &lt;br /&gt;
&lt;br /&gt;
Now let’s look at some basic object oriented concepts in Ruby.&lt;br /&gt;
&lt;br /&gt;
==Object==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_(computer_science) Objects] are basic building blocks of a Ruby OOP program. Every basic item, when being represented, can be given its own properties and actions. Object-oriented programming calls properties by the name instance variables , whose names starts with @, and actions are known as methods. &lt;br /&gt;
A '''class''' is a template for an '''object''', and an '''object''' is an instance of the class. Objects are created by calling a constructor, a special method associated with a class. The constructor in Ruby is called initialize. Constructors do not return any values. Constructors can be parameterized too, to contain values that initialize the instance method. This is also called the '''initialize method'''. For example,&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Example:&amp;lt;br&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;class Account&amp;lt;br&amp;gt;&lt;br /&gt;
  # constructor used when Account.new(...) called&amp;lt;br&amp;gt;&lt;br /&gt;
  def initialize(starting_balance=0) # optional argument&amp;lt;br&amp;gt;&lt;br /&gt;
    @balance = starting_balance&amp;lt;br&amp;gt;&lt;br /&gt;
  end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
account1 = Account.new 10&lt;br /&gt;
&amp;lt;/FONT&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Here the constructor, when invoked will create an object of type ‘Account’ represented by the name account1nitialize the instance variable balance to 10. Each object gets its own set of instance variables.&lt;br /&gt;
Different objects communicate together through methods. Each object can receive messages, send messages and process data.&lt;br /&gt;
&lt;br /&gt;
==Class==&lt;br /&gt;
A [http://www.ruby-doc.org/core-1.9.3/Class.html  class] can be defined as a blueprint for a data type. It defines the state and behaviour of the class, that is, what an object of the class will consist of and what operations can be performed on such an object. A class represents the real world entity.&lt;br /&gt;
&lt;br /&gt;
A class definition starts with the keyword class followed by the class name and is delimited with an end. For example we defined the BankAccount class using the keyword class as follows:&lt;br /&gt;
&lt;br /&gt;
Example:&amp;lt;br&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;class BankAccount&amp;lt;br&amp;gt;&lt;br /&gt;
  attr_accessor :name, :balance&amp;lt;br&amp;gt;&lt;br /&gt;
  def deposit(amt)&amp;lt;br&amp;gt;&lt;br /&gt;
    @balance+=amt&amp;lt;br&amp;gt;&lt;br /&gt;
  end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/FONT&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
The class BankAccount, contains instance variables(defined later) name and balance that defines the state of an object of the class and a method deposit that defines the behavior.  &lt;br /&gt;
Here, the name (BankAccount) must begin with a capital letter. By convention, names that contain more than one word run together with each word capitalized and no separating characters (CamelCase).&lt;br /&gt;
&lt;br /&gt;
==Inheritance==&lt;br /&gt;
One of the most important concepts in object-oriented programming is that of inheritance. Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application. The newly formed class is called the derived class or the sub-class, the class that we derive from is called base class or the super-class.&lt;br /&gt;
Although, inheritance provides an opportunity to reuse the code functionality and hasten  implementation time, Ruby does not support Multiple level of inheritances. However, this functionality can be implemented using another feature called [http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html mixins]. A mixin is like a specialized implementation of multiple inheritance in which only the interface portion is inherited.&lt;br /&gt;
The syntax for extending a class is by adding a “&amp;lt;” character and the name of the superclass to the class statement.&lt;br /&gt;
Example :&amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;class Account&amp;lt;br&amp;gt;&lt;br /&gt;
  # constructor used when Account.new(...) called&amp;lt;br&amp;gt;&lt;br /&gt;
  def initialize(starting_balance=0) # optional argument&amp;lt;br&amp;gt;&lt;br /&gt;
    @balance = starting_balance&amp;lt;br&amp;gt;&lt;br /&gt;
  end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class SharedAccount &amp;lt; Account&amp;lt;br&amp;gt;&lt;br /&gt;
 # adding another instance variable “common_fund” and an instance method “share”&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
def share(common=0) # optional argument&amp;lt;br&amp;gt;&lt;br /&gt;
    @common_fund = common&amp;lt;br&amp;gt;&lt;br /&gt;
    print &amp;quot;Total Balance : #{@balance + @common_fund}&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
  end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&lt;br /&gt;
a = SharedAccount.new 10&amp;lt;br&amp;gt;&lt;br /&gt;
a.share(20)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Output : Total Balance : 30&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/FONT&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
The above, will make use of both base class and derived class instance variables.&lt;br /&gt;
&lt;br /&gt;
==Instance Variables and Accessor Methods==&lt;br /&gt;
&lt;br /&gt;
===Instance Variables===&lt;br /&gt;
An instance variable begins with the symbol “@” in Ruby. It is different from a local variable because its scope is confined to the object to which self refers. Instance variables are invisible outside of the object. The only way we can access them or observer them is by writing methods to get or set the value of them. Instance variables have the value “nil” until they are initialized.&lt;br /&gt;
Instance variables do not need to be declared. In fact we can also access instance variables without declaring or initializing it, this will not raise an exception. However a warning will be issued if we run it using the –w switch.&lt;br /&gt;
Every instance variable is dynamically appended to an object in the first assignment.&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;@balance -&amp;gt; instance variable&amp;lt;/FONT&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
===Accessor Methods===&lt;br /&gt;
As stated previously, we cannot access instance variables from anywhere outside an object. Hence we need to define methods to access them. They are generally called as getter and setter methods.&lt;br /&gt;
The getter method is used to return the value of the instance variable. It would be defined as:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def balance &amp;lt;br&amp;gt;&lt;br /&gt;
@balance &amp;lt;br&amp;gt;&lt;br /&gt;
end &amp;lt;br&amp;gt;&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
The setter method is used to set the value of the instance variable. Setter methods always end with the “=” sign.  It would be defined as:&amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def balance= (bal) &amp;lt;br&amp;gt;&lt;br /&gt;
@balance = bal &amp;lt;br&amp;gt;&lt;br /&gt;
end &amp;lt;br&amp;gt;&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Instead of writing getter and setter methods for each class, we can use the attr_accessor function. The attr_accessor is a method call which uses metaprogramming to generate the getter and setter methods dynamically at run time.&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Example: &amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;attr_accessor :balance&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
This is equivalent to&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
def balance&amp;lt;br&amp;gt;&lt;br /&gt;
@balance&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
def balance= (bal)&amp;lt;br&amp;gt;&lt;br /&gt;
@balance = bal&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We can also generate getter and setter methods for more than one instance variable.&amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
attr_accessor :balance, :new_balance&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We can also use &amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;attr_reader&amp;lt;/FONT&amp;gt; if we only want to generate the getter function. Similarly we can use the method call &amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;attr_writer&amp;lt;/FONT&amp;gt; for generating just the setter function.&lt;br /&gt;
&lt;br /&gt;
==Instance Methods==&lt;br /&gt;
Instance methods work with instances of the class. So in order to use instance methods we have to create an instance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example: &amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def deposit&amp;lt;br&amp;gt;&lt;br /&gt;
@balance += amount&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt; &amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
You can include the definition of an instance method within the class like this: &lt;br /&gt;
Example: &amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;Class SavingsAccount &amp;lt; Account&amp;lt;br&amp;gt;&lt;br /&gt;
def deposit&amp;lt;br&amp;gt;@balance += amount&amp;lt;br&amp;gt; end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt; &amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Or you can also define it later. Since Ruby is a dynamic programming language we are allowed to reopen a class and add methods to it. For instance to add the deposit method after closing the class:&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;&lt;br /&gt;
Class SavingsAccount &amp;lt; Account&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&lt;br /&gt;
SAcc = SavingsAccount.new&amp;lt;br&amp;gt;&lt;br /&gt;
def SAcc.deposit&amp;lt;br&amp;gt;&lt;br /&gt;
@balance += amount&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
The save and update methods used in Rails are actually instance methods.&lt;br /&gt;
&lt;br /&gt;
There are two types of methods in Ruby: Safe methods and destructive methods. They are called as safe and destructive depending on whether they modify the input parameters passed to them. The destructive methods end with the “!” symbol, so that they can warn the programmer when he is writing the code. “&amp;lt;&amp;lt;” is another example of a destructive method.&lt;br /&gt;
&lt;br /&gt;
==Class Variables and Class Methods==&lt;br /&gt;
===Class Variables===&lt;br /&gt;
A class variable begins with the symbol “@@” in Ruby. Once we define a class variable it is set for the class and all of its subclasses.&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;@@bank_name = “MyBank.com”&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
We need to add a getter method to access the class variable from outside the class. This would look like:&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def self.bank_name&amp;lt;br&amp;gt;&lt;br /&gt;
@@bank_name&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
puts SavingsAccount.bank_name =&amp;gt; “MyBank.com” &amp;lt;br&amp;gt; &amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===Class Methods===&lt;br /&gt;
Class methods are equivalent to static methods in Java. Class methods only exist in the class that defined them. So we cannot call a class method with an instance variable, because the class method does not exist in the instance variable.&lt;br /&gt;
There are multiple ways of defining class methods.&amp;lt;br&amp;gt;&lt;br /&gt;
*&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def SavingsAccount.bank_name&amp;lt;/FONT&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def self.bank_name&amp;lt;/FONT&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;class &amp;lt;&amp;lt; self &amp;lt;br&amp;gt; def bank_name&amp;lt;/FONT&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Method 1 we use the class name followed by a dot followed by the class method name. In Method 2 we use the keyword [http://stackoverflow.com/questions/6669527/use-of-ruby-self-keyword self]. In Ruby self gives you access to the current object, when defined within a class it refers to the current class. Method 2 is frequently used to define a class method.&lt;br /&gt;
In the third method we are actually building an anonymous class for the current object (referred by self) using the &amp;lt;&amp;lt; notation. We are doing exactly what we did in Method 2, it is uncommon to see the use of Method 3.&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
[http://www.ruby-doc.org/docs/ProgrammingRuby/ Programming Ruby: The Pragmatic Programmer's Guide]: An excellent textbook for learning and understanding Ruby&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.ruby-lang.org/en/documentation/quickstart/ Ruby in 20 minutes] : An online tutorial for getting a hang of Ruby.&amp;lt;br&amp;gt;&lt;br /&gt;
[http://tryruby.org/levels/1/challenges/0 Try Ruby]: Try Ruby online without installing it on your machine!&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object-oriented_programming1]http://en.wikipedia.org/wiki/Object-oriented_programming&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.ruby-doc.org/docs/ProgrammingRuby/html/2]http://www.ruby-doc.org/docs/ProgrammingRuby/html/&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rubyfleebie.com/understanding-class-methods-in-ruby/3]http://www.rubyfleebie.com/understanding-class-methods-in-ruby/&amp;lt;br&amp;gt;&lt;br /&gt;
[http://stackoverflow.com/questions/2084490/ruby-class-variables4]http://stackoverflow.com/questions/2084490/ruby-class-variables&amp;lt;br&amp;gt;&lt;br /&gt;
[http://railstips.org/blog/archives/2009/05/11/class-and-instance-methods-in-ruby/5]http://railstips.org/blog/archives/2009/05/11/class-and-instance-methods-in-ruby/&amp;lt;br&amp;gt;&lt;br /&gt;
[http://railsguru.org/2010/04/quick-ruby-tutorials-3-class-and-instance-methods6]http://railsguru.org/2010/04/quick-ruby-tutorials-3-class-and-instance-methods/&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rubyist.net/~slagell/ruby/instancevars.html7]http://www.rubyist.net/~slagell/ruby/instancevars.html&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rubyist.net/~slagell/ruby/accessors.html8]http://www.rubyist.net/~slagell/ruby/accessors.html&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w56_ms&amp;diff=67490</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w56 ms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w56_ms&amp;diff=67490"/>
		<updated>2012-10-11T01:48:42Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
===What is Object Oriented Programming?===&lt;br /&gt;
Wikipedia defines [http://en.wikipedia.org/wiki/Object-oriented_programming Object-oriented programming (OOP)] as a programming paradigm that uses objects and their interactions to design applications and computer programs. &lt;br /&gt;
The primary programming concepts in OOP are:&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Abstraction_(computer_science) Abstraction] - hiding all but the necessary data about an object in order to reduce complexity and increase efficiency.&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Polymorphism_(computer_science) Polymorphism ] - characteristic of being able to assign a different meaning to a particular function or &amp;quot;operator&amp;quot; in different contexts.&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Encapsulation_(object-oriented_programming) Encapsulation] - hide the implementation details of a class from other objects.&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Inheritance_(computer_science) Inheritance] - form new classes using existing class definitions.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] is pure object-oriented language! i.e to Ruby, everything appears as an object. Every value in Ruby is an object, even the most primitive things: strings, numbers and even true and false. Ruby is so true to being object oriented that even a class is an object that is an instance of the ‘C’lass class. &lt;br /&gt;
In object-oriented code, we model concepts from the real world. During this modeling process you’ll different items to be represented. In Ruby, classes are defined to represent each of these items. Objects, which are instances of a class are nothing but different kinds of that item in terms of Ruby. &lt;br /&gt;
&lt;br /&gt;
Now let’s look at some basic object oriented concepts in Ruby.&lt;br /&gt;
&lt;br /&gt;
==Object==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_(computer_science) Objects] are basic building blocks of a Ruby OOP program. Every basic item, when being represented, can be given its own properties and actions. Object-oriented programming calls properties by the name instance variables , whose names starts with @, and actions are known as methods. &lt;br /&gt;
A '''class''' is a template for an '''object''', and an '''object''' is an instance of the class. Objects are created by calling a constructor, a special method associated with a class. The constructor in Ruby is called initialize. Constructors do not return any values. Constructors can be parameterized too, to contain values that initialize the instance method. This is also called the '''initialize method'''. For example,&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Example:&amp;lt;br&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;class Account&amp;lt;br&amp;gt;&lt;br /&gt;
  # constructor used when Account.new(...) called&amp;lt;br&amp;gt;&lt;br /&gt;
  def initialize(starting_balance=0) # optional argument&amp;lt;br&amp;gt;&lt;br /&gt;
    @balance = starting_balance&amp;lt;br&amp;gt;&lt;br /&gt;
  end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
account1 = Account.new 10&lt;br /&gt;
&amp;lt;/FONT&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Here the constructor, when invoked will create an object of type ‘Account’ represented by the name account1nitialize the instance variable balance to 10. Each object gets its own set of instance variables.&lt;br /&gt;
Different objects communicate together through methods. Each object can receive messages, send messages and process data.&lt;br /&gt;
&lt;br /&gt;
==Class==&lt;br /&gt;
A [http://www.ruby-doc.org/core-1.9.3/Class.html  class] can be defined as a blueprint for a data type. It defines the state and behaviour of the class, that is, what an object of the class will consist of and what operations can be performed on such an object. A class represents the real world entity.&lt;br /&gt;
&lt;br /&gt;
A class definition starts with the keyword class followed by the class name and is delimited with an end. For example we defined the BankAccount class using the keyword class as follows:&lt;br /&gt;
&lt;br /&gt;
Example:&amp;lt;br&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;class BankAccount&amp;lt;br&amp;gt;&lt;br /&gt;
  attr_accessor :name, :balance&amp;lt;br&amp;gt;&lt;br /&gt;
  def deposit(amt)&amp;lt;br&amp;gt;&lt;br /&gt;
    @balance+=amt&amp;lt;br&amp;gt;&lt;br /&gt;
  end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/FONT&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
The class BankAccount, contains instance variables(defined later) name and balance that defines the state of an object of the class and a method deposit that defines the behavior.  &lt;br /&gt;
Here, the name (BankAccount) must begin with a capital letter. By convention, names that contain more than one word run together with each word capitalized and no separating characters (CamelCase).&lt;br /&gt;
&lt;br /&gt;
==Inheritance==&lt;br /&gt;
One of the most important concepts in object-oriented programming is that of inheritance. Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application. The newly formed class is called the derived class or the sub-class, the class that we derive from is called base class or the super-class.&lt;br /&gt;
Although, inheritance provides an opportunity to reuse the code functionality and hasten  implementation time, Ruby does not support Multiple level of inheritances. However, this functionality can be implemented using another feature called [http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html mixins]. A mixin is like a specialized implementation of multiple inheritance in which only the interface portion is inherited.&lt;br /&gt;
The syntax for extending a class is by adding a “&amp;lt;” character and the name of the superclass to the class statement.&lt;br /&gt;
Example :&amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;class Account&amp;lt;br&amp;gt;&lt;br /&gt;
  # constructor used when Account.new(...) called&amp;lt;br&amp;gt;&lt;br /&gt;
  def initialize(starting_balance=0) # optional argument&amp;lt;br&amp;gt;&lt;br /&gt;
    @balance = starting_balance&amp;lt;br&amp;gt;&lt;br /&gt;
  end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class SharedAccount &amp;lt; Account&amp;lt;br&amp;gt;&lt;br /&gt;
 # adding another instance variable “common_fund” and an instance method “share”&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
def share(common=0) # optional argument&amp;lt;br&amp;gt;&lt;br /&gt;
    @common_fund = common&amp;lt;br&amp;gt;&lt;br /&gt;
    print &amp;quot;Total Balance : #{@balance + @common_fund}&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
  end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&lt;br /&gt;
a = SharedAccount.new 10&amp;lt;br&amp;gt;&lt;br /&gt;
a.share(20)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Output : Total Balance : 30&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/FONT&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
The above, will make use of both base class and derived class instance variables.&lt;br /&gt;
&lt;br /&gt;
==Instance Variables and Accessor Methods==&lt;br /&gt;
&lt;br /&gt;
===Instance Variables===&lt;br /&gt;
An instance variable begins with the symbol “@” in Ruby. It is different from a local variable because its scope is confined to the object to which self refers. Instance variables are invisible outside of the object. The only way we can access them or observer them is by writing methods to get or set the value of them. Instance variables have the value “nil” until they are initialized.&lt;br /&gt;
Instance variables do not need to be declared. In fact we can also access instance variables without declaring or initializing it, this will not raise an exception. However a warning will be issued if we run it using the –w switch.&lt;br /&gt;
Every instance variable is dynamically appended to an object in the first assignment.&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;@balance -&amp;gt; instance variable&amp;lt;/FONT&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
===Accessor Methods===&lt;br /&gt;
As stated previously, we cannot access instance variables from anywhere outside an object. Hence we need to define methods to access them. They are generally called as getter and setter methods.&lt;br /&gt;
The getter method is used to return the value of the instance variable. It would be defined as:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def balance &amp;lt;br&amp;gt;&lt;br /&gt;
@balance &amp;lt;br&amp;gt;&lt;br /&gt;
end &amp;lt;br&amp;gt;&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
The setter method is used to set the value of the instance variable. Setter methods always end with the “=” sign.  It would be defined as:&amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def balance= (bal) &amp;lt;br&amp;gt;&lt;br /&gt;
@balance = bal &amp;lt;br&amp;gt;&lt;br /&gt;
end &amp;lt;br&amp;gt;&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Instead of writing getter and setter methods for each class, we can use the attr_accessor function. The attr_accessor is a method call which uses metaprogramming to generate the getter and setter methods dynamically at run time.&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Example: &amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;attr_accessor :balance&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
This is equivalent to&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
def balance&amp;lt;br&amp;gt;&lt;br /&gt;
@balance&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
def balance= (bal)&amp;lt;br&amp;gt;&lt;br /&gt;
@balance = bal&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We can also generate getter and setter methods for more than one instance variable.&amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
attr_accessor :balance, :new_balance&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We can also use &amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;attr_reader&amp;lt;/FONT&amp;gt; if we only want to generate the getter function. Similarly we can use the method call &amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;attr_writer&amp;lt;/FONT&amp;gt; for generating just the setter function.&lt;br /&gt;
&lt;br /&gt;
==Instance Methods==&lt;br /&gt;
Instance methods work with instances of the class. So in order to use instance methods we have to create an instance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example: &amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def deposit&amp;lt;br&amp;gt;&lt;br /&gt;
@balance += amount&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt; &amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
You can include the definition of an instance method within the class like this: &lt;br /&gt;
Example: &amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;Class SavingsAccount &amp;lt; Account&amp;lt;br&amp;gt;&lt;br /&gt;
def deposit&amp;lt;br&amp;gt;@balance += amount&amp;lt;br&amp;gt; end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt; &amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Or you can also define it later. Since Ruby is a dynamic programming language we are allowed to reopen a class and add methods to it. For instance to add the deposit method after closing the class:&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;&lt;br /&gt;
Class SavingsAccount &amp;lt; Account&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&lt;br /&gt;
SAcc = SavingsAccount.new&amp;lt;br&amp;gt;&lt;br /&gt;
def SAcc.deposit&amp;lt;br&amp;gt;&lt;br /&gt;
@balance += amount&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
The save and update methods used in Rails are actually instance methods.&lt;br /&gt;
&lt;br /&gt;
There are two types of methods in Ruby: Safe methods and destructive methods. They are called as safe and destructive depending on whether they modify the input parameters passed to them. The destructive methods end with the “!” symbol, so that they can warn the programmer when he is writing the code. “&amp;lt;&amp;lt;” is another example of a destructive method.&lt;br /&gt;
&lt;br /&gt;
==Class Variables and Class Methods==&lt;br /&gt;
===Class Variables===&lt;br /&gt;
A class variable begins with the symbol “@@” in Ruby. Once we define a class variable it is set for the class and all of its subclasses.&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;@@bank_name = “MyBank.com”&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
We need to add a getter method to access the class variable from outside the class. This would look like:&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def self.bank_name&amp;lt;br&amp;gt;&lt;br /&gt;
@@bank_name&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
puts SavingsAccount.bank_name =&amp;gt; “MyBank.com” &amp;lt;br&amp;gt; &amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===Class Methods===&lt;br /&gt;
Class methods are equivalent to static methods in Java. Class methods only exist in the class that defined them. So we cannot call a class method with an instance variable, because the class method does not exist in the instance variable.&lt;br /&gt;
There are multiple ways of defining class methods.&amp;lt;br&amp;gt;&lt;br /&gt;
*&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def SavingsAccount.bank_name&amp;lt;/FONT&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def self.bank_name&amp;lt;/FONT&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;class &amp;lt;&amp;lt; self &amp;lt;br&amp;gt; def bank_name&amp;lt;/FONT&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Method 1 we use the class name followed by a dot followed by the class method name. In Method 2 we use the keyword [http://stackoverflow.com/questions/6669527/use-of-ruby-self-keyword self]. In Ruby self gives you access to the current object, when defined within a class it refers to the current class. Method 2 is frequently used to define a class method.&lt;br /&gt;
In the third method we are actually building an anonymous class for the current object (referred by self) using the &amp;lt;&amp;lt; notation. We are doing exactly what we did in Method 2, it is uncommon to see the use of Method 3.&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object-oriented_programming1]http://en.wikipedia.org/wiki/Object-oriented_programming&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.ruby-doc.org/docs/ProgrammingRuby/html/2]http://www.ruby-doc.org/docs/ProgrammingRuby/html/&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rubyfleebie.com/understanding-class-methods-in-ruby/3]http://www.rubyfleebie.com/understanding-class-methods-in-ruby/&amp;lt;br&amp;gt;&lt;br /&gt;
[http://stackoverflow.com/questions/2084490/ruby-class-variables4]http://stackoverflow.com/questions/2084490/ruby-class-variables&amp;lt;br&amp;gt;&lt;br /&gt;
[http://railstips.org/blog/archives/2009/05/11/class-and-instance-methods-in-ruby/5]http://railstips.org/blog/archives/2009/05/11/class-and-instance-methods-in-ruby/&amp;lt;br&amp;gt;&lt;br /&gt;
[http://railsguru.org/2010/04/quick-ruby-tutorials-3-class-and-instance-methods6]http://railsguru.org/2010/04/quick-ruby-tutorials-3-class-and-instance-methods/&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rubyist.net/~slagell/ruby/instancevars.html7]http://www.rubyist.net/~slagell/ruby/instancevars.html&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rubyist.net/~slagell/ruby/accessors.html8]http://www.rubyist.net/~slagell/ruby/accessors.html&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w56_ms&amp;diff=67489</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w56 ms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w56_ms&amp;diff=67489"/>
		<updated>2012-10-11T01:47:58Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
===What is Object Oriented Programming?===&lt;br /&gt;
Wikipedia defines [http://en.wikipedia.org/wiki/Object-oriented_programming Object-oriented programming (OOP)] as a programming paradigm that uses objects and their interactions to design applications and computer programs. &lt;br /&gt;
The primary programming concepts in OOP are:&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Abstraction_(computer_science) Abstraction] - hiding all but the necessary data about an object in order to reduce complexity and increase efficiency.&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Polymorphism_(computer_science) Polymorphism ] - characteristic of being able to assign a different meaning to a particular function or &amp;quot;operator&amp;quot; in different contexts.&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Encapsulation_(object-oriented_programming) Encapsulation] - hide the implementation details of a class from other objects.&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Inheritance_(computer_science) Inheritance] - form new classes using existing class definitions.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] is pure object-oriented language! i.e to Ruby, everything appears as an object. Every value in Ruby is an object, even the most primitive things: strings, numbers and even true and false. Ruby is so true to being object oriented that even a class is an object that is an instance of the ‘C’lass class. &lt;br /&gt;
In object-oriented code, we model concepts from the real world. During this modeling process you’ll different items to be represented. In Ruby, classes are defined to represent each of these items. Objects, which are instances of a class are nothing but different kinds of that item in terms of Ruby. &lt;br /&gt;
&lt;br /&gt;
Now let’s look at some basic object oriented concepts in Ruby.&lt;br /&gt;
&lt;br /&gt;
==Object==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_(computer_science) Objects] are basic building blocks of a Ruby OOP program. Every basic item, when being represented, can be given its own properties and actions. Object-oriented programming calls properties by the name instance variables , whose names starts with @, and actions are known as methods. &lt;br /&gt;
A '''class''' is a template for an '''object''', and an '''object''' is an instance of the class. Objects are created by calling a constructor, a special method associated with a class. The constructor in Ruby is called initialize. Constructors do not return any values. Constructors can be parameterized too, to contain values that initialize the instance method. This is also called the '''initialize method'''. For example,&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Example:&amp;lt;br&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;class Account&amp;lt;br&amp;gt;&lt;br /&gt;
  # constructor used when Account.new(...) called&amp;lt;br&amp;gt;&lt;br /&gt;
  def initialize(starting_balance=0) # optional argument&amp;lt;br&amp;gt;&lt;br /&gt;
    @balance = starting_balance&amp;lt;br&amp;gt;&lt;br /&gt;
  end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
account1 = Account.new 10&lt;br /&gt;
&amp;lt;/FONT&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Here the constructor, when invoked will create an object of type ‘Account’ represented by the name account1nitialize the instance variable balance to 10. Each object gets its own set of instance variables.&lt;br /&gt;
Different objects communicate together through methods. Each object can receive messages, send messages and process data.&lt;br /&gt;
&lt;br /&gt;
==Class==&lt;br /&gt;
A [http://www.ruby-doc.org/core-1.9.3/Class.html  class] can be defined as a blueprint for a data type. It defines the state and behaviour of the class, that is, what an object of the class will consist of and what operations can be performed on such an object. A class represents the real world entity.&lt;br /&gt;
&lt;br /&gt;
A class definition starts with the keyword class followed by the class name and is delimited with an end. For example we defined the BankAccount class using the keyword class as follows:&lt;br /&gt;
&lt;br /&gt;
Example:&amp;lt;br&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;class BankAccount&amp;lt;br&amp;gt;&lt;br /&gt;
  attr_accessor :name, :balance&amp;lt;br&amp;gt;&lt;br /&gt;
  def deposit(amt)&amp;lt;br&amp;gt;&lt;br /&gt;
    @balance+=amt&amp;lt;br&amp;gt;&lt;br /&gt;
  end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/FONT&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
The class BankAccount, contains instance variables(defined later) name and balance that defines the state of an object of the class and a method deposit that defines the behavior.  &lt;br /&gt;
Here, the name (BankAccount) must begin with a capital letter. By convention, names that contain more than one word run together with each word capitalized and no separating characters (CamelCase).&lt;br /&gt;
&lt;br /&gt;
==Inheritance==&lt;br /&gt;
One of the most important concepts in object-oriented programming is that of inheritance. Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application. The newly formed class is called the derived class or the sub-class, the class that we derive from is called base class or the super-class.&lt;br /&gt;
Although, inheritance provides an opportunity to reuse the code functionality and hasten  implementation time, Ruby does not support Multiple level of inheritances. However, this functionality can be implemented using another feature called [http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html mixins]. A mixin is like a specialized implementation of multiple inheritance in which only the interface portion is inherited.&lt;br /&gt;
The syntax for extending a class is by adding a “&amp;lt;” character and the name of the superclass to the class statement.&lt;br /&gt;
Example :&amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;class Account&amp;lt;br&amp;gt;&lt;br /&gt;
  # constructor used when Account.new(...) called&amp;lt;br&amp;gt;&lt;br /&gt;
  def initialize(starting_balance=0) # optional argument&amp;lt;br&amp;gt;&lt;br /&gt;
    @balance = starting_balance&amp;lt;br&amp;gt;&lt;br /&gt;
  end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class SharedAccount &amp;lt; Account&amp;lt;br&amp;gt;&lt;br /&gt;
 # adding another instance variable “common_fund” and an instance method “share”&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
def share(common=0) # optional argument&amp;lt;br&amp;gt;&lt;br /&gt;
    @common_fund = common&amp;lt;br&amp;gt;&lt;br /&gt;
    print &amp;quot;Total Balance : #{@balance + @common_fund}&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
  end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&lt;br /&gt;
a = SharedAccount.new 10&amp;lt;br&amp;gt;&lt;br /&gt;
a.share(20)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Output : Total Balance : 30&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/FONT&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
The above, will make use of both base class and derived class instance variables.&lt;br /&gt;
&lt;br /&gt;
==Instance Variables and Accessor Methods==&lt;br /&gt;
&lt;br /&gt;
===Instance Variables===&lt;br /&gt;
An instance variable begins with the symbol “@” in Ruby. It is different from a local variable because its scope is confined to the object to which self refers. Instance variables are invisible outside of the object. The only way we can access them or observer them is by writing methods to get or set the value of them. Instance variables have the value “nil” until they are initialized.&lt;br /&gt;
Instance variables do not need to be declared. In fact we can also access instance variables without declaring or initializing it, this will not raise an exception. However a warning will be issued if we run it using the –w switch.&lt;br /&gt;
Every instance variable is dynamically appended to an object in the first assignment.&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;@balance -&amp;gt; instance variable&amp;lt;/FONT&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
===Accessor Methods===&lt;br /&gt;
As stated previously, we cannot access instance variables from anywhere outside an object. Hence we need to define methods to access them. They are generally called as getter and setter methods.&lt;br /&gt;
The getter method is used to return the value of the instance variable. It would be defined as:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def balance &amp;lt;br&amp;gt;&lt;br /&gt;
@balance &amp;lt;br&amp;gt;&lt;br /&gt;
end &amp;lt;br&amp;gt;&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
The setter method is used to set the value of the instance variable. Setter methods always end with the “=” sign.  It would be defined as:&amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def balance= (bal) &amp;lt;br&amp;gt;&lt;br /&gt;
@balance = bal &amp;lt;br&amp;gt;&lt;br /&gt;
end &amp;lt;br&amp;gt;&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Instead of writing getter and setter methods for each class, we can use the attr_accessor function. The attr_accessor is a method call which uses metaprogramming to generate the getter and setter methods dynamically at run time.&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Example: &amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;attr_accessor :balance&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
This is equivalent to&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
def balance&amp;lt;br&amp;gt;&lt;br /&gt;
@balance&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
def balance= (bal)&amp;lt;br&amp;gt;&lt;br /&gt;
@balance = bal&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We can also generate getter and setter methods for more than one instance variable.&amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
attr_accessor :balance, :new_balance&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We can also use &amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;attr_reader&amp;lt;/FONT&amp;gt; if we only want to generate the getter function. Similarly we can use the method call &amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;attr_writer&amp;lt;/FONT&amp;gt; for generating just the setter function.&lt;br /&gt;
&lt;br /&gt;
==Instance Methods==&lt;br /&gt;
Instance methods work with instances of the class. So in order to use instance methods we have to create an instance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example: &amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def deposit&amp;lt;br&amp;gt;&lt;br /&gt;
@balance += amount&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt; &amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
You can include the definition of an instance method within the class like this: &lt;br /&gt;
Example: &amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;Class SavingsAccount &amp;lt; Account&amp;lt;br&amp;gt;&lt;br /&gt;
def deposit&amp;lt;br&amp;gt;@balance += amount&amp;lt;br&amp;gt; end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt; &amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Or you can also define it later. Since Ruby is a dynamic programming language we are allowed to reopen a class and add methods to it. For instance to add the deposit method after closing the class:&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;&lt;br /&gt;
Class SavingsAccount &amp;lt; Account&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&lt;br /&gt;
SAcc = SavingsAccount.new&amp;lt;br&amp;gt;&lt;br /&gt;
def SAcc.deposit&amp;lt;br&amp;gt;&lt;br /&gt;
@balance += amount&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
The save and update methods used in Rails are actually instance methods.&lt;br /&gt;
&lt;br /&gt;
There are two types of methods in Ruby: Safe methods and destructive methods. They are called as safe and destructive depending on whether they modify the input parameters passed to them. The destructive methods end with the “!” symbol, so that they can warn the programmer when he is writing the code. “&amp;lt;&amp;lt;” is another example of a destructive method.&lt;br /&gt;
&lt;br /&gt;
==Class Variables and Class Methods==&lt;br /&gt;
===Class Variables===&lt;br /&gt;
A class variable begins with the symbol “@@” in Ruby. Once we define a class variable it is set for the class and all of its subclasses.&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;@@bank_name = “MyBank.com”&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
We need to add a getter method to access the class variable from outside the class. This would look like:&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def self.bank_name&amp;lt;br&amp;gt;&lt;br /&gt;
@@bank_name&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
puts SavingsAccount.bank_name =&amp;gt; “MyBank.com” &amp;lt;br&amp;gt; &amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===Class Methods===&lt;br /&gt;
Class methods are equivalent to static methods in Java. Class methods only exist in the class that defined them. So we cannot call a class method with an instance variable, because the class method does not exist in the instance variable.&lt;br /&gt;
There are multiple ways of defining class methods.&amp;lt;br&amp;gt;&lt;br /&gt;
*&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def SavingsAccount.bank_name&amp;lt;/FONT&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def self.bank_name&amp;lt;/FONT&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;class &amp;lt;&amp;lt; self &amp;lt;br&amp;gt; def bank_name&amp;lt;/FONT&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Method 1 we use the class name followed by a dot followed by the class method name. In Method 2 we use the keyword [http://stackoverflow.com/questions/6669527/use-of-ruby-self-keyword self]. In Ruby self gives you access to the current object, when defined within a class it refers to the current class. Method 2 is frequently used to define a class method.&lt;br /&gt;
In the third method we are actually building an anonymous class for the current object (referred by self) using the &amp;lt;&amp;lt; notation. We are doing exactly what we did in Method 2, it is uncommon to see the use of Method 3.&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object-oriented_programming1]http://en.wikipedia.org/wiki/Object-oriented_programming&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.ruby-doc.org/docs/ProgrammingRuby/html/2]http://www.ruby-doc.org/docs/ProgrammingRuby/html/&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rubyfleebie.com/understanding-class-methods-in-ruby/3]http://www.rubyfleebie.com/understanding-class-methods-in-ruby/&amp;lt;br&amp;gt;&lt;br /&gt;
[http://stackoverflow.com/questions/2084490/ruby-class-variables 4]http://stackoverflow.com/questions/2084490/ruby-class-variables&amp;lt;br&amp;gt;&lt;br /&gt;
[http://railstips.org/blog/archives/2009/05/11/class-and-instance-methods-in-ruby/ 5]http://railstips.org/blog/archives/2009/05/11/class-and-instance-methods-in-ruby/&amp;lt;br&amp;gt;&lt;br /&gt;
[http://railsguru.org/2010/04/quick-ruby-tutorials-3-class-and-instance-methods 6]http://railsguru.org/2010/04/quick-ruby-tutorials-3-class-and-instance-methods/&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rubyist.net/~slagell/ruby/instancevars.html 7]http://www.rubyist.net/~slagell/ruby/instancevars.html&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rubyist.net/~slagell/ruby/accessors.html 8]http://www.rubyist.net/~slagell/ruby/accessors.html&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w56_ms&amp;diff=67488</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w56 ms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w56_ms&amp;diff=67488"/>
		<updated>2012-10-11T01:46:52Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
===What is Object Oriented Programming?===&lt;br /&gt;
Wikipedia defines [http://en.wikipedia.org/wiki/Object-oriented_programming Object-oriented programming (OOP)] as a programming paradigm that uses objects and their interactions to design applications and computer programs. &lt;br /&gt;
The primary programming concepts in OOP are:&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Abstraction_(computer_science) Abstraction] - hiding all but the necessary data about an object in order to reduce complexity and increase efficiency.&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Polymorphism_(computer_science) Polymorphism ] - characteristic of being able to assign a different meaning to a particular function or &amp;quot;operator&amp;quot; in different contexts.&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Encapsulation_(object-oriented_programming) Encapsulation] - hide the implementation details of a class from other objects.&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Inheritance_(computer_science) Inheritance] - form new classes using existing class definitions.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] is pure object-oriented language! i.e to Ruby, everything appears as an object. Every value in Ruby is an object, even the most primitive things: strings, numbers and even true and false. Ruby is so true to being object oriented that even a class is an object that is an instance of the ‘C’lass class. &lt;br /&gt;
In object-oriented code, we model concepts from the real world. During this modeling process you’ll different items to be represented. In Ruby, classes are defined to represent each of these items. Objects, which are instances of a class are nothing but different kinds of that item in terms of Ruby. &lt;br /&gt;
&lt;br /&gt;
Now let’s look at some basic object oriented concepts in Ruby.&lt;br /&gt;
&lt;br /&gt;
==Object==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_(computer_science) Objects] are basic building blocks of a Ruby OOP program. Every basic item, when being represented, can be given its own properties and actions. Object-oriented programming calls properties by the name instance variables , whose names starts with @, and actions are known as methods. &lt;br /&gt;
A '''class''' is a template for an '''object''', and an '''object''' is an instance of the class. Objects are created by calling a constructor, a special method associated with a class. The constructor in Ruby is called initialize. Constructors do not return any values. Constructors can be parameterized too, to contain values that initialize the instance method. This is also called the '''initialize method'''. For example,&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Example:&amp;lt;br&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;class Account&amp;lt;br&amp;gt;&lt;br /&gt;
  # constructor used when Account.new(...) called&amp;lt;br&amp;gt;&lt;br /&gt;
  def initialize(starting_balance=0) # optional argument&amp;lt;br&amp;gt;&lt;br /&gt;
    @balance = starting_balance&amp;lt;br&amp;gt;&lt;br /&gt;
  end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
account1 = Account.new 10&lt;br /&gt;
&amp;lt;/FONT&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Here the constructor, when invoked will create an object of type ‘Account’ represented by the name account1nitialize the instance variable balance to 10. Each object gets its own set of instance variables.&lt;br /&gt;
Different objects communicate together through methods. Each object can receive messages, send messages and process data.&lt;br /&gt;
&lt;br /&gt;
==Class==&lt;br /&gt;
A [http://www.ruby-doc.org/core-1.9.3/Class.html  class] can be defined as a blueprint for a data type. It defines the state and behaviour of the class, that is, what an object of the class will consist of and what operations can be performed on such an object. A class represents the real world entity.&lt;br /&gt;
&lt;br /&gt;
A class definition starts with the keyword class followed by the class name and is delimited with an end. For example we defined the BankAccount class using the keyword class as follows:&lt;br /&gt;
&lt;br /&gt;
Example:&amp;lt;br&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;class BankAccount&amp;lt;br&amp;gt;&lt;br /&gt;
  attr_accessor :name, :balance&amp;lt;br&amp;gt;&lt;br /&gt;
  def deposit(amt)&amp;lt;br&amp;gt;&lt;br /&gt;
    @balance+=amt&amp;lt;br&amp;gt;&lt;br /&gt;
  end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/FONT&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
The class BankAccount, contains instance variables(defined later) name and balance that defines the state of an object of the class and a method deposit that defines the behavior.  &lt;br /&gt;
Here, the name (BankAccount) must begin with a capital letter. By convention, names that contain more than one word run together with each word capitalized and no separating characters (CamelCase).&lt;br /&gt;
&lt;br /&gt;
==Inheritance==&lt;br /&gt;
One of the most important concepts in object-oriented programming is that of inheritance. Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application. The newly formed class is called the derived class or the sub-class, the class that we derive from is called base class or the super-class.&lt;br /&gt;
Although, inheritance provides an opportunity to reuse the code functionality and hasten  implementation time, Ruby does not support Multiple level of inheritances. However, this functionality can be implemented using another feature called [http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html mixins]. A mixin is like a specialized implementation of multiple inheritance in which only the interface portion is inherited.&lt;br /&gt;
The syntax for extending a class is by adding a “&amp;lt;” character and the name of the superclass to the class statement.&lt;br /&gt;
Example :&amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;class Account&amp;lt;br&amp;gt;&lt;br /&gt;
  # constructor used when Account.new(...) called&amp;lt;br&amp;gt;&lt;br /&gt;
  def initialize(starting_balance=0) # optional argument&amp;lt;br&amp;gt;&lt;br /&gt;
    @balance = starting_balance&amp;lt;br&amp;gt;&lt;br /&gt;
  end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class SharedAccount &amp;lt; Account&amp;lt;br&amp;gt;&lt;br /&gt;
 # adding another instance variable “common_fund” and an instance method “share”&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
def share(common=0) # optional argument&amp;lt;br&amp;gt;&lt;br /&gt;
    @common_fund = common&amp;lt;br&amp;gt;&lt;br /&gt;
    print &amp;quot;Total Balance : #{@balance + @common_fund}&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
  end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&lt;br /&gt;
a = SharedAccount.new 10&amp;lt;br&amp;gt;&lt;br /&gt;
a.share(20)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Output : Total Balance : 30&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/FONT&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
The above, will make use of both base class and derived class instance variables.&lt;br /&gt;
&lt;br /&gt;
==Instance Variables and Accessor Methods==&lt;br /&gt;
&lt;br /&gt;
===Instance Variables===&lt;br /&gt;
An instance variable begins with the symbol “@” in Ruby. It is different from a local variable because its scope is confined to the object to which self refers. Instance variables are invisible outside of the object. The only way we can access them or observer them is by writing methods to get or set the value of them. Instance variables have the value “nil” until they are initialized.&lt;br /&gt;
Instance variables do not need to be declared. In fact we can also access instance variables without declaring or initializing it, this will not raise an exception. However a warning will be issued if we run it using the –w switch.&lt;br /&gt;
Every instance variable is dynamically appended to an object in the first assignment.&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;@balance -&amp;gt; instance variable&amp;lt;/FONT&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
===Accessor Methods===&lt;br /&gt;
As stated previously, we cannot access instance variables from anywhere outside an object. Hence we need to define methods to access them. They are generally called as getter and setter methods.&lt;br /&gt;
The getter method is used to return the value of the instance variable. It would be defined as:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def balance &amp;lt;br&amp;gt;&lt;br /&gt;
@balance &amp;lt;br&amp;gt;&lt;br /&gt;
end &amp;lt;br&amp;gt;&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
The setter method is used to set the value of the instance variable. Setter methods always end with the “=” sign.  It would be defined as:&amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def balance= (bal) &amp;lt;br&amp;gt;&lt;br /&gt;
@balance = bal &amp;lt;br&amp;gt;&lt;br /&gt;
end &amp;lt;br&amp;gt;&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Instead of writing getter and setter methods for each class, we can use the attr_accessor function. The attr_accessor is a method call which uses metaprogramming to generate the getter and setter methods dynamically at run time.&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Example: &amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;attr_accessor :balance&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
This is equivalent to&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
def balance&amp;lt;br&amp;gt;&lt;br /&gt;
@balance&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
def balance= (bal)&amp;lt;br&amp;gt;&lt;br /&gt;
@balance = bal&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We can also generate getter and setter methods for more than one instance variable.&amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
attr_accessor :balance, :new_balance&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We can also use &amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;attr_reader&amp;lt;/FONT&amp;gt; if we only want to generate the getter function. Similarly we can use the method call &amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;attr_writer&amp;lt;/FONT&amp;gt; for generating just the setter function.&lt;br /&gt;
&lt;br /&gt;
==Instance Methods==&lt;br /&gt;
Instance methods work with instances of the class. So in order to use instance methods we have to create an instance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example: &amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def deposit&amp;lt;br&amp;gt;&lt;br /&gt;
@balance += amount&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt; &amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
You can include the definition of an instance method within the class like this: &lt;br /&gt;
Example: &amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;Class SavingsAccount &amp;lt; Account&amp;lt;br&amp;gt;&lt;br /&gt;
def deposit&amp;lt;br&amp;gt;@balance += amount&amp;lt;br&amp;gt; end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt; &amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Or you can also define it later. Since Ruby is a dynamic programming language we are allowed to reopen a class and add methods to it. For instance to add the deposit method after closing the class:&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;&lt;br /&gt;
Class SavingsAccount &amp;lt; Account&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&lt;br /&gt;
SAcc = SavingsAccount.new&amp;lt;br&amp;gt;&lt;br /&gt;
def SAcc.deposit&amp;lt;br&amp;gt;&lt;br /&gt;
@balance += amount&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
The save and update methods used in Rails are actually instance methods.&lt;br /&gt;
&lt;br /&gt;
There are two types of methods in Ruby: Safe methods and destructive methods. They are called as safe and destructive depending on whether they modify the input parameters passed to them. The destructive methods end with the “!” symbol, so that they can warn the programmer when he is writing the code. “&amp;lt;&amp;lt;” is another example of a destructive method.&lt;br /&gt;
&lt;br /&gt;
==Class Variables and Class Methods==&lt;br /&gt;
===Class Variables===&lt;br /&gt;
A class variable begins with the symbol “@@” in Ruby. Once we define a class variable it is set for the class and all of its subclasses.&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;@@bank_name = “MyBank.com”&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
We need to add a getter method to access the class variable from outside the class. This would look like:&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def self.bank_name&amp;lt;br&amp;gt;&lt;br /&gt;
@@bank_name&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
puts SavingsAccount.bank_name =&amp;gt; “MyBank.com” &amp;lt;br&amp;gt; &amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===Class Methods===&lt;br /&gt;
Class methods are equivalent to static methods in Java. Class methods only exist in the class that defined them. So we cannot call a class method with an instance variable, because the class method does not exist in the instance variable.&lt;br /&gt;
There are multiple ways of defining class methods.&amp;lt;br&amp;gt;&lt;br /&gt;
*&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def SavingsAccount.bank_name&amp;lt;/FONT&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def self.bank_name&amp;lt;/FONT&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;class &amp;lt;&amp;lt; self &amp;lt;br&amp;gt; def bank_name&amp;lt;/FONT&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Method 1 we use the class name followed by a dot followed by the class method name. In Method 2 we use the keyword [http://stackoverflow.com/questions/6669527/use-of-ruby-self-keyword self]. In Ruby self gives you access to the current object, when defined within a class it refers to the current class. Method 2 is frequently used to define a class method.&lt;br /&gt;
In the third method we are actually building an anonymous class for the current object (referred by self) using the &amp;lt;&amp;lt; notation. We are doing exactly what we did in Method 2, it is uncommon to see the use of Method 3.&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object-oriented_programming1]http://en.wikipedia.org/wiki/Object-oriented_programming&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.ruby-doc.org/docs/ProgrammingRuby/html/2]http://www.ruby-doc.org/docs/ProgrammingRuby/html/&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rubyfleebie.com/understanding-class-methods-in-ruby/3]http://www.rubyfleebie.com/understanding-class-methods-in-ruby/&amp;lt;br&amp;gt;&lt;br /&gt;
[4 http://stackoverflow.com/questions/2084490/ruby-class-variables]http://stackoverflow.com/questions/2084490/ruby-class-variables&amp;lt;br&amp;gt;&lt;br /&gt;
[5 http://railstips.org/blog/archives/2009/05/11/class-and-instance-methods-in-ruby/]http://railstips.org/blog/archives/2009/05/11/class-and-instance-methods-in-ruby/&amp;lt;br&amp;gt;&lt;br /&gt;
[6 http://railsguru.org/2010/04/quick-ruby-tutorials-3-class-and-instance-methods]http://railsguru.org/2010/04/quick-ruby-tutorials-3-class-and-instance-methods/&amp;lt;br&amp;gt;&lt;br /&gt;
[7 http://www.rubyist.net/~slagell/ruby/instancevars.html]http://www.rubyist.net/~slagell/ruby/instancevars.html&amp;lt;br&amp;gt;&lt;br /&gt;
[8 http://www.rubyist.net/~slagell/ruby/accessors.html]http://www.rubyist.net/~slagell/ruby/accessors.html&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w56_ms&amp;diff=67487</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w56 ms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w56_ms&amp;diff=67487"/>
		<updated>2012-10-11T01:44:05Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
===What is Object Oriented Programming?===&lt;br /&gt;
Wikipedia defines [http://en.wikipedia.org/wiki/Object-oriented_programming Object-oriented programming (OOP)] as a programming paradigm that uses objects and their interactions to design applications and computer programs. &lt;br /&gt;
The primary programming concepts in OOP are:&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Abstraction_(computer_science) Abstraction] - hiding all but the necessary data about an object in order to reduce complexity and increase efficiency.&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Polymorphism_(computer_science) Polymorphism ] - characteristic of being able to assign a different meaning to a particular function or &amp;quot;operator&amp;quot; in different contexts.&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Encapsulation_(object-oriented_programming) Encapsulation] - hide the implementation details of a class from other objects.&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Inheritance_(computer_science) Inheritance] - form new classes using existing class definitions.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] is pure object-oriented language! i.e to Ruby, everything appears as an object. Every value in Ruby is an object, even the most primitive things: strings, numbers and even true and false. Ruby is so true to being object oriented that even a class is an object that is an instance of the ‘C’lass class. &lt;br /&gt;
In object-oriented code, we model concepts from the real world. During this modeling process you’ll different items to be represented. In Ruby, classes are defined to represent each of these items. Objects, which are instances of a class are nothing but different kinds of that item in terms of Ruby. &lt;br /&gt;
&lt;br /&gt;
Now let’s look at some basic object oriented concepts in Ruby.&lt;br /&gt;
&lt;br /&gt;
==Object==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_(computer_science) Objects] are basic building blocks of a Ruby OOP program. Every basic item, when being represented, can be given its own properties and actions. Object-oriented programming calls properties by the name instance variables , whose names starts with @, and actions are known as methods. &lt;br /&gt;
A '''class''' is a template for an '''object''', and an '''object''' is an instance of the class. Objects are created by calling a constructor, a special method associated with a class. The constructor in Ruby is called initialize. Constructors do not return any values. Constructors can be parameterized too, to contain values that initialize the instance method. This is also called the '''initialize method'''. For example,&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Example:&amp;lt;br&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;class Account&amp;lt;br&amp;gt;&lt;br /&gt;
  # constructor used when Account.new(...) called&amp;lt;br&amp;gt;&lt;br /&gt;
  def initialize(starting_balance=0) # optional argument&amp;lt;br&amp;gt;&lt;br /&gt;
    @balance = starting_balance&amp;lt;br&amp;gt;&lt;br /&gt;
  end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
account1 = Account.new 10&lt;br /&gt;
&amp;lt;/FONT&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Here the constructor, when invoked will create an object of type ‘Account’ represented by the name account1nitialize the instance variable balance to 10. Each object gets its own set of instance variables.&lt;br /&gt;
Different objects communicate together through methods. Each object can receive messages, send messages and process data.&lt;br /&gt;
&lt;br /&gt;
==Class==&lt;br /&gt;
A [http://www.ruby-doc.org/core-1.9.3/Class.html  class] can be defined as a blueprint for a data type. It defines the state and behaviour of the class, that is, what an object of the class will consist of and what operations can be performed on such an object. A class represents the real world entity.&lt;br /&gt;
&lt;br /&gt;
A class definition starts with the keyword class followed by the class name and is delimited with an end. For example we defined the BankAccount class using the keyword class as follows:&lt;br /&gt;
&lt;br /&gt;
Example:&amp;lt;br&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;class BankAccount&amp;lt;br&amp;gt;&lt;br /&gt;
  attr_accessor :name, :balance&amp;lt;br&amp;gt;&lt;br /&gt;
  def deposit(amt)&amp;lt;br&amp;gt;&lt;br /&gt;
    @balance+=amt&amp;lt;br&amp;gt;&lt;br /&gt;
  end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/FONT&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
The class BankAccount, contains instance variables(defined later) name and balance that defines the state of an object of the class and a method deposit that defines the behavior.  &lt;br /&gt;
Here, the name (BankAccount) must begin with a capital letter. By convention, names that contain more than one word run together with each word capitalized and no separating characters (CamelCase).&lt;br /&gt;
&lt;br /&gt;
==Inheritance==&lt;br /&gt;
One of the most important concepts in object-oriented programming is that of inheritance. Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application. The newly formed class is called the derived class or the sub-class, the class that we derive from is called base class or the super-class.&lt;br /&gt;
Although, inheritance provides an opportunity to reuse the code functionality and hasten  implementation time, Ruby does not support Multiple level of inheritances. However, this functionality can be implemented using another feature called [http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html mixins]. A mixin is like a specialized implementation of multiple inheritance in which only the interface portion is inherited.&lt;br /&gt;
The syntax for extending a class is by adding a “&amp;lt;” character and the name of the superclass to the class statement.&lt;br /&gt;
Example :&amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;class Account&amp;lt;br&amp;gt;&lt;br /&gt;
  # constructor used when Account.new(...) called&amp;lt;br&amp;gt;&lt;br /&gt;
  def initialize(starting_balance=0) # optional argument&amp;lt;br&amp;gt;&lt;br /&gt;
    @balance = starting_balance&amp;lt;br&amp;gt;&lt;br /&gt;
  end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class SharedAccount &amp;lt; Account&amp;lt;br&amp;gt;&lt;br /&gt;
 # adding another instance variable “common_fund” and an instance method “share”&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
def share(common=0) # optional argument&amp;lt;br&amp;gt;&lt;br /&gt;
    @common_fund = common&amp;lt;br&amp;gt;&lt;br /&gt;
    print &amp;quot;Total Balance : #{@balance + @common_fund}&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
  end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&lt;br /&gt;
a = SharedAccount.new 10&amp;lt;br&amp;gt;&lt;br /&gt;
a.share(20)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Output : Total Balance : 30&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/FONT&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
The above, will make use of both base class and derived class instance variables.&lt;br /&gt;
&lt;br /&gt;
==Instance Variables and Accessor Methods==&lt;br /&gt;
&lt;br /&gt;
===Instance Variables===&lt;br /&gt;
An instance variable begins with the symbol “@” in Ruby. It is different from a local variable because its scope is confined to the object to which self refers. Instance variables are invisible outside of the object. The only way we can access them or observer them is by writing methods to get or set the value of them. Instance variables have the value “nil” until they are initialized.&lt;br /&gt;
Instance variables do not need to be declared. In fact we can also access instance variables without declaring or initializing it, this will not raise an exception. However a warning will be issued if we run it using the –w switch.&lt;br /&gt;
Every instance variable is dynamically appended to an object in the first assignment.&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;@balance -&amp;gt; instance variable&amp;lt;/FONT&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
===Accessor Methods===&lt;br /&gt;
As stated previously, we cannot access instance variables from anywhere outside an object. Hence we need to define methods to access them. They are generally called as getter and setter methods.&lt;br /&gt;
The getter method is used to return the value of the instance variable. It would be defined as:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def balance &amp;lt;br&amp;gt;&lt;br /&gt;
@balance &amp;lt;br&amp;gt;&lt;br /&gt;
end &amp;lt;br&amp;gt;&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
The setter method is used to set the value of the instance variable. Setter methods always end with the “=” sign.  It would be defined as:&amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def balance= (bal) &amp;lt;br&amp;gt;&lt;br /&gt;
@balance = bal &amp;lt;br&amp;gt;&lt;br /&gt;
end &amp;lt;br&amp;gt;&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Instead of writing getter and setter methods for each class, we can use the attr_accessor function. The attr_accessor is a method call which uses metaprogramming to generate the getter and setter methods dynamically at run time.&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Example: &amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;attr_accessor :balance&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
This is equivalent to&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
def balance&amp;lt;br&amp;gt;&lt;br /&gt;
@balance&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
def balance= (bal)&amp;lt;br&amp;gt;&lt;br /&gt;
@balance = bal&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We can also generate getter and setter methods for more than one instance variable.&amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
attr_accessor :balance, :new_balance&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We can also use &amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;attr_reader&amp;lt;/FONT&amp;gt; if we only want to generate the getter function. Similarly we can use the method call &amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;attr_writer&amp;lt;/FONT&amp;gt; for generating just the setter function.&lt;br /&gt;
&lt;br /&gt;
==Instance Methods==&lt;br /&gt;
Instance methods work with instances of the class. So in order to use instance methods we have to create an instance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example: &amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def deposit&amp;lt;br&amp;gt;&lt;br /&gt;
@balance += amount&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt; &amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
You can include the definition of an instance method within the class like this: &lt;br /&gt;
Example: &amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;Class SavingsAccount &amp;lt; Account&amp;lt;br&amp;gt;&lt;br /&gt;
def deposit&amp;lt;br&amp;gt;@balance += amount&amp;lt;br&amp;gt; end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt; &amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Or you can also define it later. Since Ruby is a dynamic programming language we are allowed to reopen a class and add methods to it. For instance to add the deposit method after closing the class:&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;&lt;br /&gt;
Class SavingsAccount &amp;lt; Account&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&lt;br /&gt;
SAcc = SavingsAccount.new&amp;lt;br&amp;gt;&lt;br /&gt;
def SAcc.deposit&amp;lt;br&amp;gt;&lt;br /&gt;
@balance += amount&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
The save and update methods used in Rails are actually instance methods.&lt;br /&gt;
&lt;br /&gt;
There are two types of methods in Ruby: Safe methods and destructive methods. They are called as safe and destructive depending on whether they modify the input parameters passed to them. The destructive methods end with the “!” symbol, so that they can warn the programmer when he is writing the code. “&amp;lt;&amp;lt;” is another example of a destructive method.&lt;br /&gt;
&lt;br /&gt;
==Class Variables and Class Methods==&lt;br /&gt;
===Class Variables===&lt;br /&gt;
A class variable begins with the symbol “@@” in Ruby. Once we define a class variable it is set for the class and all of its subclasses.&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;@@bank_name = “MyBank.com”&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
We need to add a getter method to access the class variable from outside the class. This would look like:&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def self.bank_name&amp;lt;br&amp;gt;&lt;br /&gt;
@@bank_name&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
puts SavingsAccount.bank_name =&amp;gt; “MyBank.com” &amp;lt;br&amp;gt; &amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===Class Methods===&lt;br /&gt;
Class methods are equivalent to static methods in Java. Class methods only exist in the class that defined them. So we cannot call a class method with an instance variable, because the class method does not exist in the instance variable.&lt;br /&gt;
There are multiple ways of defining class methods.&amp;lt;br&amp;gt;&lt;br /&gt;
*&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def SavingsAccount.bank_name&amp;lt;/FONT&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def self.bank_name&amp;lt;/FONT&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;class &amp;lt;&amp;lt; self &amp;lt;br&amp;gt; def bank_name&amp;lt;/FONT&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Method 1 we use the class name followed by a dot followed by the class method name. In Method 2 we use the keyword [http://stackoverflow.com/questions/6669527/use-of-ruby-self-keyword self]. In Ruby self gives you access to the current object, when defined within a class it refers to the current class. Method 2 is frequently used to define a class method.&lt;br /&gt;
In the third method we are actually building an anonymous class for the current object (referred by self) using the &amp;lt;&amp;lt; notation. We are doing exactly what we did in Method 2, it is uncommon to see the use of Method 3.&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object-oriented_programming1]http://en.wikipedia.org/wiki/Object-oriented_programming&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.ruby-doc.org/docs/ProgrammingRuby/html/2]http://www.ruby-doc.org/docs/ProgrammingRuby/html/&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rubyfleebie.com/understanding-class-methods-in-ruby/3]http://www.rubyfleebie.com/understanding-class-methods-in-ruby/&amp;lt;br&amp;gt;&lt;br /&gt;
[4http://stackoverflow.com/questions/2084490/ruby-class-variables]http://stackoverflow.com/questions/2084490/ruby-class-variables&amp;lt;br&amp;gt;&lt;br /&gt;
[5http://railstips.org/blog/archives/2009/05/11/class-and-instance-methods-in-ruby/]http://railstips.org/blog/archives/2009/05/11/class-and-instance-methods-in-ruby/&amp;lt;br&amp;gt;&lt;br /&gt;
[6http://railsguru.org/2010/04/quick-ruby-tutorials-3-class-and-instance-methods]http://railsguru.org/2010/04/quick-ruby-tutorials-3-class-and-instance-methods/&amp;lt;br&amp;gt;&lt;br /&gt;
[7http://www.rubyist.net/~slagell/ruby/instancevars.html]http://www.rubyist.net/~slagell/ruby/instancevars.html&amp;lt;br&amp;gt;&lt;br /&gt;
[8http://www.rubyist.net/~slagell/ruby/accessors.html]http://www.rubyist.net/~slagell/ruby/accessors.html&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w56_ms&amp;diff=67486</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w56 ms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w56_ms&amp;diff=67486"/>
		<updated>2012-10-11T01:39:18Z</updated>

		<summary type="html">&lt;p&gt;Msudhee: /* Class Methods */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
===What is Object Oriented Programming?===&lt;br /&gt;
Wikipedia defines [http://en.wikipedia.org/wiki/Object-oriented_programming Object-oriented programming (OOP)] as a programming paradigm that uses objects and their interactions to design applications and computer programs. &lt;br /&gt;
The primary programming concepts in OOP are:&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Abstraction_(computer_science) Abstraction] - hiding all but the necessary data about an object in order to reduce complexity and increase efficiency.&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Polymorphism_(computer_science) Polymorphism ] - characteristic of being able to assign a different meaning to a particular function or &amp;quot;operator&amp;quot; in different contexts.&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Encapsulation_(object-oriented_programming) Encapsulation] - hide the implementation details of a class from other objects.&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Inheritance_(computer_science) Inheritance] - form new classes using existing class definitions.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] is pure object-oriented language! i.e to Ruby, everything appears as an object. Every value in Ruby is an object, even the most primitive things: strings, numbers and even true and false. Ruby is so true to being object oriented that even a class is an object that is an instance of the ‘C’lass class. &lt;br /&gt;
In object-oriented code, we model concepts from the real world. During this modeling process you’ll different items to be represented. In Ruby, classes are defined to represent each of these items. Objects, which are instances of a class are nothing but different kinds of that item in terms of Ruby. &lt;br /&gt;
&lt;br /&gt;
Now let’s look at some basic object oriented concepts in Ruby.&lt;br /&gt;
&lt;br /&gt;
==Object==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Object_(computer_science) Objects] are basic building blocks of a Ruby OOP program. Every basic item, when being represented, can be given its own properties and actions. Object-oriented programming calls properties by the name instance variables , whose names starts with @, and actions are known as methods. &lt;br /&gt;
A '''class''' is a template for an '''object''', and an '''object''' is an instance of the class. Objects are created by calling a constructor, a special method associated with a class. The constructor in Ruby is called initialize. Constructors do not return any values. Constructors can be parameterized too, to contain values that initialize the instance method. This is also called the '''initialize method'''. For example,&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Example:&amp;lt;br&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;class Account&amp;lt;br&amp;gt;&lt;br /&gt;
  # constructor used when Account.new(...) called&amp;lt;br&amp;gt;&lt;br /&gt;
  def initialize(starting_balance=0) # optional argument&amp;lt;br&amp;gt;&lt;br /&gt;
    @balance = starting_balance&amp;lt;br&amp;gt;&lt;br /&gt;
  end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
account1 = Account.new 10&lt;br /&gt;
&amp;lt;/FONT&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Here the constructor, when invoked will create an object of type ‘Account’ represented by the name account1nitialize the instance variable balance to 10. Each object gets its own set of instance variables.&lt;br /&gt;
Different objects communicate together through methods. Each object can receive messages, send messages and process data.&lt;br /&gt;
&lt;br /&gt;
==Class==&lt;br /&gt;
A [http://www.ruby-doc.org/core-1.9.3/Class.html  class] can be defined as a blueprint for a data type. It defines the state and behaviour of the class, that is, what an object of the class will consist of and what operations can be performed on such an object. A class represents the real world entity.&lt;br /&gt;
&lt;br /&gt;
A class definition starts with the keyword class followed by the class name and is delimited with an end. For example we defined the BankAccount class using the keyword class as follows:&lt;br /&gt;
&lt;br /&gt;
Example:&amp;lt;br&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;class BankAccount&amp;lt;br&amp;gt;&lt;br /&gt;
  attr_accessor :name, :balance&amp;lt;br&amp;gt;&lt;br /&gt;
  def deposit(amt)&amp;lt;br&amp;gt;&lt;br /&gt;
    @balance+=amt&amp;lt;br&amp;gt;&lt;br /&gt;
  end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/FONT&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
The class BankAccount, contains instance variables(defined later) name and balance that defines the state of an object of the class and a method deposit that defines the behavior.  &lt;br /&gt;
Here, the name (BankAccount) must begin with a capital letter. By convention, names that contain more than one word run together with each word capitalized and no separating characters (CamelCase).&lt;br /&gt;
&lt;br /&gt;
==Inheritance==&lt;br /&gt;
One of the most important concepts in object-oriented programming is that of inheritance. Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application. The newly formed class is called the derived class or the sub-class, the class that we derive from is called base class or the super-class.&lt;br /&gt;
Although, inheritance provides an opportunity to reuse the code functionality and hasten  implementation time, Ruby does not support Multiple level of inheritances. However, this functionality can be implemented using another feature called [http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html mixins]. A mixin is like a specialized implementation of multiple inheritance in which only the interface portion is inherited.&lt;br /&gt;
The syntax for extending a class is by adding a “&amp;lt;” character and the name of the superclass to the class statement.&lt;br /&gt;
Example :&amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;class Account&amp;lt;br&amp;gt;&lt;br /&gt;
  # constructor used when Account.new(...) called&amp;lt;br&amp;gt;&lt;br /&gt;
  def initialize(starting_balance=0) # optional argument&amp;lt;br&amp;gt;&lt;br /&gt;
    @balance = starting_balance&amp;lt;br&amp;gt;&lt;br /&gt;
  end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class SharedAccount &amp;lt; Account&amp;lt;br&amp;gt;&lt;br /&gt;
 # adding another instance variable “common_fund” and an instance method “share”&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
def share(common=0) # optional argument&amp;lt;br&amp;gt;&lt;br /&gt;
    @common_fund = common&amp;lt;br&amp;gt;&lt;br /&gt;
    print &amp;quot;Total Balance : #{@balance + @common_fund}&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
  end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&lt;br /&gt;
a = SharedAccount.new 10&amp;lt;br&amp;gt;&lt;br /&gt;
a.share(20)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Output : Total Balance : 30&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/FONT&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
The above, will make use of both base class and derived class instance variables.&lt;br /&gt;
&lt;br /&gt;
==Instance Variables and Accessor Methods==&lt;br /&gt;
&lt;br /&gt;
===Instance Variables===&lt;br /&gt;
An instance variable begins with the symbol “@” in Ruby. It is different from a local variable because its scope is confined to the object to which self refers. Instance variables are invisible outside of the object. The only way we can access them or observer them is by writing methods to get or set the value of them. Instance variables have the value “nil” until they are initialized.&lt;br /&gt;
Instance variables do not need to be declared. In fact we can also access instance variables without declaring or initializing it, this will not raise an exception. However a warning will be issued if we run it using the –w switch.&lt;br /&gt;
Every instance variable is dynamically appended to an object in the first assignment.&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;@balance -&amp;gt; instance variable&amp;lt;/FONT&amp;gt; &lt;br /&gt;
----&lt;br /&gt;
===Accessor Methods===&lt;br /&gt;
As stated previously, we cannot access instance variables from anywhere outside an object. Hence we need to define methods to access them. They are generally called as getter and setter methods.&lt;br /&gt;
The getter method is used to return the value of the instance variable. It would be defined as:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def balance &amp;lt;br&amp;gt;&lt;br /&gt;
@balance &amp;lt;br&amp;gt;&lt;br /&gt;
end &amp;lt;br&amp;gt;&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
The setter method is used to set the value of the instance variable. Setter methods always end with the “=” sign.  It would be defined as:&amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def balance= (bal) &amp;lt;br&amp;gt;&lt;br /&gt;
@balance = bal &amp;lt;br&amp;gt;&lt;br /&gt;
end &amp;lt;br&amp;gt;&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Instead of writing getter and setter methods for each class, we can use the attr_accessor function. The attr_accessor is a method call which uses metaprogramming to generate the getter and setter methods dynamically at run time.&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Example: &amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;attr_accessor :balance&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
This is equivalent to&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
def balance&amp;lt;br&amp;gt;&lt;br /&gt;
@balance&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
def balance= (bal)&amp;lt;br&amp;gt;&lt;br /&gt;
@balance = bal&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We can also generate getter and setter methods for more than one instance variable.&amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
attr_accessor :balance, :new_balance&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
We can also use &amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;attr_reader&amp;lt;/FONT&amp;gt; if we only want to generate the getter function. Similarly we can use the method call &amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;attr_writer&amp;lt;/FONT&amp;gt; for generating just the setter function.&lt;br /&gt;
&lt;br /&gt;
==Instance Methods==&lt;br /&gt;
Instance methods work with instances of the class. So in order to use instance methods we have to create an instance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example: &amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def deposit&amp;lt;br&amp;gt;&lt;br /&gt;
@balance += amount&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt; &amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
You can include the definition of an instance method within the class like this: &lt;br /&gt;
Example: &amp;lt;br&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;Class SavingsAccount &amp;lt; Account&amp;lt;br&amp;gt;&lt;br /&gt;
def deposit&amp;lt;br&amp;gt;@balance += amount&amp;lt;br&amp;gt; end&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt; &amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Or you can also define it later. Since Ruby is a dynamic programming language we are allowed to reopen a class and add methods to it. For instance to add the deposit method after closing the class:&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;&lt;br /&gt;
Class SavingsAccount &amp;lt; Account&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&lt;br /&gt;
SAcc = SavingsAccount.new&amp;lt;br&amp;gt;&lt;br /&gt;
def SAcc.deposit&amp;lt;br&amp;gt;&lt;br /&gt;
@balance += amount&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
The save and update methods used in Rails are actually instance methods.&lt;br /&gt;
&lt;br /&gt;
There are two types of methods in Ruby: Safe methods and destructive methods. They are called as safe and destructive depending on whether they modify the input parameters passed to them. The destructive methods end with the “!” symbol, so that they can warn the programmer when he is writing the code. “&amp;lt;&amp;lt;” is another example of a destructive method.&lt;br /&gt;
&lt;br /&gt;
==Class Variables and Class Methods==&lt;br /&gt;
===Class Variables===&lt;br /&gt;
A class variable begins with the symbol “@@” in Ruby. Once we define a class variable it is set for the class and all of its subclasses.&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;@@bank_name = “MyBank.com”&amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
We need to add a getter method to access the class variable from outside the class. This would look like:&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def self.bank_name&amp;lt;br&amp;gt;&lt;br /&gt;
@@bank_name&amp;lt;br&amp;gt;&lt;br /&gt;
end&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
puts SavingsAccount.bank_name =&amp;gt; “MyBank.com” &amp;lt;br&amp;gt; &amp;lt;/FONT&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===Class Methods===&lt;br /&gt;
Class methods are equivalent to static methods in Java. Class methods only exist in the class that defined them. So we cannot call a class method with an instance variable, because the class method does not exist in the instance variable.&lt;br /&gt;
There are multiple ways of defining class methods.&amp;lt;br&amp;gt;&lt;br /&gt;
*&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def SavingsAccount.bank_name&amp;lt;/FONT&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;def self.bank_name&amp;lt;/FONT&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*&amp;lt;FONT FACE=&amp;quot;courier&amp;quot;&amp;gt;class &amp;lt;&amp;lt; self &amp;lt;br&amp;gt; def bank_name&amp;lt;/FONT&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Method 1 we use the class name followed by a dot followed by the class method name. In Method 2 we use the keyword [http://stackoverflow.com/questions/6669527/use-of-ruby-self-keyword self]. In Ruby self gives you access to the current object, when defined within a class it refers to the current class. Method 2 is frequently used to define a class method.&lt;br /&gt;
In the third method we are actually building an anonymous class for the current object (referred by self) using the &amp;lt;&amp;lt; notation. We are doing exactly what we did in Method 2, it is uncommon to see the use of Method 3.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1]http://en.wikipedia.org/wiki/Object-oriented_programming&amp;lt;br&amp;gt;&lt;br /&gt;
[2]http://www.ruby-doc.org/docs/ProgrammingRuby/html/&amp;lt;br&amp;gt;&lt;br /&gt;
[3]http://www.rubyfleebie.com/understanding-class-methods-in-ruby/&amp;lt;br&amp;gt;&lt;br /&gt;
[4]http://stackoverflow.com/questions/2084490/ruby-class-variables&amp;lt;br&amp;gt;&lt;br /&gt;
[5]http://railstips.org/blog/archives/2009/05/11/class-and-instance-methods-in-ruby/&amp;lt;br&amp;gt;&lt;br /&gt;
[6]http://railsguru.org/2010/04/quick-ruby-tutorials-3-class-and-instance-methods/&amp;lt;br&amp;gt;&lt;br /&gt;
[7]http://www.rubyist.net/~slagell/ruby/instancevars.html&amp;lt;br&amp;gt;&lt;br /&gt;
[8]http://www.rubyist.net/~slagell/ruby/accessors.html&lt;/div&gt;</summary>
		<author><name>Msudhee</name></author>
	</entry>
</feed>