<?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=Gshah</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=Gshah"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Gshah"/>
	<updated>2026-09-12T16:22:09Z</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_2014/oss_E1457_ags&amp;diff=91479</id>
		<title>CSC/ECE 517 Fall 2014/oss E1457 ags</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1457_ags&amp;diff=91479"/>
		<updated>2014-11-06T03:13:34Z</updated>

		<summary type="html">&lt;p&gt;Gshah: /* Code Smells */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring DynamicReviewMapping Controller and the ReportsController=&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
It is time consuming to assess project work in a large classroom environment, and one of the best techniques to achieve this is to have students assist in this assessment.  If each student is asked to assess a few (say, one to five) other students or student teams, the task requires a reasonable amount of effort; and that effort does not increase as the class gets larger. &amp;quot;''Expertiza is a system for managing all kinds of communication that is involved in assessment: double-blind communications between authors and reviewers, assessment of teammate contributions, evaluations by course staff, and surveys of students to assess the assignment and the &lt;br /&gt;
peer-review process.''&amp;quot; &amp;lt;ref&amp;gt;http://www.igi-global.com/book/monitoring-assessment-online-collaborative-environments/773&amp;amp;f=e-book&amp;lt;/ref&amp;gt;&lt;br /&gt;
''&amp;quot;Expertiza project uses peer review to create reusable learning objects.''&amp;quot;&amp;lt;ref&amp;gt;http://expertiza.ncsu.edu/&amp;lt;/ref&amp;gt; Students select from a list of tasks to be performed, with several students selecting each task. Then they prepare their work and submit it to an electronic peer-review system. The work is then reviewed by other students, who offer comments to help the submitters improve their work. The best submissions for each task are then selected for use in later courses. Expertiza gets students working together to improve others’ learning experiences. It helps them learn, by making them think through the lecture material and apply it to a real-world situation, just as they might do in an on-the-job situation. These learning objects can be improved iteratively; for example, the next year’s class can be presented with the examples developed by students the previous year, and asked to identify shortcomings and develop improved examples.&amp;lt;ref&amp;gt;http://scholar.google.com/scholar?q=%22Reusable+learning+objects+through+peer+review%3A+The+Expertiza+approach%22+%22The+Expertiza+platform+is+a+divide-and-conquer%22&amp;amp;btnG=&amp;amp;hl=en&amp;amp;as_sdt=0%2C34&amp;lt;/ref&amp;gt; More information on Expertiza can be found [https://github.com/expertiza/expertiza here].&lt;br /&gt;
&lt;br /&gt;
==Refactoring in Ruby==&lt;br /&gt;
Refactoring helps to&amp;lt;ref&amp;gt;http://www.refactoringinruby.com/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*Understand what led to poor code design&lt;br /&gt;
*Fix code which is difficult to understand&lt;br /&gt;
*Express each idea “once and only once”&lt;br /&gt;
*Recognize missing or inadequately formed classes&lt;br /&gt;
*Simplify overly complex relationships between classes&lt;br /&gt;
*Achieve the right balance of responsibilities among objects&lt;br /&gt;
*Make code easier to test and more maintainable&lt;br /&gt;
&lt;br /&gt;
===Code Smells===&lt;br /&gt;
We identified the following categories of code smells in the helper module:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Lengthy Definitions&amp;lt;/b&amp;gt;: These are the methods that have too many responsibilities and collaborators. As a result of which, their overall length has grown too long reducing the maintainability and readability.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplicated Code&amp;lt;/b&amp;gt;: These are those pieces of code that does almost the same functionality of some other piece of code leading to a bad design style. They are usually too error prone since not everyone identifies all the code responsible for the same task and does the changes whenever the need arises.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Bad method names&amp;lt;/b&amp;gt;: A good method name is expected to adhere to the Ruby style and design style guidelines. It is expected to convey a reasonable amount of responsibilities handled. A good method name in combination with good practices should resemble a user story.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;Used and unnecessary methods&amp;lt;/b&amp;gt;: These are those methods that were useful when the code was first developed. But, they lost their functionality as the code got updated and new functionalities were added or existing ones were modified.&lt;br /&gt;
&lt;br /&gt;
===Refactoring Techniques===&lt;br /&gt;
There are many documented refactoring techniques, and a few common ones are below.&amp;lt;ref&amp;gt;http://www.integralist.co.uk/posts/refactoring-techniques/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*'''Rename Method''': Renaming identifiers can reduce the need for code comments and nearly always helps to promote greater clarity.&lt;br /&gt;
*'''Introduce Explaining Variable''': So here is a technique specifically based around the premise of renaming.&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless &amp;quot;This is a String with some CAPS&amp;quot;.scan(/([A-Z])/).empty?&lt;br /&gt;
  puts &amp;quot;capitalised text was found&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Should be:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
caps_not_found = &amp;quot;This is a String with some CAPS&amp;quot;.scan(/([A-Z])/).empty?&lt;br /&gt;
&lt;br /&gt;
unless caps_not_found&lt;br /&gt;
  puts &amp;quot;capitalised text was found&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Extract Method''':  It consists of breaking up long methods by shifting overly complex chunks of code into new methods which have very descriptive identifiers.&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Foo&lt;br /&gt;
  attr_reader :bar&lt;br /&gt;
&lt;br /&gt;
  def initialize bar&lt;br /&gt;
    @bar = bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def do_something&lt;br /&gt;
    puts &amp;quot;my baz&amp;quot; # notice this is duplication&lt;br /&gt;
    puts bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def do_something_else&lt;br /&gt;
    puts &amp;quot;my baz&amp;quot; # notice this is duplication&lt;br /&gt;
    puts &amp;quot;Something else&amp;quot;&lt;br /&gt;
    puts bar&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Becomes:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Foo&lt;br /&gt;
  attr_reader :bar&lt;br /&gt;
&lt;br /&gt;
  def initialize bar&lt;br /&gt;
    @bar = bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def do_something&lt;br /&gt;
    baz&lt;br /&gt;
    puts bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def do_something_else&lt;br /&gt;
    baz&lt;br /&gt;
    puts &amp;quot;Something else&amp;quot;&lt;br /&gt;
    puts bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def baz&lt;br /&gt;
    puts &amp;quot;my baz&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Inline Method''': Sometimes you want the opposite of the Extract Method technique. Imagine a method exists whose content is already simple and clear, and whose identifier adds no extra benefit. So to fix this problem we'll convert the method invocation into an inlined piece of code.&lt;br /&gt;
&lt;br /&gt;
*'''Pull Up Method''': When you have duplicated code across two separate classes then the best refactoring technique to implement is to pull that duplicate code up into a super class so we DRY (Don't Repeat Yourself) out the code and allow it to be used in multiple places without duplication (meaning changes in future only have to happen in one place).&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
  attr_reader :first_name, :last_name&lt;br /&gt;
&lt;br /&gt;
  def initialize first_name, last_name&lt;br /&gt;
    @first_name = first_name&lt;br /&gt;
    @last_name = last_name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class MalePerson &amp;lt; Person&lt;br /&gt;
  # This is duplicated in the `FemalePerson` class&lt;br /&gt;
  def full_name&lt;br /&gt;
    first_name + &amp;quot; &amp;quot; + last_name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def gender&lt;br /&gt;
    &amp;quot;M&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class FemalePerson &amp;lt; Person&lt;br /&gt;
  # This is duplicated in the `MalePerson` class&lt;br /&gt;
  def full_name&lt;br /&gt;
    first_name + &amp;quot; &amp;quot; + last_name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def gender&lt;br /&gt;
    &amp;quot;F&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Becomes:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
  attr_reader :first_name, :last_name&lt;br /&gt;
&lt;br /&gt;
  def initialize first_name, last_name&lt;br /&gt;
    @first_name = first_name&lt;br /&gt;
    @last_name = last_name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def full_name&lt;br /&gt;
    first_name + &amp;quot; &amp;quot; + last_name&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class MalePerson &amp;lt; Person&lt;br /&gt;
  def gender&lt;br /&gt;
    &amp;quot;M&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class FemalePerson &amp;lt; Person&lt;br /&gt;
  def gender&lt;br /&gt;
    &amp;quot;F&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Introduce Named Parameter''':When method arguments are unclear then convert them into named parameters so they become clearer (and easier to remember).&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
We were supposed to refactor two controllers, the ReportsController and the DynamicReviewMapping Controller. The ReportsController was thought to be generating reports for students, showing all their scores in a single page. The DynamicReviewMapping Controller is actually a helper to the ReviewMapping controller. The review mapping controller maps reviews to each user. Currently, there are two ways to assign reviews to user: The user can either select a submission himself, which he wants to review, or the site can suggest a review to the user. Currently, the user can give more than two reviews. The ReviewMapping controller had a method so that all the users are assigned reviews automatically. Originally, the plan was to assign only a fixed number of reviews to each user. The dynamic review controller helped the review mapping controller assign reviews so that the reviews are never mapped such that the last user does not have any review to map, except his own. For example, consider three users, U1, U2 and U3. If U1 is assigned U2's work and U2 is assigned U1's work, U3 would not have any work to review. The dynamic review mapping controller makes sure that such a condition does not occur.&lt;br /&gt;
&lt;br /&gt;
We were supposed to refactor these controllers. The ReportsController did not have any known use, and the DynamicReviewMapping Controller had changes to be made to make it conform to standards.&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===ReportsController===&lt;br /&gt;
After searching through various controllers, looking for references used in the controller, we figured out that the code in the ReportsController was actually copied from the ResponseController, in December 2013. The ResponseController has been refactored since, and thus is an updated version. As of the usage, only the ResponseController has been referenced, and the ReportsController had never been used. We also extracted an older version of the ReportsController, that is, the one before it was replaced with code from the ResponseController. The code had a single method, and the method did not have any useful functionality. It was, thus, decided that the ReportsController should be removed from the Expertiza project, and that removing it would not have any effect on the overall project. Keeping it in would, on the other hand, create confusion for other people who would work on the project later.&lt;br /&gt;
&lt;br /&gt;
===DynamicReviewMapping Controller===&lt;br /&gt;
*The code block between line 808 to 825 was duplicated in 3 places in this file. We have refactored the code to remove this bad smell. We have created a method called create_message to avoid duplication in the code. &amp;lt;b&amp;gt;(Violated the DRY Principle. Eliminated duplication in code)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Method assign_metareviewers, assign_reviewers_team were too long. We have made two new methods (check_assignment_for_review and show_message_for_review_count) that does just one task and does it perfectly instead of large methods to do multiple tasks. &amp;lt;b&amp;gt;(Violated the Single Responsibility Principle and the DRY Principle. Eliminated lengthy methods and meaningless method names)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Method assign_reviewers_individual was not used anymore. We have checked for its functionality and deleted it since it did not play any role in the final application. &amp;lt;b&amp;gt;(Eliminated unnecessary methods)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*We have changed if to unless wherever necessary.&lt;br /&gt;
&lt;br /&gt;
*Changed &amp;quot; == 0&amp;quot; expression to &amp;quot;.zero?&amp;quot; &lt;br /&gt;
&lt;br /&gt;
*Used if (var) instead of if (var == true)&lt;br /&gt;
&lt;br /&gt;
*We have used array checking and made changes according to the following rules:&lt;br /&gt;
&lt;br /&gt;
**Use [].empty? instead of [].length == 0 or [].length.zero?&lt;br /&gt;
**Use [:foo].any? instead of [:foo].length &amp;gt; 0&lt;br /&gt;
**Use [:foo].one? instead of [:foo].length == 1&lt;br /&gt;
**Use [:foo].first instead of [:foo][0]&lt;br /&gt;
**Use [:foo].last instead of [:foo][-1]&lt;br /&gt;
&lt;br /&gt;
*We have used &amp;amp;&amp;amp; and || rather than and and or to keep boolean precedence.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
None of this would actually change the functionality of the code. To make sure, we tried to look for the usage of the code. Again, after extensive searching, we figured that the code was never used. The DynamicReviewMapping controller, as stated above, depended on a set of rules that were not applicable anymore. The controller exists so that it is available, in case the rules are reverted to the original one. As such, currently the Controller is not used. We made the changes, but we have no way to check the code. We did the best we could, and we are sure that there are no errors in the refactored code.&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
*[http://www.refactoringinruby.com/ Refactoring In Ruby]&lt;br /&gt;
*[http://refactoring.com/ Refactoring]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1457_ags&amp;diff=91478</id>
		<title>CSC/ECE 517 Fall 2014/oss E1457 ags</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1457_ags&amp;diff=91478"/>
		<updated>2014-11-06T03:12:56Z</updated>

		<summary type="html">&lt;p&gt;Gshah: /* DynamicReviewMapping Controller */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring DynamicReviewMapping Controller and the ReportsController=&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
It is time consuming to assess project work in a large classroom environment, and one of the best techniques to achieve this is to have students assist in this assessment.  If each student is asked to assess a few (say, one to five) other students or student teams, the task requires a reasonable amount of effort; and that effort does not increase as the class gets larger. &amp;quot;''Expertiza is a system for managing all kinds of communication that is involved in assessment: double-blind communications between authors and reviewers, assessment of teammate contributions, evaluations by course staff, and surveys of students to assess the assignment and the &lt;br /&gt;
peer-review process.''&amp;quot; &amp;lt;ref&amp;gt;http://www.igi-global.com/book/monitoring-assessment-online-collaborative-environments/773&amp;amp;f=e-book&amp;lt;/ref&amp;gt;&lt;br /&gt;
''&amp;quot;Expertiza project uses peer review to create reusable learning objects.''&amp;quot;&amp;lt;ref&amp;gt;http://expertiza.ncsu.edu/&amp;lt;/ref&amp;gt; Students select from a list of tasks to be performed, with several students selecting each task. Then they prepare their work and submit it to an electronic peer-review system. The work is then reviewed by other students, who offer comments to help the submitters improve their work. The best submissions for each task are then selected for use in later courses. Expertiza gets students working together to improve others’ learning experiences. It helps them learn, by making them think through the lecture material and apply it to a real-world situation, just as they might do in an on-the-job situation. These learning objects can be improved iteratively; for example, the next year’s class can be presented with the examples developed by students the previous year, and asked to identify shortcomings and develop improved examples.&amp;lt;ref&amp;gt;http://scholar.google.com/scholar?q=%22Reusable+learning+objects+through+peer+review%3A+The+Expertiza+approach%22+%22The+Expertiza+platform+is+a+divide-and-conquer%22&amp;amp;btnG=&amp;amp;hl=en&amp;amp;as_sdt=0%2C34&amp;lt;/ref&amp;gt; More information on Expertiza can be found [https://github.com/expertiza/expertiza here].&lt;br /&gt;
&lt;br /&gt;
==Refactoring in Ruby==&lt;br /&gt;
Refactoring helps to&amp;lt;ref&amp;gt;http://www.refactoringinruby.com/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*Understand what led to poor code design&lt;br /&gt;
*Fix code which is difficult to understand&lt;br /&gt;
*Express each idea “once and only once”&lt;br /&gt;
*Recognize missing or inadequately formed classes&lt;br /&gt;
*Simplify overly complex relationships between classes&lt;br /&gt;
*Achieve the right balance of responsibilities among objects&lt;br /&gt;
*Make code easier to test and more maintainable&lt;br /&gt;
&lt;br /&gt;
===Code Smells===&lt;br /&gt;
We identified the following categories of code smells in the helper module:&lt;br /&gt;
&lt;br /&gt;
*Lengthy Definitions: These are the methods that have too many responsibilities and collaborators. As a result of which, their overall length has grown too long reducing the maintainability and readability.&lt;br /&gt;
&lt;br /&gt;
*Duplicated Code: These are those pieces of code that does almost the same functionality of some other piece of code leading to a bad design style. They are usually too error prone since not everyone identifies all the code responsible for the same task and does the changes whenever the need arises.&lt;br /&gt;
&lt;br /&gt;
*Bad method names: A good method name is expected to adhere to the Ruby style and design style guidelines. It is expected to convey a reasonable amount of responsibilities handled. A good method name in combination with good practices should resemble a user story.&lt;br /&gt;
&lt;br /&gt;
*Used and unnecessary methods: These are those methods that were useful when the code was first developed. But, they lost their functionality as the code got updated and new functionalities were added or existing ones were modified.&lt;br /&gt;
&lt;br /&gt;
===Refactoring Techniques===&lt;br /&gt;
There are many documented refactoring techniques, and a few common ones are below.&amp;lt;ref&amp;gt;http://www.integralist.co.uk/posts/refactoring-techniques/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*'''Rename Method''': Renaming identifiers can reduce the need for code comments and nearly always helps to promote greater clarity.&lt;br /&gt;
*'''Introduce Explaining Variable''': So here is a technique specifically based around the premise of renaming.&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless &amp;quot;This is a String with some CAPS&amp;quot;.scan(/([A-Z])/).empty?&lt;br /&gt;
  puts &amp;quot;capitalised text was found&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Should be:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
caps_not_found = &amp;quot;This is a String with some CAPS&amp;quot;.scan(/([A-Z])/).empty?&lt;br /&gt;
&lt;br /&gt;
unless caps_not_found&lt;br /&gt;
  puts &amp;quot;capitalised text was found&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Extract Method''':  It consists of breaking up long methods by shifting overly complex chunks of code into new methods which have very descriptive identifiers.&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Foo&lt;br /&gt;
  attr_reader :bar&lt;br /&gt;
&lt;br /&gt;
  def initialize bar&lt;br /&gt;
    @bar = bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def do_something&lt;br /&gt;
    puts &amp;quot;my baz&amp;quot; # notice this is duplication&lt;br /&gt;
    puts bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def do_something_else&lt;br /&gt;
    puts &amp;quot;my baz&amp;quot; # notice this is duplication&lt;br /&gt;
    puts &amp;quot;Something else&amp;quot;&lt;br /&gt;
    puts bar&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Becomes:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Foo&lt;br /&gt;
  attr_reader :bar&lt;br /&gt;
&lt;br /&gt;
  def initialize bar&lt;br /&gt;
    @bar = bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def do_something&lt;br /&gt;
    baz&lt;br /&gt;
    puts bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def do_something_else&lt;br /&gt;
    baz&lt;br /&gt;
    puts &amp;quot;Something else&amp;quot;&lt;br /&gt;
    puts bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def baz&lt;br /&gt;
    puts &amp;quot;my baz&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Inline Method''': Sometimes you want the opposite of the Extract Method technique. Imagine a method exists whose content is already simple and clear, and whose identifier adds no extra benefit. So to fix this problem we'll convert the method invocation into an inlined piece of code.&lt;br /&gt;
&lt;br /&gt;
*'''Pull Up Method''': When you have duplicated code across two separate classes then the best refactoring technique to implement is to pull that duplicate code up into a super class so we DRY (Don't Repeat Yourself) out the code and allow it to be used in multiple places without duplication (meaning changes in future only have to happen in one place).&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
  attr_reader :first_name, :last_name&lt;br /&gt;
&lt;br /&gt;
  def initialize first_name, last_name&lt;br /&gt;
    @first_name = first_name&lt;br /&gt;
    @last_name = last_name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class MalePerson &amp;lt; Person&lt;br /&gt;
  # This is duplicated in the `FemalePerson` class&lt;br /&gt;
  def full_name&lt;br /&gt;
    first_name + &amp;quot; &amp;quot; + last_name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def gender&lt;br /&gt;
    &amp;quot;M&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class FemalePerson &amp;lt; Person&lt;br /&gt;
  # This is duplicated in the `MalePerson` class&lt;br /&gt;
  def full_name&lt;br /&gt;
    first_name + &amp;quot; &amp;quot; + last_name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def gender&lt;br /&gt;
    &amp;quot;F&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Becomes:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
  attr_reader :first_name, :last_name&lt;br /&gt;
&lt;br /&gt;
  def initialize first_name, last_name&lt;br /&gt;
    @first_name = first_name&lt;br /&gt;
    @last_name = last_name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def full_name&lt;br /&gt;
    first_name + &amp;quot; &amp;quot; + last_name&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class MalePerson &amp;lt; Person&lt;br /&gt;
  def gender&lt;br /&gt;
    &amp;quot;M&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class FemalePerson &amp;lt; Person&lt;br /&gt;
  def gender&lt;br /&gt;
    &amp;quot;F&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Introduce Named Parameter''':When method arguments are unclear then convert them into named parameters so they become clearer (and easier to remember).&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
We were supposed to refactor two controllers, the ReportsController and the DynamicReviewMapping Controller. The ReportsController was thought to be generating reports for students, showing all their scores in a single page. The DynamicReviewMapping Controller is actually a helper to the ReviewMapping controller. The review mapping controller maps reviews to each user. Currently, there are two ways to assign reviews to user: The user can either select a submission himself, which he wants to review, or the site can suggest a review to the user. Currently, the user can give more than two reviews. The ReviewMapping controller had a method so that all the users are assigned reviews automatically. Originally, the plan was to assign only a fixed number of reviews to each user. The dynamic review controller helped the review mapping controller assign reviews so that the reviews are never mapped such that the last user does not have any review to map, except his own. For example, consider three users, U1, U2 and U3. If U1 is assigned U2's work and U2 is assigned U1's work, U3 would not have any work to review. The dynamic review mapping controller makes sure that such a condition does not occur.&lt;br /&gt;
&lt;br /&gt;
We were supposed to refactor these controllers. The ReportsController did not have any known use, and the DynamicReviewMapping Controller had changes to be made to make it conform to standards.&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===ReportsController===&lt;br /&gt;
After searching through various controllers, looking for references used in the controller, we figured out that the code in the ReportsController was actually copied from the ResponseController, in December 2013. The ResponseController has been refactored since, and thus is an updated version. As of the usage, only the ResponseController has been referenced, and the ReportsController had never been used. We also extracted an older version of the ReportsController, that is, the one before it was replaced with code from the ResponseController. The code had a single method, and the method did not have any useful functionality. It was, thus, decided that the ReportsController should be removed from the Expertiza project, and that removing it would not have any effect on the overall project. Keeping it in would, on the other hand, create confusion for other people who would work on the project later.&lt;br /&gt;
&lt;br /&gt;
===DynamicReviewMapping Controller===&lt;br /&gt;
*The code block between line 808 to 825 was duplicated in 3 places in this file. We have refactored the code to remove this bad smell. We have created a method called create_message to avoid duplication in the code. &amp;lt;b&amp;gt;(Violated the DRY Principle. Eliminated duplication in code)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Method assign_metareviewers, assign_reviewers_team were too long. We have made two new methods (check_assignment_for_review and show_message_for_review_count) that does just one task and does it perfectly instead of large methods to do multiple tasks. &amp;lt;b&amp;gt;(Violated the Single Responsibility Principle and the DRY Principle. Eliminated lengthy methods and meaningless method names)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Method assign_reviewers_individual was not used anymore. We have checked for its functionality and deleted it since it did not play any role in the final application. &amp;lt;b&amp;gt;(Eliminated unnecessary methods)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*We have changed if to unless wherever necessary.&lt;br /&gt;
&lt;br /&gt;
*Changed &amp;quot; == 0&amp;quot; expression to &amp;quot;.zero?&amp;quot; &lt;br /&gt;
&lt;br /&gt;
*Used if (var) instead of if (var == true)&lt;br /&gt;
&lt;br /&gt;
*We have used array checking and made changes according to the following rules:&lt;br /&gt;
&lt;br /&gt;
**Use [].empty? instead of [].length == 0 or [].length.zero?&lt;br /&gt;
**Use [:foo].any? instead of [:foo].length &amp;gt; 0&lt;br /&gt;
**Use [:foo].one? instead of [:foo].length == 1&lt;br /&gt;
**Use [:foo].first instead of [:foo][0]&lt;br /&gt;
**Use [:foo].last instead of [:foo][-1]&lt;br /&gt;
&lt;br /&gt;
*We have used &amp;amp;&amp;amp; and || rather than and and or to keep boolean precedence.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
None of this would actually change the functionality of the code. To make sure, we tried to look for the usage of the code. Again, after extensive searching, we figured that the code was never used. The DynamicReviewMapping controller, as stated above, depended on a set of rules that were not applicable anymore. The controller exists so that it is available, in case the rules are reverted to the original one. As such, currently the Controller is not used. We made the changes, but we have no way to check the code. We did the best we could, and we are sure that there are no errors in the refactored code.&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
*[http://www.refactoringinruby.com/ Refactoring In Ruby]&lt;br /&gt;
*[http://refactoring.com/ Refactoring]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1457_ags&amp;diff=91477</id>
		<title>CSC/ECE 517 Fall 2014/oss E1457 ags</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1457_ags&amp;diff=91477"/>
		<updated>2014-11-06T03:11:38Z</updated>

		<summary type="html">&lt;p&gt;Gshah: /* DynamicReviewMapping Controller */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring DynamicReviewMapping Controller and the ReportsController=&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
It is time consuming to assess project work in a large classroom environment, and one of the best techniques to achieve this is to have students assist in this assessment.  If each student is asked to assess a few (say, one to five) other students or student teams, the task requires a reasonable amount of effort; and that effort does not increase as the class gets larger. &amp;quot;''Expertiza is a system for managing all kinds of communication that is involved in assessment: double-blind communications between authors and reviewers, assessment of teammate contributions, evaluations by course staff, and surveys of students to assess the assignment and the &lt;br /&gt;
peer-review process.''&amp;quot; &amp;lt;ref&amp;gt;http://www.igi-global.com/book/monitoring-assessment-online-collaborative-environments/773&amp;amp;f=e-book&amp;lt;/ref&amp;gt;&lt;br /&gt;
''&amp;quot;Expertiza project uses peer review to create reusable learning objects.''&amp;quot;&amp;lt;ref&amp;gt;http://expertiza.ncsu.edu/&amp;lt;/ref&amp;gt; Students select from a list of tasks to be performed, with several students selecting each task. Then they prepare their work and submit it to an electronic peer-review system. The work is then reviewed by other students, who offer comments to help the submitters improve their work. The best submissions for each task are then selected for use in later courses. Expertiza gets students working together to improve others’ learning experiences. It helps them learn, by making them think through the lecture material and apply it to a real-world situation, just as they might do in an on-the-job situation. These learning objects can be improved iteratively; for example, the next year’s class can be presented with the examples developed by students the previous year, and asked to identify shortcomings and develop improved examples.&amp;lt;ref&amp;gt;http://scholar.google.com/scholar?q=%22Reusable+learning+objects+through+peer+review%3A+The+Expertiza+approach%22+%22The+Expertiza+platform+is+a+divide-and-conquer%22&amp;amp;btnG=&amp;amp;hl=en&amp;amp;as_sdt=0%2C34&amp;lt;/ref&amp;gt; More information on Expertiza can be found [https://github.com/expertiza/expertiza here].&lt;br /&gt;
&lt;br /&gt;
==Refactoring in Ruby==&lt;br /&gt;
Refactoring helps to&amp;lt;ref&amp;gt;http://www.refactoringinruby.com/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*Understand what led to poor code design&lt;br /&gt;
*Fix code which is difficult to understand&lt;br /&gt;
*Express each idea “once and only once”&lt;br /&gt;
*Recognize missing or inadequately formed classes&lt;br /&gt;
*Simplify overly complex relationships between classes&lt;br /&gt;
*Achieve the right balance of responsibilities among objects&lt;br /&gt;
*Make code easier to test and more maintainable&lt;br /&gt;
&lt;br /&gt;
===Code Smells===&lt;br /&gt;
We identified the following categories of code smells in the helper module:&lt;br /&gt;
&lt;br /&gt;
*Lengthy Definitions: These are the methods that have too many responsibilities and collaborators. As a result of which, their overall length has grown too long reducing the maintainability and readability.&lt;br /&gt;
&lt;br /&gt;
*Duplicated Code: These are those pieces of code that does almost the same functionality of some other piece of code leading to a bad design style. They are usually too error prone since not everyone identifies all the code responsible for the same task and does the changes whenever the need arises.&lt;br /&gt;
&lt;br /&gt;
*Bad method names: A good method name is expected to adhere to the Ruby style and design style guidelines. It is expected to convey a reasonable amount of responsibilities handled. A good method name in combination with good practices should resemble a user story.&lt;br /&gt;
&lt;br /&gt;
*Used and unnecessary methods: These are those methods that were useful when the code was first developed. But, they lost their functionality as the code got updated and new functionalities were added or existing ones were modified.&lt;br /&gt;
&lt;br /&gt;
===Refactoring Techniques===&lt;br /&gt;
There are many documented refactoring techniques, and a few common ones are below.&amp;lt;ref&amp;gt;http://www.integralist.co.uk/posts/refactoring-techniques/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*'''Rename Method''': Renaming identifiers can reduce the need for code comments and nearly always helps to promote greater clarity.&lt;br /&gt;
*'''Introduce Explaining Variable''': So here is a technique specifically based around the premise of renaming.&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless &amp;quot;This is a String with some CAPS&amp;quot;.scan(/([A-Z])/).empty?&lt;br /&gt;
  puts &amp;quot;capitalised text was found&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Should be:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
caps_not_found = &amp;quot;This is a String with some CAPS&amp;quot;.scan(/([A-Z])/).empty?&lt;br /&gt;
&lt;br /&gt;
unless caps_not_found&lt;br /&gt;
  puts &amp;quot;capitalised text was found&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Extract Method''':  It consists of breaking up long methods by shifting overly complex chunks of code into new methods which have very descriptive identifiers.&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Foo&lt;br /&gt;
  attr_reader :bar&lt;br /&gt;
&lt;br /&gt;
  def initialize bar&lt;br /&gt;
    @bar = bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def do_something&lt;br /&gt;
    puts &amp;quot;my baz&amp;quot; # notice this is duplication&lt;br /&gt;
    puts bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def do_something_else&lt;br /&gt;
    puts &amp;quot;my baz&amp;quot; # notice this is duplication&lt;br /&gt;
    puts &amp;quot;Something else&amp;quot;&lt;br /&gt;
    puts bar&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Becomes:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Foo&lt;br /&gt;
  attr_reader :bar&lt;br /&gt;
&lt;br /&gt;
  def initialize bar&lt;br /&gt;
    @bar = bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def do_something&lt;br /&gt;
    baz&lt;br /&gt;
    puts bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def do_something_else&lt;br /&gt;
    baz&lt;br /&gt;
    puts &amp;quot;Something else&amp;quot;&lt;br /&gt;
    puts bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def baz&lt;br /&gt;
    puts &amp;quot;my baz&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Inline Method''': Sometimes you want the opposite of the Extract Method technique. Imagine a method exists whose content is already simple and clear, and whose identifier adds no extra benefit. So to fix this problem we'll convert the method invocation into an inlined piece of code.&lt;br /&gt;
&lt;br /&gt;
*'''Pull Up Method''': When you have duplicated code across two separate classes then the best refactoring technique to implement is to pull that duplicate code up into a super class so we DRY (Don't Repeat Yourself) out the code and allow it to be used in multiple places without duplication (meaning changes in future only have to happen in one place).&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
  attr_reader :first_name, :last_name&lt;br /&gt;
&lt;br /&gt;
  def initialize first_name, last_name&lt;br /&gt;
    @first_name = first_name&lt;br /&gt;
    @last_name = last_name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class MalePerson &amp;lt; Person&lt;br /&gt;
  # This is duplicated in the `FemalePerson` class&lt;br /&gt;
  def full_name&lt;br /&gt;
    first_name + &amp;quot; &amp;quot; + last_name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def gender&lt;br /&gt;
    &amp;quot;M&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class FemalePerson &amp;lt; Person&lt;br /&gt;
  # This is duplicated in the `MalePerson` class&lt;br /&gt;
  def full_name&lt;br /&gt;
    first_name + &amp;quot; &amp;quot; + last_name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def gender&lt;br /&gt;
    &amp;quot;F&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Becomes:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
  attr_reader :first_name, :last_name&lt;br /&gt;
&lt;br /&gt;
  def initialize first_name, last_name&lt;br /&gt;
    @first_name = first_name&lt;br /&gt;
    @last_name = last_name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def full_name&lt;br /&gt;
    first_name + &amp;quot; &amp;quot; + last_name&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class MalePerson &amp;lt; Person&lt;br /&gt;
  def gender&lt;br /&gt;
    &amp;quot;M&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class FemalePerson &amp;lt; Person&lt;br /&gt;
  def gender&lt;br /&gt;
    &amp;quot;F&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Introduce Named Parameter''':When method arguments are unclear then convert them into named parameters so they become clearer (and easier to remember).&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
We were supposed to refactor two controllers, the ReportsController and the DynamicReviewMapping Controller. The ReportsController was thought to be generating reports for students, showing all their scores in a single page. The DynamicReviewMapping Controller is actually a helper to the ReviewMapping controller. The review mapping controller maps reviews to each user. Currently, there are two ways to assign reviews to user: The user can either select a submission himself, which he wants to review, or the site can suggest a review to the user. Currently, the user can give more than two reviews. The ReviewMapping controller had a method so that all the users are assigned reviews automatically. Originally, the plan was to assign only a fixed number of reviews to each user. The dynamic review controller helped the review mapping controller assign reviews so that the reviews are never mapped such that the last user does not have any review to map, except his own. For example, consider three users, U1, U2 and U3. If U1 is assigned U2's work and U2 is assigned U1's work, U3 would not have any work to review. The dynamic review mapping controller makes sure that such a condition does not occur.&lt;br /&gt;
&lt;br /&gt;
We were supposed to refactor these controllers. The ReportsController did not have any known use, and the DynamicReviewMapping Controller had changes to be made to make it conform to standards.&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===ReportsController===&lt;br /&gt;
After searching through various controllers, looking for references used in the controller, we figured out that the code in the ReportsController was actually copied from the ResponseController, in December 2013. The ResponseController has been refactored since, and thus is an updated version. As of the usage, only the ResponseController has been referenced, and the ReportsController had never been used. We also extracted an older version of the ReportsController, that is, the one before it was replaced with code from the ResponseController. The code had a single method, and the method did not have any useful functionality. It was, thus, decided that the ReportsController should be removed from the Expertiza project, and that removing it would not have any effect on the overall project. Keeping it in would, on the other hand, create confusion for other people who would work on the project later.&lt;br /&gt;
&lt;br /&gt;
===DynamicReviewMapping Controller===&lt;br /&gt;
*The code block between line 808 to 825 was duplicated in 3 places in this file. We have refactored the code to remove this bad smell. We have created a method called create_message to avoid duplication in the code. (Violated the DRY Principle)&lt;br /&gt;
&lt;br /&gt;
*Method assign_metareviewers, assign_reviewers_team were too long. We have made two new methods (check_assignment_for_review and show_message_for_review_count) that does just one task and does it perfectly instead of large methods to do multiple tasks. (Violated the Single Responsibility Principle and the DRY Principle. Eliminated lengthy methods and meaningless method names)&lt;br /&gt;
&lt;br /&gt;
*Method assign_reviewers_individual was not used anymore. We have checked for its functionality and deleted it since it did not play any role in the final application. (Eliminated unnecessary methods)&lt;br /&gt;
&lt;br /&gt;
*We have changed if to unless wherever necessary.&lt;br /&gt;
&lt;br /&gt;
*Changed &amp;quot; == 0&amp;quot; expression to &amp;quot;.zero?&amp;quot; &lt;br /&gt;
&lt;br /&gt;
*Used if (var) instead of if (var == true)&lt;br /&gt;
&lt;br /&gt;
*We have used array checking and made changes according to the following rules:&lt;br /&gt;
&lt;br /&gt;
**Use [].empty? instead of [].length == 0 or [].length.zero?&lt;br /&gt;
**Use [:foo].any? instead of [:foo].length &amp;gt; 0&lt;br /&gt;
**Use [:foo].one? instead of [:foo].length == 1&lt;br /&gt;
**Use [:foo].first instead of [:foo][0]&lt;br /&gt;
**Use [:foo].last instead of [:foo][-1]&lt;br /&gt;
&lt;br /&gt;
*We have used &amp;amp;&amp;amp; and || rather than and and or to keep boolean precedence.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
None of this would actually change the functionality of the code. To make sure, we tried to look for the usage of the code. Again, after extensive searching, we figured that the code was never used. The DynamicReviewMapping controller, as stated above, depended on a set of rules that were not applicable anymore. The controller exists so that it is available, in case the rules are reverted to the original one. As such, currently the Controller is not used. We made the changes, but we have no way to check the code. We did the best we could, and we are sure that there are no errors in the refactored code.&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
*[http://www.refactoringinruby.com/ Refactoring In Ruby]&lt;br /&gt;
*[http://refactoring.com/ Refactoring]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1457_ags&amp;diff=91476</id>
		<title>CSC/ECE 517 Fall 2014/oss E1457 ags</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1457_ags&amp;diff=91476"/>
		<updated>2014-11-06T03:10:17Z</updated>

		<summary type="html">&lt;p&gt;Gshah: /* DynamicReviewMapping Controller */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring DynamicReviewMapping Controller and the ReportsController=&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
It is time consuming to assess project work in a large classroom environment, and one of the best techniques to achieve this is to have students assist in this assessment.  If each student is asked to assess a few (say, one to five) other students or student teams, the task requires a reasonable amount of effort; and that effort does not increase as the class gets larger. &amp;quot;''Expertiza is a system for managing all kinds of communication that is involved in assessment: double-blind communications between authors and reviewers, assessment of teammate contributions, evaluations by course staff, and surveys of students to assess the assignment and the &lt;br /&gt;
peer-review process.''&amp;quot; &amp;lt;ref&amp;gt;http://www.igi-global.com/book/monitoring-assessment-online-collaborative-environments/773&amp;amp;f=e-book&amp;lt;/ref&amp;gt;&lt;br /&gt;
''&amp;quot;Expertiza project uses peer review to create reusable learning objects.''&amp;quot;&amp;lt;ref&amp;gt;http://expertiza.ncsu.edu/&amp;lt;/ref&amp;gt; Students select from a list of tasks to be performed, with several students selecting each task. Then they prepare their work and submit it to an electronic peer-review system. The work is then reviewed by other students, who offer comments to help the submitters improve their work. The best submissions for each task are then selected for use in later courses. Expertiza gets students working together to improve others’ learning experiences. It helps them learn, by making them think through the lecture material and apply it to a real-world situation, just as they might do in an on-the-job situation. These learning objects can be improved iteratively; for example, the next year’s class can be presented with the examples developed by students the previous year, and asked to identify shortcomings and develop improved examples.&amp;lt;ref&amp;gt;http://scholar.google.com/scholar?q=%22Reusable+learning+objects+through+peer+review%3A+The+Expertiza+approach%22+%22The+Expertiza+platform+is+a+divide-and-conquer%22&amp;amp;btnG=&amp;amp;hl=en&amp;amp;as_sdt=0%2C34&amp;lt;/ref&amp;gt; More information on Expertiza can be found [https://github.com/expertiza/expertiza here].&lt;br /&gt;
&lt;br /&gt;
==Refactoring in Ruby==&lt;br /&gt;
Refactoring helps to&amp;lt;ref&amp;gt;http://www.refactoringinruby.com/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*Understand what led to poor code design&lt;br /&gt;
*Fix code which is difficult to understand&lt;br /&gt;
*Express each idea “once and only once”&lt;br /&gt;
*Recognize missing or inadequately formed classes&lt;br /&gt;
*Simplify overly complex relationships between classes&lt;br /&gt;
*Achieve the right balance of responsibilities among objects&lt;br /&gt;
*Make code easier to test and more maintainable&lt;br /&gt;
&lt;br /&gt;
===Code Smells===&lt;br /&gt;
We identified the following categories of code smells in the helper module:&lt;br /&gt;
&lt;br /&gt;
*Lengthy Definitions: These are the methods that have too many responsibilities and collaborators. As a result of which, their overall length has grown too long reducing the maintainability and readability.&lt;br /&gt;
&lt;br /&gt;
*Duplicated Code: These are those pieces of code that does almost the same functionality of some other piece of code leading to a bad design style. They are usually too error prone since not everyone identifies all the code responsible for the same task and does the changes whenever the need arises.&lt;br /&gt;
&lt;br /&gt;
*Bad method names: A good method name is expected to adhere to the Ruby style and design style guidelines. It is expected to convey a reasonable amount of responsibilities handled. A good method name in combination with good practices should resemble a user story.&lt;br /&gt;
&lt;br /&gt;
*Used and unnecessary methods: These are those methods that were useful when the code was first developed. But, they lost their functionality as the code got updated and new functionalities were added or existing ones were modified.&lt;br /&gt;
&lt;br /&gt;
===Refactoring Techniques===&lt;br /&gt;
There are many documented refactoring techniques, and a few common ones are below.&amp;lt;ref&amp;gt;http://www.integralist.co.uk/posts/refactoring-techniques/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*'''Rename Method''': Renaming identifiers can reduce the need for code comments and nearly always helps to promote greater clarity.&lt;br /&gt;
*'''Introduce Explaining Variable''': So here is a technique specifically based around the premise of renaming.&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless &amp;quot;This is a String with some CAPS&amp;quot;.scan(/([A-Z])/).empty?&lt;br /&gt;
  puts &amp;quot;capitalised text was found&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Should be:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
caps_not_found = &amp;quot;This is a String with some CAPS&amp;quot;.scan(/([A-Z])/).empty?&lt;br /&gt;
&lt;br /&gt;
unless caps_not_found&lt;br /&gt;
  puts &amp;quot;capitalised text was found&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Extract Method''':  It consists of breaking up long methods by shifting overly complex chunks of code into new methods which have very descriptive identifiers.&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Foo&lt;br /&gt;
  attr_reader :bar&lt;br /&gt;
&lt;br /&gt;
  def initialize bar&lt;br /&gt;
    @bar = bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def do_something&lt;br /&gt;
    puts &amp;quot;my baz&amp;quot; # notice this is duplication&lt;br /&gt;
    puts bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def do_something_else&lt;br /&gt;
    puts &amp;quot;my baz&amp;quot; # notice this is duplication&lt;br /&gt;
    puts &amp;quot;Something else&amp;quot;&lt;br /&gt;
    puts bar&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Becomes:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Foo&lt;br /&gt;
  attr_reader :bar&lt;br /&gt;
&lt;br /&gt;
  def initialize bar&lt;br /&gt;
    @bar = bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def do_something&lt;br /&gt;
    baz&lt;br /&gt;
    puts bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def do_something_else&lt;br /&gt;
    baz&lt;br /&gt;
    puts &amp;quot;Something else&amp;quot;&lt;br /&gt;
    puts bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def baz&lt;br /&gt;
    puts &amp;quot;my baz&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Inline Method''': Sometimes you want the opposite of the Extract Method technique. Imagine a method exists whose content is already simple and clear, and whose identifier adds no extra benefit. So to fix this problem we'll convert the method invocation into an inlined piece of code.&lt;br /&gt;
&lt;br /&gt;
*'''Pull Up Method''': When you have duplicated code across two separate classes then the best refactoring technique to implement is to pull that duplicate code up into a super class so we DRY (Don't Repeat Yourself) out the code and allow it to be used in multiple places without duplication (meaning changes in future only have to happen in one place).&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
  attr_reader :first_name, :last_name&lt;br /&gt;
&lt;br /&gt;
  def initialize first_name, last_name&lt;br /&gt;
    @first_name = first_name&lt;br /&gt;
    @last_name = last_name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class MalePerson &amp;lt; Person&lt;br /&gt;
  # This is duplicated in the `FemalePerson` class&lt;br /&gt;
  def full_name&lt;br /&gt;
    first_name + &amp;quot; &amp;quot; + last_name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def gender&lt;br /&gt;
    &amp;quot;M&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class FemalePerson &amp;lt; Person&lt;br /&gt;
  # This is duplicated in the `MalePerson` class&lt;br /&gt;
  def full_name&lt;br /&gt;
    first_name + &amp;quot; &amp;quot; + last_name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def gender&lt;br /&gt;
    &amp;quot;F&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Becomes:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
  attr_reader :first_name, :last_name&lt;br /&gt;
&lt;br /&gt;
  def initialize first_name, last_name&lt;br /&gt;
    @first_name = first_name&lt;br /&gt;
    @last_name = last_name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def full_name&lt;br /&gt;
    first_name + &amp;quot; &amp;quot; + last_name&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class MalePerson &amp;lt; Person&lt;br /&gt;
  def gender&lt;br /&gt;
    &amp;quot;M&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class FemalePerson &amp;lt; Person&lt;br /&gt;
  def gender&lt;br /&gt;
    &amp;quot;F&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Introduce Named Parameter''':When method arguments are unclear then convert them into named parameters so they become clearer (and easier to remember).&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
We were supposed to refactor two controllers, the ReportsController and the DynamicReviewMapping Controller. The ReportsController was thought to be generating reports for students, showing all their scores in a single page. The DynamicReviewMapping Controller is actually a helper to the ReviewMapping controller. The review mapping controller maps reviews to each user. Currently, there are two ways to assign reviews to user: The user can either select a submission himself, which he wants to review, or the site can suggest a review to the user. Currently, the user can give more than two reviews. The ReviewMapping controller had a method so that all the users are assigned reviews automatically. Originally, the plan was to assign only a fixed number of reviews to each user. The dynamic review controller helped the review mapping controller assign reviews so that the reviews are never mapped such that the last user does not have any review to map, except his own. For example, consider three users, U1, U2 and U3. If U1 is assigned U2's work and U2 is assigned U1's work, U3 would not have any work to review. The dynamic review mapping controller makes sure that such a condition does not occur.&lt;br /&gt;
&lt;br /&gt;
We were supposed to refactor these controllers. The ReportsController did not have any known use, and the DynamicReviewMapping Controller had changes to be made to make it conform to standards.&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===ReportsController===&lt;br /&gt;
After searching through various controllers, looking for references used in the controller, we figured out that the code in the ReportsController was actually copied from the ResponseController, in December 2013. The ResponseController has been refactored since, and thus is an updated version. As of the usage, only the ResponseController has been referenced, and the ReportsController had never been used. We also extracted an older version of the ReportsController, that is, the one before it was replaced with code from the ResponseController. The code had a single method, and the method did not have any useful functionality. It was, thus, decided that the ReportsController should be removed from the Expertiza project, and that removing it would not have any effect on the overall project. Keeping it in would, on the other hand, create confusion for other people who would work on the project later.&lt;br /&gt;
&lt;br /&gt;
===DynamicReviewMapping Controller===&lt;br /&gt;
*The code block between line 808 to 825 was duplicated in 3 places in this file. We have refactored the code to remove this bad smell. We have created a method called create_message to avoid duplication in the code. (Violated the DRY Principle)&lt;br /&gt;
&lt;br /&gt;
*Method assign_metareviewers, assign_reviewers_team were too long. We have made two new methods (check_assignment_for_review and show_message_for_review_count) that does just one task and does it perfectly instead of large methods to do multiple tasks. (Violated the Single Responsibility Principle and the DRY Principle)&lt;br /&gt;
&lt;br /&gt;
*Method assign_reviewers_individual was not used anymore. We have checked for its functionality and deleted it since it did not play any role in the final application.  (Eliminated &lt;br /&gt;
*We have changed if to unless wherever necessary.&lt;br /&gt;
*Changed &amp;quot; == 0&amp;quot; expression to &amp;quot;.zero?&amp;quot; &lt;br /&gt;
*Used if (var) instead of if (var == true)&lt;br /&gt;
*We have used array checking and made changes according to the following rules:&lt;br /&gt;
&lt;br /&gt;
**Use [].empty? instead of [].length == 0 or [].length.zero?&lt;br /&gt;
**Use [:foo].any? instead of [:foo].length &amp;gt; 0&lt;br /&gt;
**Use [:foo].one? instead of [:foo].length == 1&lt;br /&gt;
**Use [:foo].first instead of [:foo][0]&lt;br /&gt;
**Use [:foo].last instead of [:foo][-1]&lt;br /&gt;
*We have used &amp;amp;&amp;amp; and || rather than and and or to keep boolean precedence.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
None of this would actually change the functionality of the code. To make sure, we tried to look for the usage of the code. Again, after extensive searching, we figured that the code was never used. The DynamicReviewMapping controller, as stated above, depended on a set of rules that were not applicable anymore. The controller exists so that it is available, in case the rules are reverted to the original one. As such, currently the Controller is not used. We made the changes, but we have no way to check the code. We did the best we could, and we are sure that there are no errors in the refactored code.&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
*[http://www.refactoringinruby.com/ Refactoring In Ruby]&lt;br /&gt;
*[http://refactoring.com/ Refactoring]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1457_ags&amp;diff=91474</id>
		<title>CSC/ECE 517 Fall 2014/oss E1457 ags</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1457_ags&amp;diff=91474"/>
		<updated>2014-11-06T03:07:15Z</updated>

		<summary type="html">&lt;p&gt;Gshah: /* DynamicReviewMapping Controller */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring DynamicReviewMapping Controller and the ReportsController=&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
It is time consuming to assess project work in a large classroom environment, and one of the best techniques to achieve this is to have students assist in this assessment.  If each student is asked to assess a few (say, one to five) other students or student teams, the task requires a reasonable amount of effort; and that effort does not increase as the class gets larger. &amp;quot;''Expertiza is a system for managing all kinds of communication that is involved in assessment: double-blind communications between authors and reviewers, assessment of teammate contributions, evaluations by course staff, and surveys of students to assess the assignment and the &lt;br /&gt;
peer-review process.''&amp;quot; &amp;lt;ref&amp;gt;http://www.igi-global.com/book/monitoring-assessment-online-collaborative-environments/773&amp;amp;f=e-book&amp;lt;/ref&amp;gt;&lt;br /&gt;
''&amp;quot;Expertiza project uses peer review to create reusable learning objects.''&amp;quot;&amp;lt;ref&amp;gt;http://expertiza.ncsu.edu/&amp;lt;/ref&amp;gt; Students select from a list of tasks to be performed, with several students selecting each task. Then they prepare their work and submit it to an electronic peer-review system. The work is then reviewed by other students, who offer comments to help the submitters improve their work. The best submissions for each task are then selected for use in later courses. Expertiza gets students working together to improve others’ learning experiences. It helps them learn, by making them think through the lecture material and apply it to a real-world situation, just as they might do in an on-the-job situation. These learning objects can be improved iteratively; for example, the next year’s class can be presented with the examples developed by students the previous year, and asked to identify shortcomings and develop improved examples.&amp;lt;ref&amp;gt;http://scholar.google.com/scholar?q=%22Reusable+learning+objects+through+peer+review%3A+The+Expertiza+approach%22+%22The+Expertiza+platform+is+a+divide-and-conquer%22&amp;amp;btnG=&amp;amp;hl=en&amp;amp;as_sdt=0%2C34&amp;lt;/ref&amp;gt; More information on Expertiza can be found [https://github.com/expertiza/expertiza here].&lt;br /&gt;
&lt;br /&gt;
==Refactoring in Ruby==&lt;br /&gt;
Refactoring helps to&amp;lt;ref&amp;gt;http://www.refactoringinruby.com/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*Understand what led to poor code design&lt;br /&gt;
*Fix code which is difficult to understand&lt;br /&gt;
*Express each idea “once and only once”&lt;br /&gt;
*Recognize missing or inadequately formed classes&lt;br /&gt;
*Simplify overly complex relationships between classes&lt;br /&gt;
*Achieve the right balance of responsibilities among objects&lt;br /&gt;
*Make code easier to test and more maintainable&lt;br /&gt;
&lt;br /&gt;
===Code Smells===&lt;br /&gt;
We identified the following categories of code smells in the helper module:&lt;br /&gt;
&lt;br /&gt;
*Lengthy Definitions: These are the methods that have too many responsibilities and collaborators. As a result of which, their overall length has grown too long reducing the maintainability and readability.&lt;br /&gt;
&lt;br /&gt;
*Duplicated Code: These are those pieces of code that does almost the same functionality of some other piece of code leading to a bad design style. They are usually too error prone since not everyone identifies all the code responsible for the same task and does the changes whenever the need arises.&lt;br /&gt;
&lt;br /&gt;
*Bad method names: A good method name is expected to adhere to the Ruby style and design style guidelines. It is expected to convey a reasonable amount of responsibilities handled. A good method name in combination with good practices should resemble a user story.&lt;br /&gt;
&lt;br /&gt;
*Used and unnecessary methods: These are those methods that were useful when the code was first developed. But, they lost their functionality as the code got updated and new functionalities were added or existing ones were modified.&lt;br /&gt;
&lt;br /&gt;
===Refactoring Techniques===&lt;br /&gt;
There are many documented refactoring techniques, and a few common ones are below.&amp;lt;ref&amp;gt;http://www.integralist.co.uk/posts/refactoring-techniques/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*'''Rename Method''': Renaming identifiers can reduce the need for code comments and nearly always helps to promote greater clarity.&lt;br /&gt;
*'''Introduce Explaining Variable''': So here is a technique specifically based around the premise of renaming.&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless &amp;quot;This is a String with some CAPS&amp;quot;.scan(/([A-Z])/).empty?&lt;br /&gt;
  puts &amp;quot;capitalised text was found&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Should be:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
caps_not_found = &amp;quot;This is a String with some CAPS&amp;quot;.scan(/([A-Z])/).empty?&lt;br /&gt;
&lt;br /&gt;
unless caps_not_found&lt;br /&gt;
  puts &amp;quot;capitalised text was found&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Extract Method''':  It consists of breaking up long methods by shifting overly complex chunks of code into new methods which have very descriptive identifiers.&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Foo&lt;br /&gt;
  attr_reader :bar&lt;br /&gt;
&lt;br /&gt;
  def initialize bar&lt;br /&gt;
    @bar = bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def do_something&lt;br /&gt;
    puts &amp;quot;my baz&amp;quot; # notice this is duplication&lt;br /&gt;
    puts bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def do_something_else&lt;br /&gt;
    puts &amp;quot;my baz&amp;quot; # notice this is duplication&lt;br /&gt;
    puts &amp;quot;Something else&amp;quot;&lt;br /&gt;
    puts bar&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Becomes:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Foo&lt;br /&gt;
  attr_reader :bar&lt;br /&gt;
&lt;br /&gt;
  def initialize bar&lt;br /&gt;
    @bar = bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def do_something&lt;br /&gt;
    baz&lt;br /&gt;
    puts bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def do_something_else&lt;br /&gt;
    baz&lt;br /&gt;
    puts &amp;quot;Something else&amp;quot;&lt;br /&gt;
    puts bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def baz&lt;br /&gt;
    puts &amp;quot;my baz&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Inline Method''': Sometimes you want the opposite of the Extract Method technique. Imagine a method exists whose content is already simple and clear, and whose identifier adds no extra benefit. So to fix this problem we'll convert the method invocation into an inlined piece of code.&lt;br /&gt;
&lt;br /&gt;
*'''Pull Up Method''': When you have duplicated code across two separate classes then the best refactoring technique to implement is to pull that duplicate code up into a super class so we DRY (Don't Repeat Yourself) out the code and allow it to be used in multiple places without duplication (meaning changes in future only have to happen in one place).&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
  attr_reader :first_name, :last_name&lt;br /&gt;
&lt;br /&gt;
  def initialize first_name, last_name&lt;br /&gt;
    @first_name = first_name&lt;br /&gt;
    @last_name = last_name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class MalePerson &amp;lt; Person&lt;br /&gt;
  # This is duplicated in the `FemalePerson` class&lt;br /&gt;
  def full_name&lt;br /&gt;
    first_name + &amp;quot; &amp;quot; + last_name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def gender&lt;br /&gt;
    &amp;quot;M&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class FemalePerson &amp;lt; Person&lt;br /&gt;
  # This is duplicated in the `MalePerson` class&lt;br /&gt;
  def full_name&lt;br /&gt;
    first_name + &amp;quot; &amp;quot; + last_name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def gender&lt;br /&gt;
    &amp;quot;F&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Becomes:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
  attr_reader :first_name, :last_name&lt;br /&gt;
&lt;br /&gt;
  def initialize first_name, last_name&lt;br /&gt;
    @first_name = first_name&lt;br /&gt;
    @last_name = last_name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def full_name&lt;br /&gt;
    first_name + &amp;quot; &amp;quot; + last_name&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class MalePerson &amp;lt; Person&lt;br /&gt;
  def gender&lt;br /&gt;
    &amp;quot;M&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class FemalePerson &amp;lt; Person&lt;br /&gt;
  def gender&lt;br /&gt;
    &amp;quot;F&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Introduce Named Parameter''':When method arguments are unclear then convert them into named parameters so they become clearer (and easier to remember).&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
We were supposed to refactor two controllers, the ReportsController and the DynamicReviewMapping Controller. The ReportsController was thought to be generating reports for students, showing all their scores in a single page. The DynamicReviewMapping Controller is actually a helper to the ReviewMapping controller. The review mapping controller maps reviews to each user. Currently, there are two ways to assign reviews to user: The user can either select a submission himself, which he wants to review, or the site can suggest a review to the user. Currently, the user can give more than two reviews. The ReviewMapping controller had a method so that all the users are assigned reviews automatically. Originally, the plan was to assign only a fixed number of reviews to each user. The dynamic review controller helped the review mapping controller assign reviews so that the reviews are never mapped such that the last user does not have any review to map, except his own. For example, consider three users, U1, U2 and U3. If U1 is assigned U2's work and U2 is assigned U1's work, U3 would not have any work to review. The dynamic review mapping controller makes sure that such a condition does not occur.&lt;br /&gt;
&lt;br /&gt;
We were supposed to refactor these controllers. The ReportsController did not have any known use, and the DynamicReviewMapping Controller had changes to be made to make it conform to standards.&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===ReportsController===&lt;br /&gt;
After searching through various controllers, looking for references used in the controller, we figured out that the code in the ReportsController was actually copied from the ResponseController, in December 2013. The ResponseController has been refactored since, and thus is an updated version. As of the usage, only the ResponseController has been referenced, and the ReportsController had never been used. We also extracted an older version of the ReportsController, that is, the one before it was replaced with code from the ResponseController. The code had a single method, and the method did not have any useful functionality. It was, thus, decided that the ReportsController should be removed from the Expertiza project, and that removing it would not have any effect on the overall project. Keeping it in would, on the other hand, create confusion for other people who would work on the project later.&lt;br /&gt;
&lt;br /&gt;
===DynamicReviewMapping Controller===&lt;br /&gt;
*The code block between line 808 to 825 was duplicated in 3 places in this file. We have refactored the code to remove this bad smell. We have created a method called create_message to avoid duplication in the code.&lt;br /&gt;
*Method assign_metareviewers, assign_reviewers_team were too long. We have made two new methods (check_assignment_for_review and show_message_for_review_count) that does just one task and does it perfectly instead of large methods to do multiple tasks.&lt;br /&gt;
*Method assign_reviewers_individual was not used anymore. We have checked for its functionality and deleted it since it did not play any role in the final application.&lt;br /&gt;
*We have changed if to unless wherever necessary.&lt;br /&gt;
*Changed &amp;quot; == 0&amp;quot; expression to &amp;quot;.zero?&amp;quot;&lt;br /&gt;
*Used if (var) instead of if (var == true)&lt;br /&gt;
*We have used array checking and made changes according to the following rules:&lt;br /&gt;
&lt;br /&gt;
**Use [].empty? instead of [].length == 0 or [].length.zero?&lt;br /&gt;
**Use [:foo].any? instead of [:foo].length &amp;gt; 0&lt;br /&gt;
**Use [:foo].one? instead of [:foo].length == 1&lt;br /&gt;
**Use [:foo].first instead of [:foo][0]&lt;br /&gt;
**Use [:foo].last instead of [:foo][-1]&lt;br /&gt;
*We have used &amp;amp;&amp;amp; and || rather than and and or to keep boolean precedence.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
None of this would actually change the functionality of the code. To make sure, we tried to look for the usage of the code. Again, after extensive searching, we figured that the code was never used. The DynamicReviewMapping controller, as stated above, depended on a set of rules that were not applicable anymore. The controller exists so that it is available, in case the rules are reverted to the original one. As such, currently the Controller is not used. We made the changes, but we have no way to check the code. We did the best we could, and we are sure that there are no errors in the refactored code.&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
*[http://www.refactoringinruby.com/ Refactoring In Ruby]&lt;br /&gt;
*[http://refactoring.com/ Refactoring]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1457_ags&amp;diff=91473</id>
		<title>CSC/ECE 517 Fall 2014/oss E1457 ags</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1457_ags&amp;diff=91473"/>
		<updated>2014-11-06T03:06:43Z</updated>

		<summary type="html">&lt;p&gt;Gshah: /* DynamicReviewMapping Controller */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring DynamicReviewMapping Controller and the ReportsController=&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
It is time consuming to assess project work in a large classroom environment, and one of the best techniques to achieve this is to have students assist in this assessment.  If each student is asked to assess a few (say, one to five) other students or student teams, the task requires a reasonable amount of effort; and that effort does not increase as the class gets larger. &amp;quot;''Expertiza is a system for managing all kinds of communication that is involved in assessment: double-blind communications between authors and reviewers, assessment of teammate contributions, evaluations by course staff, and surveys of students to assess the assignment and the &lt;br /&gt;
peer-review process.''&amp;quot; &amp;lt;ref&amp;gt;http://www.igi-global.com/book/monitoring-assessment-online-collaborative-environments/773&amp;amp;f=e-book&amp;lt;/ref&amp;gt;&lt;br /&gt;
''&amp;quot;Expertiza project uses peer review to create reusable learning objects.''&amp;quot;&amp;lt;ref&amp;gt;http://expertiza.ncsu.edu/&amp;lt;/ref&amp;gt; Students select from a list of tasks to be performed, with several students selecting each task. Then they prepare their work and submit it to an electronic peer-review system. The work is then reviewed by other students, who offer comments to help the submitters improve their work. The best submissions for each task are then selected for use in later courses. Expertiza gets students working together to improve others’ learning experiences. It helps them learn, by making them think through the lecture material and apply it to a real-world situation, just as they might do in an on-the-job situation. These learning objects can be improved iteratively; for example, the next year’s class can be presented with the examples developed by students the previous year, and asked to identify shortcomings and develop improved examples.&amp;lt;ref&amp;gt;http://scholar.google.com/scholar?q=%22Reusable+learning+objects+through+peer+review%3A+The+Expertiza+approach%22+%22The+Expertiza+platform+is+a+divide-and-conquer%22&amp;amp;btnG=&amp;amp;hl=en&amp;amp;as_sdt=0%2C34&amp;lt;/ref&amp;gt; More information on Expertiza can be found [https://github.com/expertiza/expertiza here].&lt;br /&gt;
&lt;br /&gt;
==Refactoring in Ruby==&lt;br /&gt;
Refactoring helps to&amp;lt;ref&amp;gt;http://www.refactoringinruby.com/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*Understand what led to poor code design&lt;br /&gt;
*Fix code which is difficult to understand&lt;br /&gt;
*Express each idea “once and only once”&lt;br /&gt;
*Recognize missing or inadequately formed classes&lt;br /&gt;
*Simplify overly complex relationships between classes&lt;br /&gt;
*Achieve the right balance of responsibilities among objects&lt;br /&gt;
*Make code easier to test and more maintainable&lt;br /&gt;
&lt;br /&gt;
===Code Smells===&lt;br /&gt;
We identified the following categories of code smells in the helper module:&lt;br /&gt;
&lt;br /&gt;
*Lengthy Definitions: These are the methods that have too many responsibilities and collaborators. As a result of which, their overall length has grown too long reducing the maintainability and readability.&lt;br /&gt;
&lt;br /&gt;
*Duplicated Code: These are those pieces of code that does almost the same functionality of some other piece of code leading to a bad design style. They are usually too error prone since not everyone identifies all the code responsible for the same task and does the changes whenever the need arises.&lt;br /&gt;
&lt;br /&gt;
*Bad method names: A good method name is expected to adhere to the Ruby style and design style guidelines. It is expected to convey a reasonable amount of responsibilities handled. A good method name in combination with good practices should resemble a user story.&lt;br /&gt;
&lt;br /&gt;
*Used and unnecessary methods: These are those methods that were useful when the code was first developed. But, they lost their functionality as the code got updated and new functionalities were added or existing ones were modified.&lt;br /&gt;
&lt;br /&gt;
===Refactoring Techniques===&lt;br /&gt;
There are many documented refactoring techniques, and a few common ones are below.&amp;lt;ref&amp;gt;http://www.integralist.co.uk/posts/refactoring-techniques/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*'''Rename Method''': Renaming identifiers can reduce the need for code comments and nearly always helps to promote greater clarity.&lt;br /&gt;
*'''Introduce Explaining Variable''': So here is a technique specifically based around the premise of renaming.&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless &amp;quot;This is a String with some CAPS&amp;quot;.scan(/([A-Z])/).empty?&lt;br /&gt;
  puts &amp;quot;capitalised text was found&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Should be:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
caps_not_found = &amp;quot;This is a String with some CAPS&amp;quot;.scan(/([A-Z])/).empty?&lt;br /&gt;
&lt;br /&gt;
unless caps_not_found&lt;br /&gt;
  puts &amp;quot;capitalised text was found&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Extract Method''':  It consists of breaking up long methods by shifting overly complex chunks of code into new methods which have very descriptive identifiers.&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Foo&lt;br /&gt;
  attr_reader :bar&lt;br /&gt;
&lt;br /&gt;
  def initialize bar&lt;br /&gt;
    @bar = bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def do_something&lt;br /&gt;
    puts &amp;quot;my baz&amp;quot; # notice this is duplication&lt;br /&gt;
    puts bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def do_something_else&lt;br /&gt;
    puts &amp;quot;my baz&amp;quot; # notice this is duplication&lt;br /&gt;
    puts &amp;quot;Something else&amp;quot;&lt;br /&gt;
    puts bar&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Becomes:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Foo&lt;br /&gt;
  attr_reader :bar&lt;br /&gt;
&lt;br /&gt;
  def initialize bar&lt;br /&gt;
    @bar = bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def do_something&lt;br /&gt;
    baz&lt;br /&gt;
    puts bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def do_something_else&lt;br /&gt;
    baz&lt;br /&gt;
    puts &amp;quot;Something else&amp;quot;&lt;br /&gt;
    puts bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def baz&lt;br /&gt;
    puts &amp;quot;my baz&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Inline Method''': Sometimes you want the opposite of the Extract Method technique. Imagine a method exists whose content is already simple and clear, and whose identifier adds no extra benefit. So to fix this problem we'll convert the method invocation into an inlined piece of code.&lt;br /&gt;
&lt;br /&gt;
*'''Pull Up Method''': When you have duplicated code across two separate classes then the best refactoring technique to implement is to pull that duplicate code up into a super class so we DRY (Don't Repeat Yourself) out the code and allow it to be used in multiple places without duplication (meaning changes in future only have to happen in one place).&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
  attr_reader :first_name, :last_name&lt;br /&gt;
&lt;br /&gt;
  def initialize first_name, last_name&lt;br /&gt;
    @first_name = first_name&lt;br /&gt;
    @last_name = last_name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class MalePerson &amp;lt; Person&lt;br /&gt;
  # This is duplicated in the `FemalePerson` class&lt;br /&gt;
  def full_name&lt;br /&gt;
    first_name + &amp;quot; &amp;quot; + last_name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def gender&lt;br /&gt;
    &amp;quot;M&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class FemalePerson &amp;lt; Person&lt;br /&gt;
  # This is duplicated in the `MalePerson` class&lt;br /&gt;
  def full_name&lt;br /&gt;
    first_name + &amp;quot; &amp;quot; + last_name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def gender&lt;br /&gt;
    &amp;quot;F&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Becomes:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
  attr_reader :first_name, :last_name&lt;br /&gt;
&lt;br /&gt;
  def initialize first_name, last_name&lt;br /&gt;
    @first_name = first_name&lt;br /&gt;
    @last_name = last_name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def full_name&lt;br /&gt;
    first_name + &amp;quot; &amp;quot; + last_name&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class MalePerson &amp;lt; Person&lt;br /&gt;
  def gender&lt;br /&gt;
    &amp;quot;M&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class FemalePerson &amp;lt; Person&lt;br /&gt;
  def gender&lt;br /&gt;
    &amp;quot;F&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Introduce Named Parameter''':When method arguments are unclear then convert them into named parameters so they become clearer (and easier to remember).&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
We were supposed to refactor two controllers, the ReportsController and the DynamicReviewMapping Controller. The ReportsController was thought to be generating reports for students, showing all their scores in a single page. The DynamicReviewMapping Controller is actually a helper to the ReviewMapping controller. The review mapping controller maps reviews to each user. Currently, there are two ways to assign reviews to user: The user can either select a submission himself, which he wants to review, or the site can suggest a review to the user. Currently, the user can give more than two reviews. The ReviewMapping controller had a method so that all the users are assigned reviews automatically. Originally, the plan was to assign only a fixed number of reviews to each user. The dynamic review controller helped the review mapping controller assign reviews so that the reviews are never mapped such that the last user does not have any review to map, except his own. For example, consider three users, U1, U2 and U3. If U1 is assigned U2's work and U2 is assigned U1's work, U3 would not have any work to review. The dynamic review mapping controller makes sure that such a condition does not occur.&lt;br /&gt;
&lt;br /&gt;
We were supposed to refactor these controllers. The ReportsController did not have any known use, and the DynamicReviewMapping Controller had changes to be made to make it conform to standards.&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===ReportsController===&lt;br /&gt;
After searching through various controllers, looking for references used in the controller, we figured out that the code in the ReportsController was actually copied from the ResponseController, in December 2013. The ResponseController has been refactored since, and thus is an updated version. As of the usage, only the ResponseController has been referenced, and the ReportsController had never been used. We also extracted an older version of the ReportsController, that is, the one before it was replaced with code from the ResponseController. The code had a single method, and the method did not have any useful functionality. It was, thus, decided that the ReportsController should be removed from the Expertiza project, and that removing it would not have any effect on the overall project. Keeping it in would, on the other hand, create confusion for other people who would work on the project later.&lt;br /&gt;
&lt;br /&gt;
===DynamicReviewMapping Controller===&lt;br /&gt;
*The code block between line 808 to 825 was duplicated in 3 places in this file. We have refactored the code to remove this bad smell. We have created a method called create_message to avoid duplication in the code.&lt;br /&gt;
*Method assign_metareviewers, assign_reviewers_team were too long. We have made two new methods (check_assignment_for_review and show_message_for_review_count) that does just one task and does it perfectly instead of large methods to do multiple tasks.&lt;br /&gt;
*Method assign_reviewers_individual was not used anymore. We have checked for its functionality and deleted it since it did not play any role in the final application.&lt;br /&gt;
*We have changed if to unless wherever necessary.&lt;br /&gt;
*Changed &amp;quot; == 0&amp;quot; expression to &amp;quot;.zero?&amp;quot;&lt;br /&gt;
*Used if (var) instead of if (var == true)&lt;br /&gt;
*We have used array checking and made changes according to the following rules:&lt;br /&gt;
&lt;br /&gt;
*Use [].empty? instead of [].length == 0 or [].length.zero?&lt;br /&gt;
**Use [:foo].any? instead of [:foo].length &amp;gt; 0&lt;br /&gt;
**Use [:foo].one? instead of [:foo].length == 1&lt;br /&gt;
**Use [:foo].first instead of [:foo][0]&lt;br /&gt;
**Use [:foo].last instead of [:foo][-1]&lt;br /&gt;
*We have used &amp;amp;&amp;amp; and || rather than and and or to keep boolean precedence.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
None of this would actually change the functionality of the code. To make sure, we tried to look for the usage of the code. Again, after extensive searching, we figured that the code was never used. The DynamicReviewMapping controller, as stated above, depended on a set of rules that were not applicable anymore. The controller exists so that it is available, in case the rules are reverted to the original one. As such, currently the Controller is not used. We made the changes, but we have no way to check the code. We did the best we could, and we are sure that there are no errors in the refactored code.&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
*[http://www.refactoringinruby.com/ Refactoring In Ruby]&lt;br /&gt;
*[http://refactoring.com/ Refactoring]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1457_ags&amp;diff=91471</id>
		<title>CSC/ECE 517 Fall 2014/oss E1457 ags</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1457_ags&amp;diff=91471"/>
		<updated>2014-11-06T03:06:20Z</updated>

		<summary type="html">&lt;p&gt;Gshah: /* DynamicReviewMapping Controller */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring DynamicReviewMapping Controller and the ReportsController=&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
It is time consuming to assess project work in a large classroom environment, and one of the best techniques to achieve this is to have students assist in this assessment.  If each student is asked to assess a few (say, one to five) other students or student teams, the task requires a reasonable amount of effort; and that effort does not increase as the class gets larger. &amp;quot;''Expertiza is a system for managing all kinds of communication that is involved in assessment: double-blind communications between authors and reviewers, assessment of teammate contributions, evaluations by course staff, and surveys of students to assess the assignment and the &lt;br /&gt;
peer-review process.''&amp;quot; &amp;lt;ref&amp;gt;http://www.igi-global.com/book/monitoring-assessment-online-collaborative-environments/773&amp;amp;f=e-book&amp;lt;/ref&amp;gt;&lt;br /&gt;
''&amp;quot;Expertiza project uses peer review to create reusable learning objects.''&amp;quot;&amp;lt;ref&amp;gt;http://expertiza.ncsu.edu/&amp;lt;/ref&amp;gt; Students select from a list of tasks to be performed, with several students selecting each task. Then they prepare their work and submit it to an electronic peer-review system. The work is then reviewed by other students, who offer comments to help the submitters improve their work. The best submissions for each task are then selected for use in later courses. Expertiza gets students working together to improve others’ learning experiences. It helps them learn, by making them think through the lecture material and apply it to a real-world situation, just as they might do in an on-the-job situation. These learning objects can be improved iteratively; for example, the next year’s class can be presented with the examples developed by students the previous year, and asked to identify shortcomings and develop improved examples.&amp;lt;ref&amp;gt;http://scholar.google.com/scholar?q=%22Reusable+learning+objects+through+peer+review%3A+The+Expertiza+approach%22+%22The+Expertiza+platform+is+a+divide-and-conquer%22&amp;amp;btnG=&amp;amp;hl=en&amp;amp;as_sdt=0%2C34&amp;lt;/ref&amp;gt; More information on Expertiza can be found [https://github.com/expertiza/expertiza here].&lt;br /&gt;
&lt;br /&gt;
==Refactoring in Ruby==&lt;br /&gt;
Refactoring helps to&amp;lt;ref&amp;gt;http://www.refactoringinruby.com/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*Understand what led to poor code design&lt;br /&gt;
*Fix code which is difficult to understand&lt;br /&gt;
*Express each idea “once and only once”&lt;br /&gt;
*Recognize missing or inadequately formed classes&lt;br /&gt;
*Simplify overly complex relationships between classes&lt;br /&gt;
*Achieve the right balance of responsibilities among objects&lt;br /&gt;
*Make code easier to test and more maintainable&lt;br /&gt;
&lt;br /&gt;
===Code Smells===&lt;br /&gt;
We identified the following categories of code smells in the helper module:&lt;br /&gt;
&lt;br /&gt;
*Lengthy Definitions: These are the methods that have too many responsibilities and collaborators. As a result of which, their overall length has grown too long reducing the maintainability and readability.&lt;br /&gt;
&lt;br /&gt;
*Duplicated Code: These are those pieces of code that does almost the same functionality of some other piece of code leading to a bad design style. They are usually too error prone since not everyone identifies all the code responsible for the same task and does the changes whenever the need arises.&lt;br /&gt;
&lt;br /&gt;
*Bad method names: A good method name is expected to adhere to the Ruby style and design style guidelines. It is expected to convey a reasonable amount of responsibilities handled. A good method name in combination with good practices should resemble a user story.&lt;br /&gt;
&lt;br /&gt;
*Used and unnecessary methods: These are those methods that were useful when the code was first developed. But, they lost their functionality as the code got updated and new functionalities were added or existing ones were modified.&lt;br /&gt;
&lt;br /&gt;
===Refactoring Techniques===&lt;br /&gt;
There are many documented refactoring techniques, and a few common ones are below.&amp;lt;ref&amp;gt;http://www.integralist.co.uk/posts/refactoring-techniques/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*'''Rename Method''': Renaming identifiers can reduce the need for code comments and nearly always helps to promote greater clarity.&lt;br /&gt;
*'''Introduce Explaining Variable''': So here is a technique specifically based around the premise of renaming.&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless &amp;quot;This is a String with some CAPS&amp;quot;.scan(/([A-Z])/).empty?&lt;br /&gt;
  puts &amp;quot;capitalised text was found&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Should be:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
caps_not_found = &amp;quot;This is a String with some CAPS&amp;quot;.scan(/([A-Z])/).empty?&lt;br /&gt;
&lt;br /&gt;
unless caps_not_found&lt;br /&gt;
  puts &amp;quot;capitalised text was found&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Extract Method''':  It consists of breaking up long methods by shifting overly complex chunks of code into new methods which have very descriptive identifiers.&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Foo&lt;br /&gt;
  attr_reader :bar&lt;br /&gt;
&lt;br /&gt;
  def initialize bar&lt;br /&gt;
    @bar = bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def do_something&lt;br /&gt;
    puts &amp;quot;my baz&amp;quot; # notice this is duplication&lt;br /&gt;
    puts bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def do_something_else&lt;br /&gt;
    puts &amp;quot;my baz&amp;quot; # notice this is duplication&lt;br /&gt;
    puts &amp;quot;Something else&amp;quot;&lt;br /&gt;
    puts bar&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Becomes:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Foo&lt;br /&gt;
  attr_reader :bar&lt;br /&gt;
&lt;br /&gt;
  def initialize bar&lt;br /&gt;
    @bar = bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def do_something&lt;br /&gt;
    baz&lt;br /&gt;
    puts bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def do_something_else&lt;br /&gt;
    baz&lt;br /&gt;
    puts &amp;quot;Something else&amp;quot;&lt;br /&gt;
    puts bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def baz&lt;br /&gt;
    puts &amp;quot;my baz&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Inline Method''': Sometimes you want the opposite of the Extract Method technique. Imagine a method exists whose content is already simple and clear, and whose identifier adds no extra benefit. So to fix this problem we'll convert the method invocation into an inlined piece of code.&lt;br /&gt;
&lt;br /&gt;
*'''Pull Up Method''': When you have duplicated code across two separate classes then the best refactoring technique to implement is to pull that duplicate code up into a super class so we DRY (Don't Repeat Yourself) out the code and allow it to be used in multiple places without duplication (meaning changes in future only have to happen in one place).&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
  attr_reader :first_name, :last_name&lt;br /&gt;
&lt;br /&gt;
  def initialize first_name, last_name&lt;br /&gt;
    @first_name = first_name&lt;br /&gt;
    @last_name = last_name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class MalePerson &amp;lt; Person&lt;br /&gt;
  # This is duplicated in the `FemalePerson` class&lt;br /&gt;
  def full_name&lt;br /&gt;
    first_name + &amp;quot; &amp;quot; + last_name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def gender&lt;br /&gt;
    &amp;quot;M&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class FemalePerson &amp;lt; Person&lt;br /&gt;
  # This is duplicated in the `MalePerson` class&lt;br /&gt;
  def full_name&lt;br /&gt;
    first_name + &amp;quot; &amp;quot; + last_name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def gender&lt;br /&gt;
    &amp;quot;F&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Becomes:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
  attr_reader :first_name, :last_name&lt;br /&gt;
&lt;br /&gt;
  def initialize first_name, last_name&lt;br /&gt;
    @first_name = first_name&lt;br /&gt;
    @last_name = last_name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def full_name&lt;br /&gt;
    first_name + &amp;quot; &amp;quot; + last_name&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class MalePerson &amp;lt; Person&lt;br /&gt;
  def gender&lt;br /&gt;
    &amp;quot;M&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class FemalePerson &amp;lt; Person&lt;br /&gt;
  def gender&lt;br /&gt;
    &amp;quot;F&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Introduce Named Parameter''':When method arguments are unclear then convert them into named parameters so they become clearer (and easier to remember).&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
We were supposed to refactor two controllers, the ReportsController and the DynamicReviewMapping Controller. The ReportsController was thought to be generating reports for students, showing all their scores in a single page. The DynamicReviewMapping Controller is actually a helper to the ReviewMapping controller. The review mapping controller maps reviews to each user. Currently, there are two ways to assign reviews to user: The user can either select a submission himself, which he wants to review, or the site can suggest a review to the user. Currently, the user can give more than two reviews. The ReviewMapping controller had a method so that all the users are assigned reviews automatically. Originally, the plan was to assign only a fixed number of reviews to each user. The dynamic review controller helped the review mapping controller assign reviews so that the reviews are never mapped such that the last user does not have any review to map, except his own. For example, consider three users, U1, U2 and U3. If U1 is assigned U2's work and U2 is assigned U1's work, U3 would not have any work to review. The dynamic review mapping controller makes sure that such a condition does not occur.&lt;br /&gt;
&lt;br /&gt;
We were supposed to refactor these controllers. The ReportsController did not have any known use, and the DynamicReviewMapping Controller had changes to be made to make it conform to standards.&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===ReportsController===&lt;br /&gt;
After searching through various controllers, looking for references used in the controller, we figured out that the code in the ReportsController was actually copied from the ResponseController, in December 2013. The ResponseController has been refactored since, and thus is an updated version. As of the usage, only the ResponseController has been referenced, and the ReportsController had never been used. We also extracted an older version of the ReportsController, that is, the one before it was replaced with code from the ResponseController. The code had a single method, and the method did not have any useful functionality. It was, thus, decided that the ReportsController should be removed from the Expertiza project, and that removing it would not have any effect on the overall project. Keeping it in would, on the other hand, create confusion for other people who would work on the project later.&lt;br /&gt;
&lt;br /&gt;
===DynamicReviewMapping Controller===&lt;br /&gt;
*The code block between line 808 to 825 was duplicated in 3 places in this file. We have refactored the code to remove this bad smell. We have created a method called create_message to avoid duplication in the code.&lt;br /&gt;
*Method assign_metareviewers, assign_reviewers_team were too long. We have made two new methods (check_assignment_for_review and show_message_for_review_count) that does just one task and does it perfectly instead of large methods to do multiple tasks.&lt;br /&gt;
*Method assign_reviewers_individual was not used anymore. We have checked for its functionality and deleted it since it did not play any role in the final application.&lt;br /&gt;
*We have changed if to unless wherever necessary.&lt;br /&gt;
*Changed &amp;quot; == 0&amp;quot; expression to &amp;quot;.zero?&amp;quot;&lt;br /&gt;
*Used if (var) instead of if (var == true)&lt;br /&gt;
*We have used array checking and made changes according to the following rules:&lt;br /&gt;
&lt;br /&gt;
**Use [].empty? instead of [].length == 0 or [].length.zero?&lt;br /&gt;
**Use [:foo].any? instead of [:foo].length &amp;gt; 0&lt;br /&gt;
**Use [:foo].one? instead of [:foo].length == 1&lt;br /&gt;
**Use [:foo].first instead of [:foo][0]&lt;br /&gt;
**Use [:foo].last instead of [:foo][-1]&lt;br /&gt;
*We have used &amp;amp;&amp;amp; and || rather than and and or to keep boolean precedence.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
None of this would actually change the functionality of the code. To make sure, we tried to look for the usage of the code. Again, after extensive searching, we figured that the code was never used. The DynamicReviewMapping controller, as stated above, depended on a set of rules that were not applicable anymore. The controller exists so that it is available, in case the rules are reverted to the original one. As such, currently the Controller is not used. We made the changes, but we have no way to check the code. We did the best we could, and we are sure that there are no errors in the refactored code.&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
*[http://www.refactoringinruby.com/ Refactoring In Ruby]&lt;br /&gt;
*[http://refactoring.com/ Refactoring]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1457_ags&amp;diff=91468</id>
		<title>CSC/ECE 517 Fall 2014/oss E1457 ags</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1457_ags&amp;diff=91468"/>
		<updated>2014-11-06T03:01:22Z</updated>

		<summary type="html">&lt;p&gt;Gshah: /* Refactoring in Ruby */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring DynamicReviewMapping Controller and the ReportsController=&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
It is time consuming to assess project work in a large classroom environment, and one of the best techniques to achieve this is to have students assist in this assessment.  If each student is asked to assess a few (say, one to five) other students or student teams, the task requires a reasonable amount of effort; and that effort does not increase as the class gets larger. &amp;quot;''Expertiza is a system for managing all kinds of communication that is involved in assessment: double-blind communications between authors and reviewers, assessment of teammate contributions, evaluations by course staff, and surveys of students to assess the assignment and the &lt;br /&gt;
peer-review process.''&amp;quot; &amp;lt;ref&amp;gt;http://www.igi-global.com/book/monitoring-assessment-online-collaborative-environments/773&amp;amp;f=e-book&amp;lt;/ref&amp;gt;&lt;br /&gt;
''&amp;quot;Expertiza project uses peer review to create reusable learning objects.''&amp;quot;&amp;lt;ref&amp;gt;http://expertiza.ncsu.edu/&amp;lt;/ref&amp;gt; Students select from a list of tasks to be performed, with several students selecting each task. Then they prepare their work and submit it to an electronic peer-review system. The work is then reviewed by other students, who offer comments to help the submitters improve their work. The best submissions for each task are then selected for use in later courses. Expertiza gets students working together to improve others’ learning experiences. It helps them learn, by making them think through the lecture material and apply it to a real-world situation, just as they might do in an on-the-job situation. These learning objects can be improved iteratively; for example, the next year’s class can be presented with the examples developed by students the previous year, and asked to identify shortcomings and develop improved examples.&amp;lt;ref&amp;gt;http://scholar.google.com/scholar?q=%22Reusable+learning+objects+through+peer+review%3A+The+Expertiza+approach%22+%22The+Expertiza+platform+is+a+divide-and-conquer%22&amp;amp;btnG=&amp;amp;hl=en&amp;amp;as_sdt=0%2C34&amp;lt;/ref&amp;gt; More information on Expertiza can be found [https://github.com/expertiza/expertiza here].&lt;br /&gt;
&lt;br /&gt;
==Refactoring in Ruby==&lt;br /&gt;
Refactoring helps to&amp;lt;ref&amp;gt;http://www.refactoringinruby.com/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*Understand what led to poor code design&lt;br /&gt;
*Fix code which is difficult to understand&lt;br /&gt;
*Express each idea “once and only once”&lt;br /&gt;
*Recognize missing or inadequately formed classes&lt;br /&gt;
*Simplify overly complex relationships between classes&lt;br /&gt;
*Achieve the right balance of responsibilities among objects&lt;br /&gt;
*Make code easier to test and more maintainable&lt;br /&gt;
&lt;br /&gt;
===Code Smells===&lt;br /&gt;
We identified the following categories of code smells in the helper module:&lt;br /&gt;
&lt;br /&gt;
*Lengthy Definitions: These are the methods that have too many responsibilities and collaborators. As a result of which, their overall length has grown too long reducing the maintainability and readability.&lt;br /&gt;
&lt;br /&gt;
*Duplicated Code: These are those pieces of code that does almost the same functionality of some other piece of code leading to a bad design style. They are usually too error prone since not everyone identifies all the code responsible for the same task and does the changes whenever the need arises.&lt;br /&gt;
&lt;br /&gt;
*Bad method names: A good method name is expected to adhere to the Ruby style and design style guidelines. It is expected to convey a reasonable amount of responsibilities handled. A good method name in combination with good practices should resemble a user story.&lt;br /&gt;
&lt;br /&gt;
*Used and unnecessary methods: These are those methods that were useful when the code was first developed. But, they lost their functionality as the code got updated and new functionalities were added or existing ones were modified.&lt;br /&gt;
&lt;br /&gt;
===Refactoring Techniques===&lt;br /&gt;
There are many documented refactoring techniques, and a few common ones are below.&amp;lt;ref&amp;gt;http://www.integralist.co.uk/posts/refactoring-techniques/&amp;lt;/ref&amp;gt;&lt;br /&gt;
*'''Rename Method''': Renaming identifiers can reduce the need for code comments and nearly always helps to promote greater clarity.&lt;br /&gt;
*'''Introduce Explaining Variable''': So here is a technique specifically based around the premise of renaming.&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless &amp;quot;This is a String with some CAPS&amp;quot;.scan(/([A-Z])/).empty?&lt;br /&gt;
  puts &amp;quot;capitalised text was found&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Should be:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
caps_not_found = &amp;quot;This is a String with some CAPS&amp;quot;.scan(/([A-Z])/).empty?&lt;br /&gt;
&lt;br /&gt;
unless caps_not_found&lt;br /&gt;
  puts &amp;quot;capitalised text was found&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Extract Method''':  It consists of breaking up long methods by shifting overly complex chunks of code into new methods which have very descriptive identifiers.&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Foo&lt;br /&gt;
  attr_reader :bar&lt;br /&gt;
&lt;br /&gt;
  def initialize bar&lt;br /&gt;
    @bar = bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def do_something&lt;br /&gt;
    puts &amp;quot;my baz&amp;quot; # notice this is duplication&lt;br /&gt;
    puts bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def do_something_else&lt;br /&gt;
    puts &amp;quot;my baz&amp;quot; # notice this is duplication&lt;br /&gt;
    puts &amp;quot;Something else&amp;quot;&lt;br /&gt;
    puts bar&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Becomes:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Foo&lt;br /&gt;
  attr_reader :bar&lt;br /&gt;
&lt;br /&gt;
  def initialize bar&lt;br /&gt;
    @bar = bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def do_something&lt;br /&gt;
    baz&lt;br /&gt;
    puts bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def do_something_else&lt;br /&gt;
    baz&lt;br /&gt;
    puts &amp;quot;Something else&amp;quot;&lt;br /&gt;
    puts bar&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def baz&lt;br /&gt;
    puts &amp;quot;my baz&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Inline Method''': Sometimes you want the opposite of the Extract Method technique. Imagine a method exists whose content is already simple and clear, and whose identifier adds no extra benefit. So to fix this problem we'll convert the method invocation into an inlined piece of code.&lt;br /&gt;
&lt;br /&gt;
*'''Pull Up Method''': When you have duplicated code across two separate classes then the best refactoring technique to implement is to pull that duplicate code up into a super class so we DRY (Don't Repeat Yourself) out the code and allow it to be used in multiple places without duplication (meaning changes in future only have to happen in one place).&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
  attr_reader :first_name, :last_name&lt;br /&gt;
&lt;br /&gt;
  def initialize first_name, last_name&lt;br /&gt;
    @first_name = first_name&lt;br /&gt;
    @last_name = last_name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class MalePerson &amp;lt; Person&lt;br /&gt;
  # This is duplicated in the `FemalePerson` class&lt;br /&gt;
  def full_name&lt;br /&gt;
    first_name + &amp;quot; &amp;quot; + last_name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def gender&lt;br /&gt;
    &amp;quot;M&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class FemalePerson &amp;lt; Person&lt;br /&gt;
  # This is duplicated in the `MalePerson` class&lt;br /&gt;
  def full_name&lt;br /&gt;
    first_name + &amp;quot; &amp;quot; + last_name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def gender&lt;br /&gt;
    &amp;quot;F&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Becomes:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
  attr_reader :first_name, :last_name&lt;br /&gt;
&lt;br /&gt;
  def initialize first_name, last_name&lt;br /&gt;
    @first_name = first_name&lt;br /&gt;
    @last_name = last_name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def full_name&lt;br /&gt;
    first_name + &amp;quot; &amp;quot; + last_name&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class MalePerson &amp;lt; Person&lt;br /&gt;
  def gender&lt;br /&gt;
    &amp;quot;M&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class FemalePerson &amp;lt; Person&lt;br /&gt;
  def gender&lt;br /&gt;
    &amp;quot;F&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Introduce Named Parameter''':When method arguments are unclear then convert them into named parameters so they become clearer (and easier to remember).&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
We were supposed to refactor two controllers, the ReportsController and the DynamicReviewMapping Controller. The ReportsController was thought to be generating reports for students, showing all their scores in a single page. The DynamicReviewMapping Controller is actually a helper to the ReviewMapping controller. The review mapping controller maps reviews to each user. Currently, there are two ways to assign reviews to user: The user can either select a submission himself, which he wants to review, or the site can suggest a review to the user. Currently, the user can give more than two reviews. The ReviewMapping controller had a method so that all the users are assigned reviews automatically. Originally, the plan was to assign only a fixed number of reviews to each user. The dynamic review controller helped the review mapping controller assign reviews so that the reviews are never mapped such that the last user does not have any review to map, except his own. For example, consider three users, U1, U2 and U3. If U1 is assigned U2's work and U2 is assigned U1's work, U3 would not have any work to review. The dynamic review mapping controller makes sure that such a condition does not occur.&lt;br /&gt;
&lt;br /&gt;
We were supposed to refactor these controllers. The ReportsController did not have any known use, and the DynamicReviewMapping Controller had changes to be made to make it conform to standards.&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===ReportsController===&lt;br /&gt;
After searching through various controllers, looking for references used in the controller, we figured out that the code in the ReportsController was actually copied from the ResponseController, in December 2013. The ResponseController has been refactored since, and thus is an updated version. As of the usage, only the ResponseController has been referenced, and the ReportsController had never been used. We also extracted an older version of the ReportsController, that is, the one before it was replaced with code from the ResponseController. The code had a single method, and the method did not have any useful functionality. It was, thus, decided that the ReportsController should be removed from the Expertiza project, and that removing it would not have any effect on the overall project. Keeping it in would, on the other hand, create confusion for other people who would work on the project later.&lt;br /&gt;
&lt;br /&gt;
===DynamicReviewMapping Controller===&lt;br /&gt;
The changes to be made to the DynamicReviewController were small ones: &lt;br /&gt;
*changing if to unless where applicable&lt;br /&gt;
*change the “== true&amp;quot; and &amp;quot;== false&amp;quot; wherever applicable&lt;br /&gt;
*A code block was repeated 3 times through the file. We were supposed to refactor that to a function to make the code DRYer.&lt;br /&gt;
*Methods assign_metareviewers and assign_reviewers_team were too long. We were supposed to break them up for better readability.&lt;br /&gt;
*Method assign_reviewers_individual did not seem to be used. We were supposed to make sure, then delete the method if that was the case.&lt;br /&gt;
&lt;br /&gt;
None of this would actually change the functionality of the code. To make sure, we tried to look for the usage of the code. Again, after extensive searching, we figured that the code was never used. The DynamicReviewMapping controller, as stated above, depended on a set of rules that were not applicable anymore. The controller exists so that it is available, in case the rules are reverted to the original one. As such, currently the Controller is not used. We made the changes, but we have no way to check the code. We did the best we could, and we are sure that there are no errors in the refactored code.&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
*[http://www.refactoringinruby.com/ Refactoring In Ruby]&lt;br /&gt;
*[http://refactoring.com/ Refactoring]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014&amp;diff=89705</id>
		<title>CSC/ECE 517 Fall 2014</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014&amp;diff=89705"/>
		<updated>2014-10-26T23:45:23Z</updated>

		<summary type="html">&lt;p&gt;Gshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*[[CSC/ECE_517_Fall_2014/sample_page]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a 22 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 19 mx]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 3 zq]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 4 lf]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 4 wl]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a a7 ch]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 25 rs]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 25 jf]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 8 os]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 8 sn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 15 gs]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 10 hu]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 20 kv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 21 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 24 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 26 sn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 6 rl]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 2 ss]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 16 av]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 1 rm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 1 sj]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 23 ss]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 20 rn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 22 sp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 26 gn]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 13 va]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 9 aa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 9 kn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 11 ap]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 25 ks]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 7 kz]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a_6_bn]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a 10 zz]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a 16 va]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a F1415 rv]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a_3_cp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1b 26 sa]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b_28_cg]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b 29 ry]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b 30 cs]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b_33_jy]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b_27_js]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss E1465 oak]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss_M1456_kdv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss_E1456_akk]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_M1455_asa]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_E1458_sst]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_E1457_ags]]&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88748</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88748"/>
		<updated>2014-09-26T04:27:44Z</updated>

		<summary type="html">&lt;p&gt;Gshah: /* Comparison with other popular debugging tools */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Debugging in Rails using Pry'''&amp;lt;/big&amp;gt;     &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Web_application Web application]&amp;lt;/span&amp;gt; framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Model–view–controller model view controller]&amp;lt;/span&amp;gt;, like Mailers, Routes (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer REST]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol HTTP]&amp;lt;/span&amp;gt;-Verbs, Constraints), Environments and Initializers, Caching (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer Redis]&amp;lt;/span&amp;gt; &lt;br /&gt;
,&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Memcached Memcached]&amp;lt;/span&amp;gt;), Assets (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Sass_(stylesheet_language) SASS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript Javascript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/CoffeeScript CoffeeScript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Pipeline_(computing) Pipelining]&amp;lt;/span&amp;gt;), Bundler and dependency management, Tests (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/RSpec RSpec]&amp;lt;/span&amp;gt; , &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[https://github.com/jnicklas/capybara Capybara]&amp;lt;/span&amp;gt;&amp;lt;ref&amp;gt;https://github.com/jnicklas/capybara&amp;lt;/ref&amp;gt;), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debugging Debugging]&amp;lt;/span&amp;gt;  is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell IRB]&amp;lt;/span&amp;gt; shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Syntax_highlighting Syntax highlighting]&amp;lt;/span&amp;gt;, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration - and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place. &lt;br /&gt;
&lt;br /&gt;
Pry is written in &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby]&amp;lt;/span&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Pry_(software)&amp;lt;/ref&amp;gt;. The Pry core team consists of John Mair, Conrad Irwin and Ryan Fitzgerald and many more contributors. The last stable release was version 0.9.10 and it was released on July 15, 2012. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Read–eval–print_loop REPL]&amp;lt;/span&amp;gt; driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Rubinius Rubinius]&amp;lt;/span&amp;gt; core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/GitHub#Gist Gist]&amp;lt;/span&amp;gt; integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/IPython IPython]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Smalltalk Smalltalk]&amp;lt;/span&amp;gt; and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Usage and Example =&lt;br /&gt;
&lt;br /&gt;
=== Usage ===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
For example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Pry Commands =&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
::''Description'':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
::''Description'':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
::''Description'': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
::''Description'':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
::''Description'': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::''Description'': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
::''Description'': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
::''Description'': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
::''Description'': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
::''Description'': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
= Remote debugging =&lt;br /&gt;
&lt;br /&gt;
Remote debugging means you work on your local computer and you want to start and debug a program on another computer, the remote machine. Pry is a great tool for digging into your code and seeing what's going on with tons of great features. However, there are situations where using a standard binding.pry breakpoint will not block your program and allow you to inspect it.A remote session allows you to start instances of Pry in a running program and connect to those instances over a socket. This is particularly useful for using Pry in places not normally possible, such as apps running on the Pow web server. It also opens the door for such exotica as multi-user sessions.&lt;br /&gt;
&lt;br /&gt;
Pry has two plugins that implement remote sessions: 'pry-remote' and the newer and more ambitious 'pry-remote-em'&amp;lt;ref&amp;gt;https://github.com/Mon-Ouie/pry-remote&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''pry-remote: '''A way to start Pry remotely and to connect to it using DRb. This allows to access the state of the running program from anywhere. Simply replace the normal 'binding.pry' call with 'binding.remote_pry' as the example below illustrates.&lt;br /&gt;
&lt;br /&gt;
We set up the server as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'pry-remote'&lt;br /&gt;
&lt;br /&gt;
class Foo&lt;br /&gt;
  def initialize(x, y)&lt;br /&gt;
    binding.remote_pry&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Foo.new 10, 20&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can then connect to it using the 'pry-remote' executable.&lt;br /&gt;
&lt;br /&gt;
'''pry-remote-em: ''' pry-remote-em is a EventMachine-based alternative to pry-remote. It adds user authentication and SSL support along with tab completion and paging. It also allows multiple clients to connect to the same server, and multiple servers to run on the same computer and even within the same process.&lt;br /&gt;
&lt;br /&gt;
require 'pry-remote-em/server'&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Foo&lt;br /&gt;
  def initialize(x, y)&lt;br /&gt;
    binding.remote_pry_em&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
EM.run { Foo.new 10, 20 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Comparison with other popular debugging tools =&lt;br /&gt;
&lt;br /&gt;
Pry is a cross-over REPL because it supports some of what Ruby Debugger does with addons and sometimes even built and also supports all of what IRB does with some enhancements such as tab completion, code spacing and syntax highlighting as well as supporting an easy way to tap into an object with an REPL easily. There are also other things like the ability to show the source of a class, a method and source around where you are (if you are in a method)&amp;lt;ref&amp;gt;http://www.infoq.com/articles/ruby-debuggers-survey&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Other debuggers available for Ruby are:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Komodo_Edit Komodo]&amp;lt;/span&amp;gt;: The Komodo debugger is a tool for analyzing programs on a line-by-line basis, monitoring and altering variables, and watching output as it is generated. &lt;br /&gt;
&lt;br /&gt;
2. Eclipse's &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[https://www.eclipse.org/proposals/dash/html/maintopic.html EclipseMonkey]&amp;lt;/span&amp;gt; extension allows scripts written in JRuby. As these scripts run inside the same JVM as the Eclipse IDE, it's possible to access the Debugger instances and control it.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://www.sapphiresteel.com SapphireSteel's]&amp;lt;/span&amp;gt; Ruby in Steel IDE is also built using native code to implement the functionality, complete with using Ruby hooks to get notified about events such as method invocations etc.&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/RadRails Aptana RadRails]&amp;lt;/span&amp;gt;: Aptana RadRails sets breakpoints, inspect variables, control execution. The integrated Ruby &amp;amp; Rails debugger helps you squash the bugs.&lt;br /&gt;
&lt;br /&gt;
5. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/RubyMine RubyMine]&amp;lt;/span&amp;gt;: RubyMine has an excellent step-through debugger which lets you set breakpoints in your code and trace through the program. It provides a useful feature for exploring all of the metaprogramming going on behind the scenes in Ruby on Rails.&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88746</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88746"/>
		<updated>2014-09-26T04:23:45Z</updated>

		<summary type="html">&lt;p&gt;Gshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Debugging in Rails using Pry'''&amp;lt;/big&amp;gt;     &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Web_application Web application]&amp;lt;/span&amp;gt; framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Model–view–controller model view controller]&amp;lt;/span&amp;gt;, like Mailers, Routes (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer REST]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol HTTP]&amp;lt;/span&amp;gt;-Verbs, Constraints), Environments and Initializers, Caching (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer Redis]&amp;lt;/span&amp;gt; &lt;br /&gt;
,&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Memcached Memcached]&amp;lt;/span&amp;gt;), Assets (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Sass_(stylesheet_language) SASS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript Javascript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/CoffeeScript CoffeeScript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Pipeline_(computing) Pipelining]&amp;lt;/span&amp;gt;), Bundler and dependency management, Tests (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/RSpec RSpec]&amp;lt;/span&amp;gt; , &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[https://github.com/jnicklas/capybara Capybara]&amp;lt;/span&amp;gt;&amp;lt;ref&amp;gt;https://github.com/jnicklas/capybara&amp;lt;/ref&amp;gt;), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debugging Debugging]&amp;lt;/span&amp;gt;  is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell IRB]&amp;lt;/span&amp;gt; shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Syntax_highlighting Syntax highlighting]&amp;lt;/span&amp;gt;, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration - and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place. &lt;br /&gt;
&lt;br /&gt;
Pry is written in &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby]&amp;lt;/span&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Pry_(software)&amp;lt;/ref&amp;gt;. The Pry core team consists of John Mair, Conrad Irwin and Ryan Fitzgerald and many more contributors. The last stable release was version 0.9.10 and it was released on July 15, 2012. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Read–eval–print_loop REPL]&amp;lt;/span&amp;gt; driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Rubinius Rubinius]&amp;lt;/span&amp;gt; core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/GitHub#Gist Gist]&amp;lt;/span&amp;gt; integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/IPython IPython]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Smalltalk Smalltalk]&amp;lt;/span&amp;gt; and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Usage and Example =&lt;br /&gt;
&lt;br /&gt;
=== Usage ===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
For example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Pry Commands =&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
::''Description'':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
::''Description'':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
::''Description'': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
::''Description'':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
::''Description'': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::''Description'': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
::''Description'': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
::''Description'': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
::''Description'': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
::''Description'': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
= Remote debugging =&lt;br /&gt;
&lt;br /&gt;
Remote debugging means you work on your local computer and you want to start and debug a program on another computer, the remote machine. Pry is a great tool for digging into your code and seeing what's going on with tons of great features. However, there are situations where using a standard binding.pry breakpoint will not block your program and allow you to inspect it.A remote session allows you to start instances of Pry in a running program and connect to those instances over a socket. This is particularly useful for using Pry in places not normally possible, such as apps running on the Pow web server. It also opens the door for such exotica as multi-user sessions.&lt;br /&gt;
&lt;br /&gt;
Pry has two plugins that implement remote sessions: 'pry-remote' and the newer and more ambitious 'pry-remote-em'&amp;lt;ref&amp;gt;https://github.com/Mon-Ouie/pry-remote&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''pry-remote: '''A way to start Pry remotely and to connect to it using DRb. This allows to access the state of the running program from anywhere. Simply replace the normal 'binding.pry' call with 'binding.remote_pry' as the example below illustrates.&lt;br /&gt;
&lt;br /&gt;
We set up the server as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'pry-remote'&lt;br /&gt;
&lt;br /&gt;
class Foo&lt;br /&gt;
  def initialize(x, y)&lt;br /&gt;
    binding.remote_pry&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Foo.new 10, 20&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can then connect to it using the 'pry-remote' executable.&lt;br /&gt;
&lt;br /&gt;
'''pry-remote-em: ''' pry-remote-em is a EventMachine-based alternative to pry-remote. It adds user authentication and SSL support along with tab completion and paging. It also allows multiple clients to connect to the same server, and multiple servers to run on the same computer and even within the same process.&lt;br /&gt;
&lt;br /&gt;
require 'pry-remote-em/server'&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Foo&lt;br /&gt;
  def initialize(x, y)&lt;br /&gt;
    binding.remote_pry_em&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
EM.run { Foo.new 10, 20 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Comparison with other popular debugging tools =&lt;br /&gt;
&lt;br /&gt;
Pry is a cross-over REPL because it supports some of what Ruby Debugger does with addons and sometimes even built and also supports all of what IRB does with some enhancements such as tab completion, code spacing and syntax highlighting as well as supporting an easy way to tap into an object with an REPL easily. There are also other things like the ability to show the source of a class, a method and source around where you are (if you are in a method)&amp;lt;ref&amp;gt;http://www.infoq.com/articles/ruby-debuggers-survey&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Other debuggers available for Ruby are:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Komodo_Edit Komodo]&amp;lt;/span&amp;gt;: The Komodo debugger is a tool for analyzing programs on a line-by-line basis, monitoring and altering variables, and watching output as it is generated. &lt;br /&gt;
&lt;br /&gt;
2. IDEs with embedded scripting support also allow to script the debugger. An option, for instance, is Eclipse's &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[https://www.eclipse.org/proposals/dash/html/maintopic.html EclipseMonkey]&amp;lt;/span&amp;gt; extension which allows scripts written in JRuby. As these scripts run inside the same JVM as the Eclipse IDE, it's possible to access the Debugger instances and control it.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://www.sapphiresteel.com SapphireSteel's]&amp;lt;/span&amp;gt; Ruby in Steel IDE is also built using native code to implement the functionality, complete with using Ruby hooks to get notified about events such as method invocations etc.&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/RadRails Aptana RadRails]&amp;lt;/span&amp;gt;: Aptana RadRails sets breakpoints, inspect variables, control execution. The integrated Ruby &amp;amp; Rails debugger helps you squash the bugs.&lt;br /&gt;
&lt;br /&gt;
5. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/RubyMine RubyMine]&amp;lt;/span&amp;gt;: RubyMine has an excellent step-through debugger which lets you set breakpoints in your code and trace through the program. It provides a useful feature for exploring all of the metaprogramming going on behind the scenes in Ruby on Rails.&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88745</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88745"/>
		<updated>2014-09-26T04:23:31Z</updated>

		<summary type="html">&lt;p&gt;Gshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Debugging in Rails using Pry'''&amp;lt;/big&amp;gt;     &lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Web_application Web application]&amp;lt;/span&amp;gt; framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Model–view–controller model view controller]&amp;lt;/span&amp;gt;, like Mailers, Routes (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer REST]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol HTTP]&amp;lt;/span&amp;gt;-Verbs, Constraints), Environments and Initializers, Caching (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer Redis]&amp;lt;/span&amp;gt; &lt;br /&gt;
,&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Memcached Memcached]&amp;lt;/span&amp;gt;), Assets (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Sass_(stylesheet_language) SASS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript Javascript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/CoffeeScript CoffeeScript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Pipeline_(computing) Pipelining]&amp;lt;/span&amp;gt;), Bundler and dependency management, Tests (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/RSpec RSpec]&amp;lt;/span&amp;gt; , &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[https://github.com/jnicklas/capybara Capybara]&amp;lt;/span&amp;gt;&amp;lt;ref&amp;gt;https://github.com/jnicklas/capybara&amp;lt;/ref&amp;gt;), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debugging Debugging]&amp;lt;/span&amp;gt;  is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell IRB]&amp;lt;/span&amp;gt; shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Syntax_highlighting Syntax highlighting]&amp;lt;/span&amp;gt;, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration - and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place. &lt;br /&gt;
&lt;br /&gt;
Pry is written in &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby]&amp;lt;/span&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Pry_(software)&amp;lt;/ref&amp;gt;. The Pry core team consists of John Mair, Conrad Irwin and Ryan Fitzgerald and many more contributors. The last stable release was version 0.9.10 and it was released on July 15, 2012. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Read–eval–print_loop REPL]&amp;lt;/span&amp;gt; driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Rubinius Rubinius]&amp;lt;/span&amp;gt; core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/GitHub#Gist Gist]&amp;lt;/span&amp;gt; integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/IPython IPython]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Smalltalk Smalltalk]&amp;lt;/span&amp;gt; and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Usage and Example =&lt;br /&gt;
&lt;br /&gt;
=== Usage ===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
For example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Pry Commands =&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
::''Description'':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
::''Description'':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
::''Description'': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
::''Description'':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
::''Description'': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::''Description'': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
::''Description'': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
::''Description'': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
::''Description'': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
::''Description'': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
= Remote debugging =&lt;br /&gt;
&lt;br /&gt;
Remote debugging means you work on your local computer and you want to start and debug a program on another computer, the remote machine. Pry is a great tool for digging into your code and seeing what's going on with tons of great features. However, there are situations where using a standard binding.pry breakpoint will not block your program and allow you to inspect it.A remote session allows you to start instances of Pry in a running program and connect to those instances over a socket. This is particularly useful for using Pry in places not normally possible, such as apps running on the Pow web server. It also opens the door for such exotica as multi-user sessions.&lt;br /&gt;
&lt;br /&gt;
Pry has two plugins that implement remote sessions: 'pry-remote' and the newer and more ambitious 'pry-remote-em'&amp;lt;ref&amp;gt;https://github.com/Mon-Ouie/pry-remote&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''pry-remote: '''A way to start Pry remotely and to connect to it using DRb. This allows to access the state of the running program from anywhere. Simply replace the normal 'binding.pry' call with 'binding.remote_pry' as the example below illustrates.&lt;br /&gt;
&lt;br /&gt;
We set up the server as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'pry-remote'&lt;br /&gt;
&lt;br /&gt;
class Foo&lt;br /&gt;
  def initialize(x, y)&lt;br /&gt;
    binding.remote_pry&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Foo.new 10, 20&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can then connect to it using the 'pry-remote' executable.&lt;br /&gt;
&lt;br /&gt;
'''pry-remote-em: ''' pry-remote-em is a EventMachine-based alternative to pry-remote. It adds user authentication and SSL support along with tab completion and paging. It also allows multiple clients to connect to the same server, and multiple servers to run on the same computer and even within the same process.&lt;br /&gt;
&lt;br /&gt;
require 'pry-remote-em/server'&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Foo&lt;br /&gt;
  def initialize(x, y)&lt;br /&gt;
    binding.remote_pry_em&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
EM.run { Foo.new 10, 20 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Comparison with other popular debugging tools =&lt;br /&gt;
&lt;br /&gt;
Pry is a cross-over REPL because it supports some of what Ruby Debugger does with addons and sometimes even built and also supports all of what IRB does with some enhancements such as tab completion, code spacing and syntax highlighting as well as supporting an easy way to tap into an object with an REPL easily. There are also other things like the ability to show the source of a class, a method and source around where you are (if you are in a method)&amp;lt;ref&amp;gt;http://www.infoq.com/articles/ruby-debuggers-survey&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Other debuggers available for Ruby are:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Komodo_Edit Komodo]&amp;lt;/span&amp;gt;: The Komodo debugger is a tool for analyzing programs on a line-by-line basis, monitoring and altering variables, and watching output as it is generated. &lt;br /&gt;
&lt;br /&gt;
2. IDEs with embedded scripting support also allow to script the debugger. An option, for instance, is Eclipse's &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[https://www.eclipse.org/proposals/dash/html/maintopic.html EclipseMonkey]&amp;lt;/span&amp;gt; extension which allows scripts written in JRuby. As these scripts run inside the same JVM as the Eclipse IDE, it's possible to access the Debugger instances and control it.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://www.sapphiresteel.com SapphireSteel's]&amp;lt;/span&amp;gt; Ruby in Steel IDE is also built using native code to implement the functionality, complete with using Ruby hooks to get notified about events such as method invocations etc.&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/RadRails Aptana RadRails]&amp;lt;/span&amp;gt;: Aptana RadRails sets breakpoints, inspect variables, control execution. The integrated Ruby &amp;amp; Rails debugger helps you squash the bugs.&lt;br /&gt;
&lt;br /&gt;
5. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/RubyMine RubyMine]&amp;lt;/span&amp;gt;: RubyMine has an excellent step-through debugger which lets you set breakpoints in your code and trace through the program. It provides a useful feature for exploring all of the metaprogramming going on behind the scenes in Ruby on Rails.&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88744</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88744"/>
		<updated>2014-09-26T04:23:05Z</updated>

		<summary type="html">&lt;p&gt;Gshah: /* Installation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Debugging in Rails using Pry'''&amp;lt;/big&amp;gt;     &lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Web_application Web application]&amp;lt;/span&amp;gt; framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Model–view–controller model view controller]&amp;lt;/span&amp;gt;, like Mailers, Routes (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer REST]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol HTTP]&amp;lt;/span&amp;gt;-Verbs, Constraints), Environments and Initializers, Caching (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer Redis]&amp;lt;/span&amp;gt; &lt;br /&gt;
,&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Memcached Memcached]&amp;lt;/span&amp;gt;), Assets (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Sass_(stylesheet_language) SASS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript Javascript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/CoffeeScript CoffeeScript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Pipeline_(computing) Pipelining]&amp;lt;/span&amp;gt;), Bundler and dependency management, Tests (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/RSpec RSpec]&amp;lt;/span&amp;gt; , &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[https://github.com/jnicklas/capybara Capybara]&amp;lt;/span&amp;gt;&amp;lt;ref&amp;gt;https://github.com/jnicklas/capybara&amp;lt;/ref&amp;gt;), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debugging Debugging]&amp;lt;/span&amp;gt;  is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell IRB]&amp;lt;/span&amp;gt; shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Syntax_highlighting Syntax highlighting]&amp;lt;/span&amp;gt;, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration - and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place. &lt;br /&gt;
&lt;br /&gt;
Pry is written in &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby]&amp;lt;/span&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Pry_(software)&amp;lt;/ref&amp;gt;. The Pry core team consists of John Mair, Conrad Irwin and Ryan Fitzgerald and many more contributors. The last stable release was version 0.9.10 and it was released on July 15, 2012. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Read–eval–print_loop REPL]&amp;lt;/span&amp;gt; driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Rubinius Rubinius]&amp;lt;/span&amp;gt; core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/GitHub#Gist Gist]&amp;lt;/span&amp;gt; integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/IPython IPython]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Smalltalk Smalltalk]&amp;lt;/span&amp;gt; and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Usage and Example =&lt;br /&gt;
&lt;br /&gt;
=== Usage ===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
For example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Pry Commands =&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
::''Description'':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
::''Description'':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
::''Description'': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
::''Description'':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
::''Description'': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::''Description'': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
::''Description'': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
::''Description'': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
::''Description'': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
::''Description'': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
= Remote debugging =&lt;br /&gt;
&lt;br /&gt;
Remote debugging means you work on your local computer and you want to start and debug a program on another computer, the remote machine. Pry is a great tool for digging into your code and seeing what's going on with tons of great features. However, there are situations where using a standard binding.pry breakpoint will not block your program and allow you to inspect it.A remote session allows you to start instances of Pry in a running program and connect to those instances over a socket. This is particularly useful for using Pry in places not normally possible, such as apps running on the Pow web server. It also opens the door for such exotica as multi-user sessions.&lt;br /&gt;
&lt;br /&gt;
Pry has two plugins that implement remote sessions: 'pry-remote' and the newer and more ambitious 'pry-remote-em'&amp;lt;ref&amp;gt;https://github.com/Mon-Ouie/pry-remote&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''pry-remote: '''A way to start Pry remotely and to connect to it using DRb. This allows to access the state of the running program from anywhere. Simply replace the normal 'binding.pry' call with 'binding.remote_pry' as the example below illustrates.&lt;br /&gt;
&lt;br /&gt;
We set up the server as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'pry-remote'&lt;br /&gt;
&lt;br /&gt;
class Foo&lt;br /&gt;
  def initialize(x, y)&lt;br /&gt;
    binding.remote_pry&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Foo.new 10, 20&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can then connect to it using the 'pry-remote' executable.&lt;br /&gt;
&lt;br /&gt;
'''pry-remote-em: ''' pry-remote-em is a EventMachine-based alternative to pry-remote. It adds user authentication and SSL support along with tab completion and paging. It also allows multiple clients to connect to the same server, and multiple servers to run on the same computer and even within the same process.&lt;br /&gt;
&lt;br /&gt;
require 'pry-remote-em/server'&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Foo&lt;br /&gt;
  def initialize(x, y)&lt;br /&gt;
    binding.remote_pry_em&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
EM.run { Foo.new 10, 20 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Comparison with other popular debugging tools =&lt;br /&gt;
&lt;br /&gt;
Pry is a cross-over REPL because it supports some of what Ruby Debugger does with addons and sometimes even built and also supports all of what IRB does with some enhancements such as tab completion, code spacing and syntax highlighting as well as supporting an easy way to tap into an object with an REPL easily. There are also other things like the ability to show the source of a class, a method and source around where you are (if you are in a method)&amp;lt;ref&amp;gt;http://www.infoq.com/articles/ruby-debuggers-survey&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Other debuggers available for Ruby are:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Komodo_Edit Komodo]&amp;lt;/span&amp;gt;: The Komodo debugger is a tool for analyzing programs on a line-by-line basis, monitoring and altering variables, and watching output as it is generated. &lt;br /&gt;
&lt;br /&gt;
2. IDEs with embedded scripting support also allow to script the debugger. An option, for instance, is Eclipse's &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[https://www.eclipse.org/proposals/dash/html/maintopic.html EclipseMonkey]&amp;lt;/span&amp;gt; extension which allows scripts written in JRuby. As these scripts run inside the same JVM as the Eclipse IDE, it's possible to access the Debugger instances and control it.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://www.sapphiresteel.com SapphireSteel's]&amp;lt;/span&amp;gt; Ruby in Steel IDE is also built using native code to implement the functionality, complete with using Ruby hooks to get notified about events such as method invocations etc.&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/RadRails Aptana RadRails]&amp;lt;/span&amp;gt;: Aptana RadRails sets breakpoints, inspect variables, control execution. The integrated Ruby &amp;amp; Rails debugger helps you squash the bugs.&lt;br /&gt;
&lt;br /&gt;
5. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/RubyMine RubyMine]&amp;lt;/span&amp;gt;: RubyMine has an excellent step-through debugger which lets you set breakpoints in your code and trace through the program. It provides a useful feature for exploring all of the metaprogramming going on behind the scenes in Ruby on Rails.&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88743</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88743"/>
		<updated>2014-09-26T04:22:43Z</updated>

		<summary type="html">&lt;p&gt;Gshah: /* See also */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Debugging in Rails using Pry'''&amp;lt;/big&amp;gt;     &lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Web_application Web application]&amp;lt;/span&amp;gt; framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Model–view–controller model view controller]&amp;lt;/span&amp;gt;, like Mailers, Routes (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer REST]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol HTTP]&amp;lt;/span&amp;gt;-Verbs, Constraints), Environments and Initializers, Caching (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer Redis]&amp;lt;/span&amp;gt; &lt;br /&gt;
,&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Memcached Memcached]&amp;lt;/span&amp;gt;), Assets (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Sass_(stylesheet_language) SASS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript Javascript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/CoffeeScript CoffeeScript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Pipeline_(computing) Pipelining]&amp;lt;/span&amp;gt;), Bundler and dependency management, Tests (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/RSpec RSpec]&amp;lt;/span&amp;gt; , &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[https://github.com/jnicklas/capybara Capybara]&amp;lt;/span&amp;gt;&amp;lt;ref&amp;gt;https://github.com/jnicklas/capybara&amp;lt;/ref&amp;gt;), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debugging Debugging]&amp;lt;/span&amp;gt;  is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell IRB]&amp;lt;/span&amp;gt; shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Syntax_highlighting Syntax highlighting]&amp;lt;/span&amp;gt;, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration - and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place. &lt;br /&gt;
&lt;br /&gt;
Pry is written in &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby]&amp;lt;/span&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Pry_(software)&amp;lt;/ref&amp;gt;. The Pry core team consists of John Mair, Conrad Irwin and Ryan Fitzgerald and many more contributors. The last stable release was version 0.9.10 and it was released on July 15, 2012. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Read–eval–print_loop REPL]&amp;lt;/span&amp;gt; driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Rubinius Rubinius]&amp;lt;/span&amp;gt; core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/GitHub#Gist Gist]&amp;lt;/span&amp;gt; integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/IPython IPython]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Smalltalk Smalltalk]&amp;lt;/span&amp;gt; and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Usage and Example =&lt;br /&gt;
&lt;br /&gt;
=== Usage ===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
For example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Pry Commands =&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
::''Description'':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
::''Description'':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
::''Description'': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
::''Description'':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
::''Description'': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::''Description'': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
::''Description'': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
::''Description'': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
::''Description'': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
::''Description'': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
= Remote debugging =&lt;br /&gt;
&lt;br /&gt;
Remote debugging means you work on your local computer and you want to start and debug a program on another computer, the remote machine. Pry is a great tool for digging into your code and seeing what's going on with tons of great features. However, there are situations where using a standard binding.pry breakpoint will not block your program and allow you to inspect it.A remote session allows you to start instances of Pry in a running program and connect to those instances over a socket. This is particularly useful for using Pry in places not normally possible, such as apps running on the Pow web server. It also opens the door for such exotica as multi-user sessions.&lt;br /&gt;
&lt;br /&gt;
Pry has two plugins that implement remote sessions: 'pry-remote' and the newer and more ambitious 'pry-remote-em'&amp;lt;ref&amp;gt;https://github.com/Mon-Ouie/pry-remote&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''pry-remote: '''A way to start Pry remotely and to connect to it using DRb. This allows to access the state of the running program from anywhere. Simply replace the normal 'binding.pry' call with 'binding.remote_pry' as the example below illustrates.&lt;br /&gt;
&lt;br /&gt;
We set up the server as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'pry-remote'&lt;br /&gt;
&lt;br /&gt;
class Foo&lt;br /&gt;
  def initialize(x, y)&lt;br /&gt;
    binding.remote_pry&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Foo.new 10, 20&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can then connect to it using the 'pry-remote' executable.&lt;br /&gt;
&lt;br /&gt;
'''pry-remote-em: ''' pry-remote-em is a EventMachine-based alternative to pry-remote. It adds user authentication and SSL support along with tab completion and paging. It also allows multiple clients to connect to the same server, and multiple servers to run on the same computer and even within the same process.&lt;br /&gt;
&lt;br /&gt;
require 'pry-remote-em/server'&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Foo&lt;br /&gt;
  def initialize(x, y)&lt;br /&gt;
    binding.remote_pry_em&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
EM.run { Foo.new 10, 20 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Comparison with other popular debugging tools =&lt;br /&gt;
&lt;br /&gt;
Pry is a cross-over REPL because it supports some of what Ruby Debugger does with addons and sometimes even built and also supports all of what IRB does with some enhancements such as tab completion, code spacing and syntax highlighting as well as supporting an easy way to tap into an object with an REPL easily. There are also other things like the ability to show the source of a class, a method and source around where you are (if you are in a method)&amp;lt;ref&amp;gt;http://www.infoq.com/articles/ruby-debuggers-survey&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Other debuggers available for Ruby are:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Komodo_Edit Komodo]&amp;lt;/span&amp;gt;: The Komodo debugger is a tool for analyzing programs on a line-by-line basis, monitoring and altering variables, and watching output as it is generated. &lt;br /&gt;
&lt;br /&gt;
2. IDEs with embedded scripting support also allow to script the debugger. An option, for instance, is Eclipse's &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[https://www.eclipse.org/proposals/dash/html/maintopic.html EclipseMonkey]&amp;lt;/span&amp;gt; extension which allows scripts written in JRuby. As these scripts run inside the same JVM as the Eclipse IDE, it's possible to access the Debugger instances and control it.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://www.sapphiresteel.com SapphireSteel's]&amp;lt;/span&amp;gt; Ruby in Steel IDE is also built using native code to implement the functionality, complete with using Ruby hooks to get notified about events such as method invocations etc.&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/RadRails Aptana RadRails]&amp;lt;/span&amp;gt;: Aptana RadRails sets breakpoints, inspect variables, control execution. The integrated Ruby &amp;amp; Rails debugger helps you squash the bugs.&lt;br /&gt;
&lt;br /&gt;
5. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/RubyMine RubyMine]&amp;lt;/span&amp;gt;: RubyMine has an excellent step-through debugger which lets you set breakpoints in your code and trace through the program. It provides a useful feature for exploring all of the metaprogramming going on behind the scenes in Ruby on Rails.&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88742</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88742"/>
		<updated>2014-09-26T04:22:17Z</updated>

		<summary type="html">&lt;p&gt;Gshah: /* Comparison with other popular debugging tools */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Debugging in Rails using Pry'''&amp;lt;/big&amp;gt;     &lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Web_application Web application]&amp;lt;/span&amp;gt; framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Model–view–controller model view controller]&amp;lt;/span&amp;gt;, like Mailers, Routes (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer REST]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol HTTP]&amp;lt;/span&amp;gt;-Verbs, Constraints), Environments and Initializers, Caching (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer Redis]&amp;lt;/span&amp;gt; &lt;br /&gt;
,&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Memcached Memcached]&amp;lt;/span&amp;gt;), Assets (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Sass_(stylesheet_language) SASS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript Javascript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/CoffeeScript CoffeeScript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Pipeline_(computing) Pipelining]&amp;lt;/span&amp;gt;), Bundler and dependency management, Tests (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/RSpec RSpec]&amp;lt;/span&amp;gt; , &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[https://github.com/jnicklas/capybara Capybara]&amp;lt;/span&amp;gt;&amp;lt;ref&amp;gt;https://github.com/jnicklas/capybara&amp;lt;/ref&amp;gt;), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debugging Debugging]&amp;lt;/span&amp;gt;  is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell IRB]&amp;lt;/span&amp;gt; shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Syntax_highlighting Syntax highlighting]&amp;lt;/span&amp;gt;, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration - and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place. &lt;br /&gt;
&lt;br /&gt;
Pry is written in &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby]&amp;lt;/span&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Pry_(software)&amp;lt;/ref&amp;gt;. The Pry core team consists of John Mair, Conrad Irwin and Ryan Fitzgerald and many more contributors. The last stable release was version 0.9.10 and it was released on July 15, 2012. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Read–eval–print_loop REPL]&amp;lt;/span&amp;gt; driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Rubinius Rubinius]&amp;lt;/span&amp;gt; core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/GitHub#Gist Gist]&amp;lt;/span&amp;gt; integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/IPython IPython]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Smalltalk Smalltalk]&amp;lt;/span&amp;gt; and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Usage and Example =&lt;br /&gt;
&lt;br /&gt;
=== Usage ===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
For example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Pry Commands =&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
::''Description'':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
::''Description'':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
::''Description'': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
::''Description'':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
::''Description'': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::''Description'': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
::''Description'': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
::''Description'': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
::''Description'': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
::''Description'': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
= Remote debugging =&lt;br /&gt;
&lt;br /&gt;
Remote debugging means you work on your local computer and you want to start and debug a program on another computer, the remote machine. Pry is a great tool for digging into your code and seeing what's going on with tons of great features. However, there are situations where using a standard binding.pry breakpoint will not block your program and allow you to inspect it.A remote session allows you to start instances of Pry in a running program and connect to those instances over a socket. This is particularly useful for using Pry in places not normally possible, such as apps running on the Pow web server. It also opens the door for such exotica as multi-user sessions.&lt;br /&gt;
&lt;br /&gt;
Pry has two plugins that implement remote sessions: 'pry-remote' and the newer and more ambitious 'pry-remote-em'&amp;lt;ref&amp;gt;https://github.com/Mon-Ouie/pry-remote&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''pry-remote: '''A way to start Pry remotely and to connect to it using DRb. This allows to access the state of the running program from anywhere. Simply replace the normal 'binding.pry' call with 'binding.remote_pry' as the example below illustrates.&lt;br /&gt;
&lt;br /&gt;
We set up the server as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'pry-remote'&lt;br /&gt;
&lt;br /&gt;
class Foo&lt;br /&gt;
  def initialize(x, y)&lt;br /&gt;
    binding.remote_pry&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Foo.new 10, 20&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can then connect to it using the 'pry-remote' executable.&lt;br /&gt;
&lt;br /&gt;
'''pry-remote-em: ''' pry-remote-em is a EventMachine-based alternative to pry-remote. It adds user authentication and SSL support along with tab completion and paging. It also allows multiple clients to connect to the same server, and multiple servers to run on the same computer and even within the same process.&lt;br /&gt;
&lt;br /&gt;
require 'pry-remote-em/server'&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Foo&lt;br /&gt;
  def initialize(x, y)&lt;br /&gt;
    binding.remote_pry_em&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
EM.run { Foo.new 10, 20 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Comparison with other popular debugging tools =&lt;br /&gt;
&lt;br /&gt;
Pry is a cross-over REPL because it supports some of what Ruby Debugger does with addons and sometimes even built and also supports all of what IRB does with some enhancements such as tab completion, code spacing and syntax highlighting as well as supporting an easy way to tap into an object with an REPL easily. There are also other things like the ability to show the source of a class, a method and source around where you are (if you are in a method)&amp;lt;ref&amp;gt;http://www.infoq.com/articles/ruby-debuggers-survey&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Other debuggers available for Ruby are:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Komodo_Edit Komodo]&amp;lt;/span&amp;gt;: The Komodo debugger is a tool for analyzing programs on a line-by-line basis, monitoring and altering variables, and watching output as it is generated. &lt;br /&gt;
&lt;br /&gt;
2. IDEs with embedded scripting support also allow to script the debugger. An option, for instance, is Eclipse's &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[https://www.eclipse.org/proposals/dash/html/maintopic.html EclipseMonkey]&amp;lt;/span&amp;gt; extension which allows scripts written in JRuby. As these scripts run inside the same JVM as the Eclipse IDE, it's possible to access the Debugger instances and control it.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://www.sapphiresteel.com SapphireSteel's]&amp;lt;/span&amp;gt; Ruby in Steel IDE is also built using native code to implement the functionality, complete with using Ruby hooks to get notified about events such as method invocations etc.&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/RadRails Aptana RadRails]&amp;lt;/span&amp;gt;: Aptana RadRails sets breakpoints, inspect variables, control execution. The integrated Ruby &amp;amp; Rails debugger helps you squash the bugs.&lt;br /&gt;
&lt;br /&gt;
5. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/RubyMine RubyMine]&amp;lt;/span&amp;gt;: RubyMine has an excellent step-through debugger which lets you set breakpoints in your code and trace through the program. It provides a useful feature for exploring all of the metaprogramming going on behind the scenes in Ruby on Rails.&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88740</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88740"/>
		<updated>2014-09-26T04:08:46Z</updated>

		<summary type="html">&lt;p&gt;Gshah: /* Comparison with other popular debugging tools */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Debugging in Rails using Pry'''&amp;lt;/big&amp;gt;     &lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Web_application Web application]&amp;lt;/span&amp;gt; framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Model–view–controller model view controller]&amp;lt;/span&amp;gt;, like Mailers, Routes (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer REST]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol HTTP]&amp;lt;/span&amp;gt;-Verbs, Constraints), Environments and Initializers, Caching (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer Redis]&amp;lt;/span&amp;gt; &lt;br /&gt;
,&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Memcached Memcached]&amp;lt;/span&amp;gt;), Assets (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Sass_(stylesheet_language) SASS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript Javascript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/CoffeeScript CoffeeScript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Pipeline_(computing) Pipelining]&amp;lt;/span&amp;gt;), Bundler and dependency management, Tests (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/RSpec RSpec]&amp;lt;/span&amp;gt; , &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[https://github.com/jnicklas/capybara Capybara]&amp;lt;/span&amp;gt;&amp;lt;ref&amp;gt;https://github.com/jnicklas/capybara&amp;lt;/ref&amp;gt;), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debugging Debugging]&amp;lt;/span&amp;gt;  is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell IRB]&amp;lt;/span&amp;gt; shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Syntax_highlighting Syntax highlighting]&amp;lt;/span&amp;gt;, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration - and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place. &lt;br /&gt;
&lt;br /&gt;
Pry is written in &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby]&amp;lt;/span&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Pry_(software)&amp;lt;/ref&amp;gt;. The Pry core team consists of John Mair, Conrad Irwin and Ryan Fitzgerald and many more contributors. The last stable release was version 0.9.10 and it was released on July 15, 2012. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Read–eval–print_loop REPL]&amp;lt;/span&amp;gt; driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Rubinius Rubinius]&amp;lt;/span&amp;gt; core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/GitHub#Gist Gist]&amp;lt;/span&amp;gt; integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/IPython IPython]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Smalltalk Smalltalk]&amp;lt;/span&amp;gt; and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Usage and Example =&lt;br /&gt;
&lt;br /&gt;
=== Usage ===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
For example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Pry Commands =&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
::''Description'':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
::''Description'':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
::''Description'': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
::''Description'':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
::''Description'': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::''Description'': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
::''Description'': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
::''Description'': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
::''Description'': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
::''Description'': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
= Remote debugging =&lt;br /&gt;
&lt;br /&gt;
Remote debugging means you work on your local computer and you want to start and debug a program on another computer, the remote machine. Pry is a great tool for digging into your code and seeing what's going on with tons of great features. However, there are situations where using a standard binding.pry breakpoint will not block your program and allow you to inspect it.A remote session allows you to start instances of Pry in a running program and connect to those instances over a socket. This is particularly useful for using Pry in places not normally possible, such as apps running on the Pow web server. It also opens the door for such exotica as multi-user sessions.&lt;br /&gt;
&lt;br /&gt;
Pry has two plugins that implement remote sessions: 'pry-remote' and the newer and more ambitious 'pry-remote-em'&amp;lt;ref&amp;gt;https://github.com/Mon-Ouie/pry-remote&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''pry-remote: '''A way to start Pry remotely and to connect to it using DRb. This allows to access the state of the running program from anywhere. Simply replace the normal 'binding.pry' call with 'binding.remote_pry' as the example below illustrates.&lt;br /&gt;
&lt;br /&gt;
We set up the server as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'pry-remote'&lt;br /&gt;
&lt;br /&gt;
class Foo&lt;br /&gt;
  def initialize(x, y)&lt;br /&gt;
    binding.remote_pry&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Foo.new 10, 20&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can then connect to it using the 'pry-remote' executable.&lt;br /&gt;
&lt;br /&gt;
'''pry-remote-em: ''' pry-remote-em is a EventMachine-based alternative to pry-remote. It adds user authentication and SSL support along with tab completion and paging. It also allows multiple clients to connect to the same server, and multiple servers to run on the same computer and even within the same process.&lt;br /&gt;
&lt;br /&gt;
require 'pry-remote-em/server'&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Foo&lt;br /&gt;
  def initialize(x, y)&lt;br /&gt;
    binding.remote_pry_em&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
EM.run { Foo.new 10, 20 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Comparison with other popular debugging tools =&lt;br /&gt;
&lt;br /&gt;
Pry is a cross-over REPL because it supports some of what Ruby Debugger does with addons and sometimes even built and also supports all of what IRB does with some enhancements such as tab completion, code spacing and syntax highlighting as well as supporting an easy way to tap into an object with an REPL easily. There are also other things like the ability to show the source of a class, a method and source around where you are (if you are in a method)&amp;lt;ref&amp;gt;http://www.infoq.com/articles/ruby-debuggers-survey&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Other debuggers available for Ruby are:&lt;br /&gt;
&lt;br /&gt;
1. http://en.wikipedia.org/wiki/Komodo_Edit&lt;br /&gt;
2. IDEs with embedded scripting support also allow to script the debugger. An option, for instance, is Eclipse's EclipseMonkey extension which allows scripts written in JRuby. As these scripts run inside the same JVM as the Eclipse IDE, it's possible to access the Debugger instances and control it.&lt;br /&gt;
&lt;br /&gt;
3. SapphireSteel's Ruby in Steel IDE is also built using native code to implement the functionality, complete with using Ruby hooks to get notified about events such as method invocations etc.&lt;br /&gt;
&lt;br /&gt;
4. Komodo can debug Ruby&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88736</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88736"/>
		<updated>2014-09-26T03:59:11Z</updated>

		<summary type="html">&lt;p&gt;Gshah: /* Comparison with other popular debugging tools */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Debugging in Rails using Pry'''&amp;lt;/big&amp;gt;     &lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Web_application Web application]&amp;lt;/span&amp;gt; framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Model–view–controller model view controller]&amp;lt;/span&amp;gt;, like Mailers, Routes (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer REST]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol HTTP]&amp;lt;/span&amp;gt;-Verbs, Constraints), Environments and Initializers, Caching (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer Redis]&amp;lt;/span&amp;gt; &lt;br /&gt;
,&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Memcached Memcached]&amp;lt;/span&amp;gt;), Assets (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Sass_(stylesheet_language) SASS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript Javascript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/CoffeeScript CoffeeScript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Pipeline_(computing) Pipelining]&amp;lt;/span&amp;gt;), Bundler and dependency management, Tests (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/RSpec RSpec]&amp;lt;/span&amp;gt; , &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[https://github.com/jnicklas/capybara Capybara]&amp;lt;/span&amp;gt;&amp;lt;ref&amp;gt;https://github.com/jnicklas/capybara&amp;lt;/ref&amp;gt;), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debugging Debugging]&amp;lt;/span&amp;gt;  is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell IRB]&amp;lt;/span&amp;gt; shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Syntax_highlighting Syntax highlighting]&amp;lt;/span&amp;gt;, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration - and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place. &lt;br /&gt;
&lt;br /&gt;
Pry is written in &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby]&amp;lt;/span&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Pry_(software)&amp;lt;/ref&amp;gt;. The Pry core team consists of John Mair, Conrad Irwin and Ryan Fitzgerald and many more contributors. The last stable release was version 0.9.10 and it was released on July 15, 2012. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Read–eval–print_loop REPL]&amp;lt;/span&amp;gt; driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Rubinius Rubinius]&amp;lt;/span&amp;gt; core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/GitHub#Gist Gist]&amp;lt;/span&amp;gt; integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/IPython IPython]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Smalltalk Smalltalk]&amp;lt;/span&amp;gt; and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Usage and Example =&lt;br /&gt;
&lt;br /&gt;
=== Usage ===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
For example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Pry Commands =&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
::''Description'':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
::''Description'':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
::''Description'': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
::''Description'':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
::''Description'': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::''Description'': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
::''Description'': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
::''Description'': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
::''Description'': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
::''Description'': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
= Remote debugging =&lt;br /&gt;
&lt;br /&gt;
Remote debugging means you work on your local computer and you want to start and debug a program on another computer, the remote machine. Pry is a great tool for digging into your code and seeing what's going on with tons of great features. However, there are situations where using a standard binding.pry breakpoint will not block your program and allow you to inspect it.A remote session allows you to start instances of Pry in a running program and connect to those instances over a socket. This is particularly useful for using Pry in places not normally possible, such as apps running on the Pow web server. It also opens the door for such exotica as multi-user sessions.&lt;br /&gt;
&lt;br /&gt;
Pry has two plugins that implement remote sessions: 'pry-remote' and the newer and more ambitious 'pry-remote-em'&amp;lt;ref&amp;gt;https://github.com/Mon-Ouie/pry-remote&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''pry-remote: '''A way to start Pry remotely and to connect to it using DRb. This allows to access the state of the running program from anywhere. Simply replace the normal 'binding.pry' call with 'binding.remote_pry' as the example below illustrates.&lt;br /&gt;
&lt;br /&gt;
We set up the server as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'pry-remote'&lt;br /&gt;
&lt;br /&gt;
class Foo&lt;br /&gt;
  def initialize(x, y)&lt;br /&gt;
    binding.remote_pry&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Foo.new 10, 20&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can then connect to it using the 'pry-remote' executable.&lt;br /&gt;
&lt;br /&gt;
'''pry-remote-em: ''' pry-remote-em is a EventMachine-based alternative to pry-remote. It adds user authentication and SSL support along with tab completion and paging. It also allows multiple clients to connect to the same server, and multiple servers to run on the same computer and even within the same process.&lt;br /&gt;
&lt;br /&gt;
require 'pry-remote-em/server'&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Foo&lt;br /&gt;
  def initialize(x, y)&lt;br /&gt;
    binding.remote_pry_em&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
EM.run { Foo.new 10, 20 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Comparison with other popular debugging tools =&lt;br /&gt;
&lt;br /&gt;
Pry is a cross-over REPL because it supports some of what Ruby Debugger does with addons and sometimes even built and also supports all of what IRB does with some enhancements such as tab completion, code spacing and syntax highlighting as well as supporting an easy way to tap into an object with an REPL easily. There are also other things like the ability to show the source of a class, a method and source around where you are (if you are in a method)&amp;lt;ref&amp;gt;http://www.infoq.com/articles/ruby-debuggers-survey&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Other debuggers available for Ruby are:&lt;br /&gt;
&lt;br /&gt;
1. Command line interfaces for Ruby debuggers are available, such as the one shipped with the Ruby standard library, the Rubinius debugger. While these certainly allow to debug code, they also make it quite tedious to set breakpoints or see what's actually going on. Rubinius debugger uses accessible and modifiable opcodes of the Ruby code. A breakpoint is set by exchanging a regular opcode with a special opcode that suspends the current thread and notifies the higher layers of the debugger stack.&lt;br /&gt;
&lt;br /&gt;
2. IDEs with embedded scripting support also allow to script the debugger. An option, for instance, is Eclipse's EclipseMonkey extension which allows scripts written in JRuby. As these scripts run inside the same JVM as the Eclipse IDE, it's possible to access the Debugger instances and control it.&lt;br /&gt;
&lt;br /&gt;
3. SapphireSteel's Ruby in Steel IDE is also built using native code to implement the functionality, complete with using Ruby hooks to get notified about events such as method invocations etc.&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88703</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88703"/>
		<updated>2014-09-26T03:28:45Z</updated>

		<summary type="html">&lt;p&gt;Gshah: /* Remote debugging */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Debugging in Rails using Pry'''&amp;lt;/big&amp;gt;     &lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Web_application Web application]&amp;lt;/span&amp;gt; framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Model–view–controller model view controller]&amp;lt;/span&amp;gt;, like Mailers, Routes (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer REST]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol HTTP]&amp;lt;/span&amp;gt;-Verbs, Constraints), Environments and Initializers, Caching (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer Redis]&amp;lt;/span&amp;gt; &lt;br /&gt;
,&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Memcached Memcached]&amp;lt;/span&amp;gt;), Assets (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Sass_(stylesheet_language) SASS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript Javascript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/CoffeeScript CoffeeScript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Pipeline_(computing) Pipelining]&amp;lt;/span&amp;gt;), Bundler and dependency management, Tests (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/RSpec RSpec]&amp;lt;/span&amp;gt; , &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[https://github.com/jnicklas/capybara Capybara]&amp;lt;/span&amp;gt;&amp;lt;ref&amp;gt;https://github.com/jnicklas/capybara&amp;lt;/ref&amp;gt;), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debugging Debugging]&amp;lt;/span&amp;gt;  is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell IRB]&amp;lt;/span&amp;gt; shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Syntax_highlighting Syntax highlighting]&amp;lt;/span&amp;gt;, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration - and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place. &lt;br /&gt;
&lt;br /&gt;
Pry is written in &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby]&amp;lt;/span&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Pry_(software)&amp;lt;/ref&amp;gt;. The Pry core team consists of John Mair, Conrad Irwin and Ryan Fitzgerald and many more contributors. The last stable release was version 0.9.10 and it was released on July 15, 2012. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Read–eval–print_loop REPL]&amp;lt;/span&amp;gt; driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Rubinius Rubinius]&amp;lt;/span&amp;gt; core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/GitHub#Gist Gist]&amp;lt;/span&amp;gt; integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/IPython IPython]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Smalltalk Smalltalk]&amp;lt;/span&amp;gt; and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Usage and Example =&lt;br /&gt;
&lt;br /&gt;
=== Usage ===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
For example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Pry Commands =&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
::''Description'':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
::''Description'':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
::''Description'': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
::''Description'':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
::''Description'': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::''Description'': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
::''Description'': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
::''Description'': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
::''Description'': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
::''Description'': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
= Remote debugging =&lt;br /&gt;
&lt;br /&gt;
Remote debugging means you work on your local computer and you want to start and debug a program on another computer, the remote machine. Pry is a great tool for digging into your code and seeing what's going on with tons of great features. However, there are situations where using a standard binding.pry breakpoint will not block your program and allow you to inspect it.A remote session allows you to start instances of Pry in a running program and connect to those instances over a socket. This is particularly useful for using Pry in places not normally possible, such as apps running on the Pow web server. It also opens the door for such exotica as multi-user sessions.&lt;br /&gt;
&lt;br /&gt;
Pry has two plugins that implement remote sessions: 'pry-remote' and the newer and more ambitious 'pry-remote-em'&amp;lt;ref&amp;gt;https://github.com/Mon-Ouie/pry-remote&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''pry-remote: '''A way to start Pry remotely and to connect to it using DRb. This allows to access the state of the running program from anywhere. Simply replace the normal 'binding.pry' call with 'binding.remote_pry' as the example below illustrates.&lt;br /&gt;
&lt;br /&gt;
We set up the server as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'pry-remote'&lt;br /&gt;
&lt;br /&gt;
class Foo&lt;br /&gt;
  def initialize(x, y)&lt;br /&gt;
    binding.remote_pry&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Foo.new 10, 20&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can then connect to it using the 'pry-remote' executable.&lt;br /&gt;
&lt;br /&gt;
'''pry-remote-em: ''' pry-remote-em is a EventMachine-based alternative to pry-remote. It adds user authentication and SSL support along with tab completion and paging. It also allows multiple clients to connect to the same server, and multiple servers to run on the same computer and even within the same process.&lt;br /&gt;
&lt;br /&gt;
require 'pry-remote-em/server'&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Foo&lt;br /&gt;
  def initialize(x, y)&lt;br /&gt;
    binding.remote_pry_em&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
EM.run { Foo.new 10, 20 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Comparison with other popular debugging tools =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88699</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88699"/>
		<updated>2014-09-26T03:26:00Z</updated>

		<summary type="html">&lt;p&gt;Gshah: /* Remote debugging */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Debugging in Rails using Pry'''&amp;lt;/big&amp;gt;     &lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Web_application Web application]&amp;lt;/span&amp;gt; framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Model–view–controller model view controller]&amp;lt;/span&amp;gt;, like Mailers, Routes (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer REST]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol HTTP]&amp;lt;/span&amp;gt;-Verbs, Constraints), Environments and Initializers, Caching (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer Redis]&amp;lt;/span&amp;gt; &lt;br /&gt;
,&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Memcached Memcached]&amp;lt;/span&amp;gt;), Assets (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Sass_(stylesheet_language) SASS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript Javascript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/CoffeeScript CoffeeScript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Pipeline_(computing) Pipelining]&amp;lt;/span&amp;gt;), Bundler and dependency management, Tests (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/RSpec RSpec]&amp;lt;/span&amp;gt; , &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[https://github.com/jnicklas/capybara Capybara]&amp;lt;/span&amp;gt;&amp;lt;ref&amp;gt;https://github.com/jnicklas/capybara&amp;lt;/ref&amp;gt;), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debugging Debugging]&amp;lt;/span&amp;gt;  is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell IRB]&amp;lt;/span&amp;gt; shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Syntax_highlighting Syntax highlighting]&amp;lt;/span&amp;gt;, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration - and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place. &lt;br /&gt;
&lt;br /&gt;
Pry is written in &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby]&amp;lt;/span&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Pry_(software)&amp;lt;/ref&amp;gt;. The Pry core team consists of John Mair, Conrad Irwin and Ryan Fitzgerald and many more contributors. The last stable release was version 0.9.10 and it was released on July 15, 2012. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Read–eval–print_loop REPL]&amp;lt;/span&amp;gt; driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Rubinius Rubinius]&amp;lt;/span&amp;gt; core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/GitHub#Gist Gist]&amp;lt;/span&amp;gt; integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/IPython IPython]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Smalltalk Smalltalk]&amp;lt;/span&amp;gt; and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Usage and Example =&lt;br /&gt;
&lt;br /&gt;
=== Usage ===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
For example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Pry Commands =&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
::''Description'':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
::''Description'':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
::''Description'': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
::''Description'':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
::''Description'': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::''Description'': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
::''Description'': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
::''Description'': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
::''Description'': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
::''Description'': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
= Remote debugging =&lt;br /&gt;
&lt;br /&gt;
Remote debugging means you work on your local computer and you want to start and debug a program on another computer, the remote machine. Pry is a great tool for digging into your code and seeing what's going on with tons of great features. However, there are situations where using a standard binding.pry breakpoint will not block your program and allow you to inspect it.A remote session allows you to start instances of Pry in a running program and connect to those instances over a socket. This is particularly useful for using Pry in places not normally possible, such as apps running on the Pow web server. It also opens the door for such exotica as multi-user sessions.&lt;br /&gt;
&lt;br /&gt;
Pry has two plugins that implement remote sessions: 'pry-remote' and the newer and more ambitious 'pry-remote-em'.&lt;br /&gt;
&lt;br /&gt;
'''pry-remote: '''A way to start Pry remotely and to connect to it using DRb. This allows to access the state of the running program from anywhere. Simply replace the normal 'binding.pry' call with 'binding.remote_pry' as the example below illustrates.&lt;br /&gt;
&lt;br /&gt;
We set up the server as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'pry-remote'&lt;br /&gt;
&lt;br /&gt;
class Foo&lt;br /&gt;
  def initialize(x, y)&lt;br /&gt;
    binding.remote_pry&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Foo.new 10, 20&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can then connect to it using the 'pry-remote' executable.&lt;br /&gt;
&lt;br /&gt;
'''pry-remote-em: ''' pry-remote-em is a EventMachine-based alternative to pry-remote. It adds user authentication and SSL support along with tab completion and paging. It also allows multiple clients to connect to the same server, and multiple servers to run on the same computer and even within the same process.&lt;br /&gt;
&lt;br /&gt;
require 'pry-remote-em/server'&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Foo&lt;br /&gt;
  def initialize(x, y)&lt;br /&gt;
    binding.remote_pry_em&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
EM.run { Foo.new 10, 20 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Comparison with other popular debugging tools =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88691</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88691"/>
		<updated>2014-09-26T03:22:25Z</updated>

		<summary type="html">&lt;p&gt;Gshah: /* Remote debugging */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Debugging in Rails using Pry'''&amp;lt;/big&amp;gt;     &lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Web_application Web application]&amp;lt;/span&amp;gt; framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Model–view–controller model view controller]&amp;lt;/span&amp;gt;, like Mailers, Routes (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer REST]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol HTTP]&amp;lt;/span&amp;gt;-Verbs, Constraints), Environments and Initializers, Caching (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer Redis]&amp;lt;/span&amp;gt; &lt;br /&gt;
,&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Memcached Memcached]&amp;lt;/span&amp;gt;), Assets (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Sass_(stylesheet_language) SASS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript Javascript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/CoffeeScript CoffeeScript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Pipeline_(computing) Pipelining]&amp;lt;/span&amp;gt;), Bundler and dependency management, Tests (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/RSpec RSpec]&amp;lt;/span&amp;gt; , &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[https://github.com/jnicklas/capybara Capybara]&amp;lt;/span&amp;gt;&amp;lt;ref&amp;gt;https://github.com/jnicklas/capybara&amp;lt;/ref&amp;gt;), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debugging Debugging]&amp;lt;/span&amp;gt;  is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell IRB]&amp;lt;/span&amp;gt; shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Syntax_highlighting Syntax highlighting]&amp;lt;/span&amp;gt;, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration - and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place. &lt;br /&gt;
&lt;br /&gt;
Pry is written in &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby]&amp;lt;/span&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Pry_(software)&amp;lt;/ref&amp;gt;. The Pry core team consists of John Mair, Conrad Irwin and Ryan Fitzgerald and many more contributors. The last stable release was version 0.9.10 and it was released on July 15, 2012. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Read–eval–print_loop REPL]&amp;lt;/span&amp;gt; driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Rubinius Rubinius]&amp;lt;/span&amp;gt; core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/GitHub#Gist Gist]&amp;lt;/span&amp;gt; integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/IPython IPython]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Smalltalk Smalltalk]&amp;lt;/span&amp;gt; and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Usage and Example =&lt;br /&gt;
&lt;br /&gt;
=== Usage ===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
For example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Pry Commands =&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
::''Description'':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
::''Description'':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
::''Description'': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
::''Description'':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
::''Description'': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::''Description'': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
::''Description'': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
::''Description'': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
::''Description'': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
::''Description'': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
= Remote debugging =&lt;br /&gt;
&lt;br /&gt;
Remote debugging means you work on your local computer and you want to start and debug a program on another computer, the remote machine. Pry is a great tool for digging into your code and seeing what's going on with tons of great features. However, there are situations where using a standard binding.pry breakpoint will not block your program and allow you to inspect it.A remote session allows you to start instances of Pry in a running program and connect to those instances over a socket. This is particularly useful for using Pry in places not normally possible, such as apps running on the Pow web server. It also opens the door for such exotica as multi-user sessions.&lt;br /&gt;
&lt;br /&gt;
Pry has two plugins that implement remote sessions: 'pry-remote' and the newer and more ambitious 'pry-remote-em'.&lt;br /&gt;
&lt;br /&gt;
'''pry-remote: '''A way to start Pry remotely and to connect to it using DRb. This allows to access the state of the running program from anywhere. Simply replace the normal 'binding.pry' call with 'binding.remote_pry' as the example below illustrates.&lt;br /&gt;
&lt;br /&gt;
We set up the server as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'pry-remote'&lt;br /&gt;
&lt;br /&gt;
class Foo&lt;br /&gt;
  def initialize(x, y)&lt;br /&gt;
    binding.remote_pry&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Foo.new 10, 20&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can then connect to it using the 'pry-remote' executable.&lt;br /&gt;
&lt;br /&gt;
'''pry-remote-em: '''&lt;br /&gt;
&lt;br /&gt;
= Comparison with other popular debugging tools =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88679</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88679"/>
		<updated>2014-09-26T03:13:50Z</updated>

		<summary type="html">&lt;p&gt;Gshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Debugging in Rails using Pry'''&amp;lt;/big&amp;gt;     &lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Web_application Web application]&amp;lt;/span&amp;gt; framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Model–view–controller model view controller]&amp;lt;/span&amp;gt;, like Mailers, Routes (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer REST]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol HTTP]&amp;lt;/span&amp;gt;-Verbs, Constraints), Environments and Initializers, Caching (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer Redis]&amp;lt;/span&amp;gt; &lt;br /&gt;
,&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Memcached Memcached]&amp;lt;/span&amp;gt;), Assets (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Sass_(stylesheet_language) SASS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript Javascript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/CoffeeScript CoffeeScript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Pipeline_(computing) Pipelining]&amp;lt;/span&amp;gt;), Bundler and dependency management, Tests (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/RSpec RSpec]&amp;lt;/span&amp;gt; , &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[https://github.com/jnicklas/capybara Capybara]&amp;lt;/span&amp;gt;&amp;lt;ref&amp;gt;https://github.com/jnicklas/capybara&amp;lt;/ref&amp;gt;), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debugging Debugging]&amp;lt;/span&amp;gt;  is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell IRB]&amp;lt;/span&amp;gt; shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Syntax_highlighting Syntax highlighting]&amp;lt;/span&amp;gt;, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration - and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place. &lt;br /&gt;
&lt;br /&gt;
Pry is written in &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby]&amp;lt;/span&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Pry_(software)&amp;lt;/ref&amp;gt;. The Pry core team consists of John Mair, Conrad Irwin and Ryan Fitzgerald and many more contributors. The last stable release was version 0.9.10 and it was released on July 15, 2012. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Read–eval–print_loop REPL]&amp;lt;/span&amp;gt; driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Rubinius Rubinius]&amp;lt;/span&amp;gt; core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/GitHub#Gist Gist]&amp;lt;/span&amp;gt; integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/IPython IPython]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Smalltalk Smalltalk]&amp;lt;/span&amp;gt; and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Usage and Example =&lt;br /&gt;
&lt;br /&gt;
=== Usage ===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
For example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Pry Commands =&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
::''Description'':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
::''Description'':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
::''Description'': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
::''Description'':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
::''Description'': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::''Description'': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
::''Description'': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
::''Description'': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
::''Description'': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
::''Description'': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
= Remote debugging =&lt;br /&gt;
&lt;br /&gt;
Remote debugging means you work on your local computer and you want to start and debug a program on another computer, the remote machine. Pry is a great tool for digging into your code and seeing what's going on with tons of great features. However, there are situations where using a standard binding.pry breakpoint will not block your program and allow you to inspect it.Pry-remote (along with its cousin pry-remote-em) enables you to start instances of Pry in a running program and connect to those instances over a network or the Internet. Once connected you can interact with the internal state of the program. This plugin comes into its own when used with tools such as Pow, enabling you to get a Pry session in places not normally possible. pry-remote is also notable for having pry-nav support.&lt;br /&gt;
&lt;br /&gt;
We set up the server as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'pry-remote'&lt;br /&gt;
&lt;br /&gt;
class Foo&lt;br /&gt;
  def initialize(x, y)&lt;br /&gt;
    binding.remote_pry&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Foo.new 10, 20&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Comparison with other popular debugging tools =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88677</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88677"/>
		<updated>2014-09-26T03:13:37Z</updated>

		<summary type="html">&lt;p&gt;Gshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Debugging in Rails using Pry'''&amp;lt;/big&amp;gt;     &lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|thumb]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Web_application Web application]&amp;lt;/span&amp;gt; framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Model–view–controller model view controller]&amp;lt;/span&amp;gt;, like Mailers, Routes (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer REST]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol HTTP]&amp;lt;/span&amp;gt;-Verbs, Constraints), Environments and Initializers, Caching (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer Redis]&amp;lt;/span&amp;gt; &lt;br /&gt;
,&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Memcached Memcached]&amp;lt;/span&amp;gt;), Assets (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Sass_(stylesheet_language) SASS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript Javascript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/CoffeeScript CoffeeScript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Pipeline_(computing) Pipelining]&amp;lt;/span&amp;gt;), Bundler and dependency management, Tests (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/RSpec RSpec]&amp;lt;/span&amp;gt; , &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[https://github.com/jnicklas/capybara Capybara]&amp;lt;/span&amp;gt;&amp;lt;ref&amp;gt;https://github.com/jnicklas/capybara&amp;lt;/ref&amp;gt;), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debugging Debugging]&amp;lt;/span&amp;gt;  is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell IRB]&amp;lt;/span&amp;gt; shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Syntax_highlighting Syntax highlighting]&amp;lt;/span&amp;gt;, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration - and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place. &lt;br /&gt;
&lt;br /&gt;
Pry is written in &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby]&amp;lt;/span&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Pry_(software)&amp;lt;/ref&amp;gt;. The Pry core team consists of John Mair, Conrad Irwin and Ryan Fitzgerald and many more contributors. The last stable release was version 0.9.10 and it was released on July 15, 2012. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Read–eval–print_loop REPL]&amp;lt;/span&amp;gt; driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Rubinius Rubinius]&amp;lt;/span&amp;gt; core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/GitHub#Gist Gist]&amp;lt;/span&amp;gt; integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/IPython IPython]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Smalltalk Smalltalk]&amp;lt;/span&amp;gt; and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Usage and Example =&lt;br /&gt;
&lt;br /&gt;
=== Usage ===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
For example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Pry Commands =&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
::''Description'':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
::''Description'':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
::''Description'': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
::''Description'':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
::''Description'': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::''Description'': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
::''Description'': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
::''Description'': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
::''Description'': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
::''Description'': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
= Remote debugging =&lt;br /&gt;
&lt;br /&gt;
Remote debugging means you work on your local computer and you want to start and debug a program on another computer, the remote machine. Pry is a great tool for digging into your code and seeing what's going on with tons of great features. However, there are situations where using a standard binding.pry breakpoint will not block your program and allow you to inspect it.Pry-remote (along with its cousin pry-remote-em) enables you to start instances of Pry in a running program and connect to those instances over a network or the Internet. Once connected you can interact with the internal state of the program. This plugin comes into its own when used with tools such as Pow, enabling you to get a Pry session in places not normally possible. pry-remote is also notable for having pry-nav support.&lt;br /&gt;
&lt;br /&gt;
We set up the server as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'pry-remote'&lt;br /&gt;
&lt;br /&gt;
class Foo&lt;br /&gt;
  def initialize(x, y)&lt;br /&gt;
    binding.remote_pry&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Foo.new 10, 20&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Comparison with other popular debugging tools =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88675</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88675"/>
		<updated>2014-09-26T03:13:12Z</updated>

		<summary type="html">&lt;p&gt;Gshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Debugging in Rails using Pry'''&amp;lt;/big&amp;gt;     &lt;br /&gt;
&lt;br /&gt;
&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;[[File:Pry REPL Logo.png|right]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Web_application Web application]&amp;lt;/span&amp;gt; framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Model–view–controller model view controller]&amp;lt;/span&amp;gt;, like Mailers, Routes (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer REST]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol HTTP]&amp;lt;/span&amp;gt;-Verbs, Constraints), Environments and Initializers, Caching (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer Redis]&amp;lt;/span&amp;gt; &lt;br /&gt;
,&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Memcached Memcached]&amp;lt;/span&amp;gt;), Assets (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Sass_(stylesheet_language) SASS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript Javascript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/CoffeeScript CoffeeScript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Pipeline_(computing) Pipelining]&amp;lt;/span&amp;gt;), Bundler and dependency management, Tests (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/RSpec RSpec]&amp;lt;/span&amp;gt; , &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[https://github.com/jnicklas/capybara Capybara]&amp;lt;/span&amp;gt;&amp;lt;ref&amp;gt;https://github.com/jnicklas/capybara&amp;lt;/ref&amp;gt;), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debugging Debugging]&amp;lt;/span&amp;gt;  is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell IRB]&amp;lt;/span&amp;gt; shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Syntax_highlighting Syntax highlighting]&amp;lt;/span&amp;gt;, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration - and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place. &lt;br /&gt;
&lt;br /&gt;
Pry is written in &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby]&amp;lt;/span&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Pry_(software)&amp;lt;/ref&amp;gt;. The Pry core team consists of John Mair, Conrad Irwin and Ryan Fitzgerald and many more contributors. The last stable release was version 0.9.10 and it was released on July 15, 2012. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Read–eval–print_loop REPL]&amp;lt;/span&amp;gt; driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Rubinius Rubinius]&amp;lt;/span&amp;gt; core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/GitHub#Gist Gist]&amp;lt;/span&amp;gt; integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/IPython IPython]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Smalltalk Smalltalk]&amp;lt;/span&amp;gt; and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Usage and Example =&lt;br /&gt;
&lt;br /&gt;
=== Usage ===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
For example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Pry Commands =&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
::''Description'':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
::''Description'':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
::''Description'': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
::''Description'':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
::''Description'': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::''Description'': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
::''Description'': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
::''Description'': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
::''Description'': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
::''Description'': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
= Remote debugging =&lt;br /&gt;
&lt;br /&gt;
Remote debugging means you work on your local computer and you want to start and debug a program on another computer, the remote machine. Pry is a great tool for digging into your code and seeing what's going on with tons of great features. However, there are situations where using a standard binding.pry breakpoint will not block your program and allow you to inspect it.Pry-remote (along with its cousin pry-remote-em) enables you to start instances of Pry in a running program and connect to those instances over a network or the Internet. Once connected you can interact with the internal state of the program. This plugin comes into its own when used with tools such as Pow, enabling you to get a Pry session in places not normally possible. pry-remote is also notable for having pry-nav support.&lt;br /&gt;
&lt;br /&gt;
We set up the server as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'pry-remote'&lt;br /&gt;
&lt;br /&gt;
class Foo&lt;br /&gt;
  def initialize(x, y)&lt;br /&gt;
    binding.remote_pry&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Foo.new 10, 20&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Comparison with other popular debugging tools =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88672</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88672"/>
		<updated>2014-09-26T03:12:32Z</updated>

		<summary type="html">&lt;p&gt;Gshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Debugging in Rails using Pry'''&amp;lt;/big&amp;gt;     &lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right]]&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Web_application Web application]&amp;lt;/span&amp;gt; framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Model–view–controller model view controller]&amp;lt;/span&amp;gt;, like Mailers, Routes (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer REST]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol HTTP]&amp;lt;/span&amp;gt;-Verbs, Constraints), Environments and Initializers, Caching (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer Redis]&amp;lt;/span&amp;gt; &lt;br /&gt;
,&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Memcached Memcached]&amp;lt;/span&amp;gt;), Assets (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Sass_(stylesheet_language) SASS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript Javascript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/CoffeeScript CoffeeScript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Pipeline_(computing) Pipelining]&amp;lt;/span&amp;gt;), Bundler and dependency management, Tests (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/RSpec RSpec]&amp;lt;/span&amp;gt; , &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[https://github.com/jnicklas/capybara Capybara]&amp;lt;/span&amp;gt;&amp;lt;ref&amp;gt;https://github.com/jnicklas/capybara&amp;lt;/ref&amp;gt;), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debugging Debugging]&amp;lt;/span&amp;gt;  is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell IRB]&amp;lt;/span&amp;gt; shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Syntax_highlighting Syntax highlighting]&amp;lt;/span&amp;gt;, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration - and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place. &lt;br /&gt;
&lt;br /&gt;
Pry is written in &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby]&amp;lt;/span&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Pry_(software)&amp;lt;/ref&amp;gt;. The Pry core team consists of John Mair, Conrad Irwin and Ryan Fitzgerald and many more contributors. The last stable release was version 0.9.10 and it was released on July 15, 2012. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Read–eval–print_loop REPL]&amp;lt;/span&amp;gt; driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Rubinius Rubinius]&amp;lt;/span&amp;gt; core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/GitHub#Gist Gist]&amp;lt;/span&amp;gt; integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/IPython IPython]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Smalltalk Smalltalk]&amp;lt;/span&amp;gt; and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Usage and Example =&lt;br /&gt;
&lt;br /&gt;
=== Usage ===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
For example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Pry Commands =&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
::''Description'':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
::''Description'':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
::''Description'': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
::''Description'':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
::''Description'': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::''Description'': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
::''Description'': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
::''Description'': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
::''Description'': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
::''Description'': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
= Remote debugging =&lt;br /&gt;
&lt;br /&gt;
Remote debugging means you work on your local computer and you want to start and debug a program on another computer, the remote machine. Pry is a great tool for digging into your code and seeing what's going on with tons of great features. However, there are situations where using a standard binding.pry breakpoint will not block your program and allow you to inspect it.Pry-remote (along with its cousin pry-remote-em) enables you to start instances of Pry in a running program and connect to those instances over a network or the Internet. Once connected you can interact with the internal state of the program. This plugin comes into its own when used with tools such as Pow, enabling you to get a Pry session in places not normally possible. pry-remote is also notable for having pry-nav support.&lt;br /&gt;
&lt;br /&gt;
We set up the server as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'pry-remote'&lt;br /&gt;
&lt;br /&gt;
class Foo&lt;br /&gt;
  def initialize(x, y)&lt;br /&gt;
    binding.remote_pry&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Foo.new 10, 20&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Comparison with other popular debugging tools =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88669</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88669"/>
		<updated>2014-09-26T03:10:24Z</updated>

		<summary type="html">&lt;p&gt;Gshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Debugging in Rails using Pry'''&amp;lt;/big&amp;gt;     &lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right|Pry REPL: a powerful IRB alternative and runtime developer console for Ruby.]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Web_application Web application]&amp;lt;/span&amp;gt; framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Model–view–controller model view controller]&amp;lt;/span&amp;gt;, like Mailers, Routes (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer REST]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol HTTP]&amp;lt;/span&amp;gt;-Verbs, Constraints), Environments and Initializers, Caching (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer Redis]&amp;lt;/span&amp;gt; &lt;br /&gt;
,&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Memcached Memcached]&amp;lt;/span&amp;gt;), Assets (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Sass_(stylesheet_language) SASS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript Javascript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/CoffeeScript CoffeeScript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Pipeline_(computing) Pipelining]&amp;lt;/span&amp;gt;), Bundler and dependency management, Tests (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/RSpec RSpec]&amp;lt;/span&amp;gt; , &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[https://github.com/jnicklas/capybara Capybara]&amp;lt;/span&amp;gt;&amp;lt;ref&amp;gt;https://github.com/jnicklas/capybara&amp;lt;/ref&amp;gt;), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debugging Debugging]&amp;lt;/span&amp;gt;  is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell IRB]&amp;lt;/span&amp;gt; shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Syntax_highlighting Syntax highlighting]&amp;lt;/span&amp;gt;, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration - and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place. &lt;br /&gt;
&lt;br /&gt;
Pry is written in &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby]&amp;lt;/span&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Pry_(software)&amp;lt;/ref&amp;gt;. The Pry core team consists of John Mair, Conrad Irwin and Ryan Fitzgerald and many more contributors. The last stable release was version 0.9.10 and it was released on July 15, 2012. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Read–eval–print_loop REPL]&amp;lt;/span&amp;gt; driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Rubinius Rubinius]&amp;lt;/span&amp;gt; core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/GitHub#Gist Gist]&amp;lt;/span&amp;gt; integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/IPython IPython]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Smalltalk Smalltalk]&amp;lt;/span&amp;gt; and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Usage and Example =&lt;br /&gt;
&lt;br /&gt;
=== Usage ===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
For example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Pry Commands =&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
::''Description'':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
::''Description'':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
::''Description'': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
::''Description'':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
::''Description'': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::''Description'': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
::''Description'': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
::''Description'': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
::''Description'': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
::''Description'': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
= Remote debugging =&lt;br /&gt;
&lt;br /&gt;
Remote debugging means you work on your local computer and you want to start and debug a program on another computer, the remote machine. Pry is a great tool for digging into your code and seeing what's going on with tons of great features. However, there are situations where using a standard binding.pry breakpoint will not block your program and allow you to inspect it.Pry-remote (along with its cousin pry-remote-em) enables you to start instances of Pry in a running program and connect to those instances over a network or the Internet. Once connected you can interact with the internal state of the program. This plugin comes into its own when used with tools such as Pow, enabling you to get a Pry session in places not normally possible. pry-remote is also notable for having pry-nav support.&lt;br /&gt;
&lt;br /&gt;
We set up the server as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'pry-remote'&lt;br /&gt;
&lt;br /&gt;
class Foo&lt;br /&gt;
  def initialize(x, y)&lt;br /&gt;
    binding.remote_pry&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Foo.new 10, 20&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Comparison with other popular debugging tools =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88668</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88668"/>
		<updated>2014-09-26T03:09:04Z</updated>

		<summary type="html">&lt;p&gt;Gshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Debugging in Rails using Pry'''&amp;lt;/big&amp;gt;     &lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right|Pry REPL: a powerful IRB alternative and runtime developer console for Ruby.]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Web_application Web application]&amp;lt;/span&amp;gt; framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Model–view–controller model view controller]&amp;lt;/span&amp;gt;, like Mailers, Routes (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer REST]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol HTTP]&amp;lt;/span&amp;gt;-Verbs, Constraints), Environments and Initializers, Caching (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer Redis]&amp;lt;/span&amp;gt; &lt;br /&gt;
,&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Memcached Memcached]&amp;lt;/span&amp;gt;), Assets (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Sass_(stylesheet_language) SASS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript Javascript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/CoffeeScript CoffeeScript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Pipeline_(computing) Pipelining]&amp;lt;/span&amp;gt;), Bundler and dependency management, Tests (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/RSpec RSpec]&amp;lt;/span&amp;gt; , &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[https://github.com/jnicklas/capybara Capybara]&amp;lt;/span&amp;gt;&amp;lt;ref&amp;gt;https://github.com/jnicklas/capybara&amp;lt;/ref&amp;gt;), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debugging Debugging]&amp;lt;/span&amp;gt;  is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell IRB]&amp;lt;/span&amp;gt; shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Syntax_highlighting Syntax highlighting]&amp;lt;/span&amp;gt;, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration - and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place. &lt;br /&gt;
&lt;br /&gt;
Pry is written in Ruby&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Pry_(software)&amp;lt;/ref&amp;gt;. The Pry core team consists of John Mair, Conrad Irwin and Ryan Fitzgerald and many more contributors. The last stable release was version 0.9.10 and it was released on July 15, 2012. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Read–eval–print_loop REPL]&amp;lt;/span&amp;gt; driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Rubinius Rubinius]&amp;lt;/span&amp;gt; core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/GitHub#Gist Gist]&amp;lt;/span&amp;gt; integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/IPython IPython]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Smalltalk Smalltalk]&amp;lt;/span&amp;gt; and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Usage and Example =&lt;br /&gt;
&lt;br /&gt;
=== Usage ===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
For example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Pry Commands =&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
::''Description'':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
::''Description'':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
::''Description'': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
::''Description'':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
::''Description'': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::''Description'': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
::''Description'': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
::''Description'': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
::''Description'': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
::''Description'': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
= Remote debugging =&lt;br /&gt;
&lt;br /&gt;
Remote debugging means you work on your local computer and you want to start and debug a program on another computer, the remote machine. Pry is a great tool for digging into your code and seeing what's going on with tons of great features. However, there are situations where using a standard binding.pry breakpoint will not block your program and allow you to inspect it.Pry-remote (along with its cousin pry-remote-em) enables you to start instances of Pry in a running program and connect to those instances over a network or the Internet. Once connected you can interact with the internal state of the program. This plugin comes into its own when used with tools such as Pow, enabling you to get a Pry session in places not normally possible. pry-remote is also notable for having pry-nav support.&lt;br /&gt;
&lt;br /&gt;
We set up the server as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'pry-remote'&lt;br /&gt;
&lt;br /&gt;
class Foo&lt;br /&gt;
  def initialize(x, y)&lt;br /&gt;
    binding.remote_pry&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Foo.new 10, 20&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Comparison with other popular debugging tools =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88666</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88666"/>
		<updated>2014-09-26T03:07:34Z</updated>

		<summary type="html">&lt;p&gt;Gshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Debugging in Rails using Pry'''&amp;lt;/big&amp;gt;     &lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right|Pry REPL: a powerful IRB alternative and runtime developer console for Ruby.]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Web_application Web application]&amp;lt;/span&amp;gt; framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Model–view–controller model view controller]&amp;lt;/span&amp;gt;, like Mailers, Routes (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer REST]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol HTTP]&amp;lt;/span&amp;gt;-Verbs, Constraints), Environments and Initializers, Caching (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer Redis]&amp;lt;/span&amp;gt; &lt;br /&gt;
,&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Memcached Memcached]&amp;lt;/span&amp;gt;), Assets (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Sass_(stylesheet_language) SASS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript Javascript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/CoffeeScript CoffeeScript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Pipeline_(computing) Pipelining]&amp;lt;/span&amp;gt;), Bundler and dependency management, Tests (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/RSpec RSpec]&amp;lt;/span&amp;gt; , &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[https://github.com/jnicklas/capybara Capybara]&amp;lt;/span&amp;gt;&amp;lt;ref&amp;gt;https://github.com/jnicklas/capybara&amp;lt;/ref&amp;gt;), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debugging Debugging]&amp;lt;/span&amp;gt;  is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell IRB]&amp;lt;/span&amp;gt; shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Syntax_highlighting Syntax highlighting]&amp;lt;/span&amp;gt;, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration - and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place. &lt;br /&gt;
&lt;br /&gt;
Pry is written in Ruby&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Pry_(software)#Competitors&amp;lt;/ref&amp;gt;. The Pry core team consists of John Mair, Conrad Irwin and Ryan Fitzgerald and many more contributors. The last stable release was version 0.9.10 and it was released on July 15, 2012. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Read–eval–print_loop REPL]&amp;lt;/span&amp;gt; driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Rubinius Rubinius]&amp;lt;/span&amp;gt; core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/GitHub#Gist Gist]&amp;lt;/span&amp;gt; integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/IPython IPython]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Smalltalk Smalltalk]&amp;lt;/span&amp;gt; and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Usage and Example =&lt;br /&gt;
&lt;br /&gt;
=== Usage ===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
For example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Pry Commands =&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
::''Description'':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
::''Description'':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
::''Description'': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
::''Description'':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
::''Description'': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::''Description'': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
::''Description'': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
::''Description'': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
::''Description'': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
::''Description'': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
= Remote debugging =&lt;br /&gt;
&lt;br /&gt;
Remote debugging means you work on your local computer and you want to start and debug a program on another computer, the remote machine. Pry is a great tool for digging into your code and seeing what's going on with tons of great features. However, there are situations where using a standard binding.pry breakpoint will not block your program and allow you to inspect it.Pry-remote (along with its cousin pry-remote-em) enables you to start instances of Pry in a running program and connect to those instances over a network or the Internet. Once connected you can interact with the internal state of the program. This plugin comes into its own when used with tools such as Pow, enabling you to get a Pry session in places not normally possible. pry-remote is also notable for having pry-nav support.&lt;br /&gt;
&lt;br /&gt;
We set up the server as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'pry-remote'&lt;br /&gt;
&lt;br /&gt;
class Foo&lt;br /&gt;
  def initialize(x, y)&lt;br /&gt;
    binding.remote_pry&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Foo.new 10, 20&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Comparison with other popular debugging tools =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88636</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88636"/>
		<updated>2014-09-26T02:21:12Z</updated>

		<summary type="html">&lt;p&gt;Gshah: /* Remote debugging */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Debugging in Rails using Pry'''&amp;lt;/big&amp;gt;     &lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right|Pry REPL: a powerful IRB alternative and runtime developer console for Ruby.]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Web_application Web application]&amp;lt;/span&amp;gt; framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Model–view–controller model view controller]&amp;lt;/span&amp;gt;, like Mailers, Routes (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer REST]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol HTTP]&amp;lt;/span&amp;gt;-Verbs, Constraints), Environments and Initializers, Caching (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer Redis]&amp;lt;/span&amp;gt; &lt;br /&gt;
,&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Memcached Memcached]&amp;lt;/span&amp;gt;), Assets (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Sass_(stylesheet_language) SASS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript Javascript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/CoffeeScript CoffeeScript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Pipeline_(computing) Pipelining]&amp;lt;/span&amp;gt;), Bundler and dependency management, Tests (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/RSpec RSpec]&amp;lt;/span&amp;gt; , &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[https://github.com/jnicklas/capybara Capybara]&amp;lt;/span&amp;gt;&amp;lt;ref&amp;gt;https://github.com/jnicklas/capybara&amp;lt;/ref&amp;gt;), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debugging Debugging]&amp;lt;/span&amp;gt;  is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell IRB]&amp;lt;/span&amp;gt; shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Syntax_highlighting Syntax highlighting]&amp;lt;/span&amp;gt;, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration - and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Read–eval–print_loop REPL]&amp;lt;/span&amp;gt; driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Rubinius Rubinius]&amp;lt;/span&amp;gt; core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/GitHub#Gist Gist]&amp;lt;/span&amp;gt; integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/IPython IPython]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Smalltalk Smalltalk]&amp;lt;/span&amp;gt; and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Usage and Example =&lt;br /&gt;
&lt;br /&gt;
=== Usage ===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
For example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Pry Commands =&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
::''Description'':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
::''Description'':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
::''Description'': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
::''Description'':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
::''Description'': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::''Description'': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
::''Description'': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
::''Description'': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
::''Description'': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
::''Description'': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
= Remote debugging =&lt;br /&gt;
&lt;br /&gt;
Remote debugging means you work on your local computer and you want to start and debug a program on another computer, the remote machine. Pry is a great tool for digging into your code and seeing what's going on with tons of great features. However, there are situations where using a standard binding.pry breakpoint will not block your program and allow you to inspect it.Pry-remote (along with its cousin pry-remote-em) enables you to start instances of Pry in a running program and connect to those instances over a network or the Internet. Once connected you can interact with the internal state of the program. This plugin comes into its own when used with tools such as Pow, enabling you to get a Pry session in places not normally possible. pry-remote is also notable for having pry-nav support.&lt;br /&gt;
&lt;br /&gt;
We set up the server as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'pry-remote'&lt;br /&gt;
&lt;br /&gt;
class Foo&lt;br /&gt;
  def initialize(x, y)&lt;br /&gt;
    binding.remote_pry&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Foo.new 10, 20&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Comparison with other popular debugging tools =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88587</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88587"/>
		<updated>2014-09-26T01:10:58Z</updated>

		<summary type="html">&lt;p&gt;Gshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Debugging in Rails using Pry'''&amp;lt;/big&amp;gt;     &lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right|Pry REPL: a powerful IRB alternative and runtime developer console for Ruby.]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Web_application Web application]&amp;lt;/span&amp;gt; framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Model–view–controller model view controller]&amp;lt;/span&amp;gt;, like Mailers, Routes (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer REST]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol HTTP]&amp;lt;/span&amp;gt;-Verbs, Constraints), Environments and Initializers, Caching (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer Redis]&amp;lt;/span&amp;gt; &lt;br /&gt;
,&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Memcached Memcached]&amp;lt;/span&amp;gt;), Assets (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Sass_(stylesheet_language) SASS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript Javascript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/CoffeeScript CoffeeScript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Pipeline_(computing) Pipelining]&amp;lt;/span&amp;gt;), Bundler and dependency management, Tests (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/RSpec RSpec]&amp;lt;/span&amp;gt; , &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[https://github.com/jnicklas/capybara Capybara]&amp;lt;/span&amp;gt;&amp;lt;ref&amp;gt;https://github.com/jnicklas/capybara&amp;lt;/ref&amp;gt;), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debugging Debugging]&amp;lt;/span&amp;gt;  is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell IRB]&amp;lt;/span&amp;gt; shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Syntax_highlighting Syntax highlighting]&amp;lt;/span&amp;gt;, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration - and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Read–eval–print_loop REPL]&amp;lt;/span&amp;gt; driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Rubinius Rubinius]&amp;lt;/span&amp;gt; core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/GitHub#Gist Gist]&amp;lt;/span&amp;gt; integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/IPython IPython]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Smalltalk Smalltalk]&amp;lt;/span&amp;gt; and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Usage and Example =&lt;br /&gt;
&lt;br /&gt;
=== Usage ===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
For example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Pry Commands =&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
::''Description'':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
::''Description'':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
::''Description'': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
::''Description'':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
::''Description'': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::''Description'': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
::''Description'': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
::''Description'': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
::''Description'': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
::''Description'': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
= Remote debugging =&lt;br /&gt;
&lt;br /&gt;
= Comparison with other popular debugging tools =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88585</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88585"/>
		<updated>2014-09-26T01:07:33Z</updated>

		<summary type="html">&lt;p&gt;Gshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Debugging in Rails using Pry'''&amp;lt;/big&amp;gt;     &lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right|Pry REPL: a powerful IRB alternative and runtime developer console for Ruby.]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Web_application Web application]&amp;lt;/span&amp;gt; framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Model–view–controller model view controller]&amp;lt;/span&amp;gt;, like Mailers, Routes (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer REST]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol HTTP]&amp;lt;/span&amp;gt;-Verbs, Constraints), Environments and Initializers, Caching (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer Redis]&amp;lt;/span&amp;gt; &lt;br /&gt;
,&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Memcached Memcached]&amp;lt;/span&amp;gt;), Assets (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Sass_(stylesheet_language) SASS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript Javascript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/CoffeeScript CoffeeScript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Pipeline_(computing) Pipelining]&amp;lt;/span&amp;gt;), Bundler and dependency management, Tests (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/RSpec RSpec]&amp;lt;/span&amp;gt; , &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[https://github.com/jnicklas/capybara Capybara]&amp;lt;/span&amp;gt;), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debugging Debugging]&amp;lt;/span&amp;gt;  is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell IRB]&amp;lt;/span&amp;gt; shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Syntax_highlighting Syntax highlighting]&amp;lt;/span&amp;gt;, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration - and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Read–eval–print_loop REPL]&amp;lt;/span&amp;gt; driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Rubinius Rubinius]&amp;lt;/span&amp;gt; core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/GitHub#Gist Gist]&amp;lt;/span&amp;gt; integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/IPython IPython]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Smalltalk Smalltalk]&amp;lt;/span&amp;gt; and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Usage and Example =&lt;br /&gt;
&lt;br /&gt;
=== Usage ===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
For example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Pry Commands =&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
::''Description'':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
::''Description'':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
::''Description'': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
::''Description'':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
::''Description'': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::''Description'': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
::''Description'': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
::''Description'': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
::''Description'': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
::''Description'': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
= Remote debugging =&lt;br /&gt;
&lt;br /&gt;
= Comparison with other popular debugging tools =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
https://github.com/jnicklas/capybara&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88583</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88583"/>
		<updated>2014-09-26T01:03:50Z</updated>

		<summary type="html">&lt;p&gt;Gshah: /* Features */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Debugging in Rails using Pry'''&amp;lt;/big&amp;gt;     &lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right|Pry REPL: a powerful IRB alternative and runtime developer console for Ruby.]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Web_application Web application]&amp;lt;/span&amp;gt; framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Model–view–controller model view controller]&amp;lt;/span&amp;gt;, like Mailers, Routes (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer REST]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol HTTP]&amp;lt;/span&amp;gt;-Verbs, Constraints), Environments and Initializers, Caching (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer Redis]&amp;lt;/span&amp;gt; &lt;br /&gt;
, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Memcached Memcached]&amp;lt;/span&amp;gt;), Assets (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Sass_(stylesheet_language) SASS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript Javascript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/CoffeeScript CoffeeScript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Pipeline_(computing) Pipelining]&amp;lt;/span&amp;gt;), Bundler and dependency management, Tests (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/RSpec RSpec]&amp;lt;/span&amp;gt; , &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[https://github.com/jnicklas/capybara Capybara]&amp;lt;/span&amp;gt;), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debugging Debugging]&amp;lt;/span&amp;gt;  is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell IRB]&amp;lt;/span&amp;gt; shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Syntax_highlighting Syntax highlighting]&amp;lt;/span&amp;gt;, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration - and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Read–eval–print_loop REPL]&amp;lt;/span&amp;gt; driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Rubinius Rubinius]&amp;lt;/span&amp;gt; core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/GitHub#Gist Gist]&amp;lt;/span&amp;gt; integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/IPython IPython]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Smalltalk Smalltalk]&amp;lt;/span&amp;gt; and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Usage and Example =&lt;br /&gt;
&lt;br /&gt;
=== Usage ===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
For example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Pry Commands =&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
::''Description'':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
::''Description'':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
::''Description'': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
::''Description'':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
::''Description'': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::''Description'': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
::''Description'': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
::''Description'': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
::''Description'': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
::''Description'': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
= Remote debugging =&lt;br /&gt;
&lt;br /&gt;
= Comparison with other popular debugging tools =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88582</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88582"/>
		<updated>2014-09-26T01:01:22Z</updated>

		<summary type="html">&lt;p&gt;Gshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Debugging in Rails using Pry'''&amp;lt;/big&amp;gt;     &lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right|Pry REPL: a powerful IRB alternative and runtime developer console for Ruby.]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Web_application Web application]&amp;lt;/span&amp;gt; framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Model–view–controller model view controller]&amp;lt;/span&amp;gt;, like Mailers, Routes (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer REST]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol HTTP]&amp;lt;/span&amp;gt;-Verbs, Constraints), Environments and Initializers, Caching (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer Redis]&amp;lt;/span&amp;gt; &lt;br /&gt;
, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Memcached Memcached]&amp;lt;/span&amp;gt;), Assets (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Sass_(stylesheet_language) SASS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript Javascript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/CoffeeScript CoffeeScript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Pipeline_(computing) Pipelining]&amp;lt;/span&amp;gt;), Bundler and dependency management, Tests (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/RSpec RSpec]&amp;lt;/span&amp;gt; , &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[https://github.com/jnicklas/capybara Capybara]&amp;lt;/span&amp;gt;), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debugging Debugging]&amp;lt;/span&amp;gt;  is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell IRB]&amp;lt;/span&amp;gt; shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Syntax_highlighting Syntax highlighting]&amp;lt;/span&amp;gt;, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration - and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Read–eval–print_loop REPL]&amp;lt;/span&amp;gt; driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# Rubinius core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/GitHub#Gist Gist]&amp;lt;/span&amp;gt; integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/IPython IPython]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Smalltalk Smalltalk]&amp;lt;/span&amp;gt; and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Usage and Example =&lt;br /&gt;
&lt;br /&gt;
=== Usage ===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
For example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Pry Commands =&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
::''Description'':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
::''Description'':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
::''Description'': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
::''Description'':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
::''Description'': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::''Description'': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
::''Description'': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
::''Description'': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
::''Description'': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
::''Description'': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
= Remote debugging =&lt;br /&gt;
&lt;br /&gt;
= Comparison with other popular debugging tools =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88574</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88574"/>
		<updated>2014-09-26T00:50:46Z</updated>

		<summary type="html">&lt;p&gt;Gshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Debugging in Rails using Pry'''&amp;lt;/big&amp;gt;     &lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right|Pry REPL: a powerful IRB alternative and runtime developer console for Ruby.]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a Web application framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the model view controller, like Mailers, Routes (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer REST]&amp;lt;/span&amp;gt;, HTTP-Verbs, Constraints), Environments and Initializers, Caching (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Representational_state_transfer Redis]&amp;lt;/span&amp;gt; &lt;br /&gt;
, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Memcached Memcached]&amp;lt;/span&amp;gt;), Assets (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Sass_(stylesheet_language) SASS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript Javascript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/CoffeeScript CoffeeScript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Pipeline_(computing) Pipelining]&amp;lt;/span&amp;gt;), Bundler and dependency management, Tests (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/RSpec RSpec]&amp;lt;/span&amp;gt; , &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[https://github.com/jnicklas/capybara Capybara]&amp;lt;/span&amp;gt;), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debugging Debugging]&amp;lt;/span&amp;gt;  is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell IRB]&amp;lt;/span&amp;gt; shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Syntax_highlighting Syntax highlighting]&amp;lt;/span&amp;gt;, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration - and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring REPL driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# Rubinius core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# Gist integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by IPython, Smalltalk and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Usage and Example =&lt;br /&gt;
&lt;br /&gt;
=== Usage ===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
For example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Pry Commands =&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
::''Description'':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
::''Description'':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
::''Description'': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
::''Description'':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
::''Description'': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::''Description'': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
::''Description'': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
::''Description'': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
::''Description'': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
::''Description'': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
= Remote debugging =&lt;br /&gt;
&lt;br /&gt;
= Comparison with other popular debugging tools =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88562</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88562"/>
		<updated>2014-09-26T00:43:42Z</updated>

		<summary type="html">&lt;p&gt;Gshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Debugging in Rails using Pry'''&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right|Pry REPL: a powerful IRB alternative and runtime developer console for Ruby.]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a Web application framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the model view controller, like Mailers, Routes (REST, HTTP-Verbs, Constraints), Environments and Initializers, Caching (Redis, Memcached), Assets (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Cascading_Style_Sheets CSS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Sass_(stylesheet_language) SASS]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/JavaScript Javascript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/CoffeeScript CoffeeScript]&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Pipeline_(computing) Pipelining]&amp;lt;/span&amp;gt;), Bundler and dependency management, Tests (&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/RSpec RSpec]&amp;lt;/span&amp;gt; , &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[https://github.com/jnicklas/capybara Capybara]&amp;lt;/span&amp;gt;), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. Debugging is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard IRB shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features syntax highlighting, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration- and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring REPL driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# Rubinius core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# Gist integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by IPython, Smalltalk and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Usage and Example =&lt;br /&gt;
&lt;br /&gt;
=== Usage ===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
For example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Pry Commands =&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
::''Description'':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
::''Description'':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
::''Description'': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
::''Description'':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
::''Description'': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::''Description'': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
::''Description'': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
::''Description'': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
::''Description'': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
::''Description'': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
= Remote debugging =&lt;br /&gt;
&lt;br /&gt;
= Comparison with other popular debugging tools =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88549</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88549"/>
		<updated>2014-09-26T00:34:39Z</updated>

		<summary type="html">&lt;p&gt;Gshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Debugging in Rails using Pry'''&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right|Pry REPL: a powerful IRB alternative and runtime developer console for Ruby.]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a Web application framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the model view controller, like Mailers, Routes (REST, HTTP-Verbs, Constraints), Environments and Initializers, Caching (Redis, Memcached), Assets (CSS, SASS,, JavaScript, CoffeeScript, Pipelining), Bundler and dependency management, Tests (RSpec, Capybara), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. Debugging is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard IRB shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features syntax highlighting, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration- and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring REPL driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# Rubinius core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# Gist integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by IPython, Smalltalk and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Usage and Example =&lt;br /&gt;
&lt;br /&gt;
=== Usage ===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
For example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Pry Commands =&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
::''Description'':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
::''Description'':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
::''Description'': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
::''Description'':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
::''Description'': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::''Description'': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
::''Description'': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
::''Description'': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
::''Description'': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
::''Description'': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
= Remote debugging =&lt;br /&gt;
&lt;br /&gt;
= Comparison with other popular debugging tools =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88548</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88548"/>
		<updated>2014-09-26T00:34:12Z</updated>

		<summary type="html">&lt;p&gt;Gshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Debugging in Rails using Pry'''&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right|Pry REPL: a powerful IRB alternative and runtime developer console for Ruby.]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a Web application framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the model view controller, like Mailers, Routes (REST, HTTP-Verbs, Constraints), Environments and Initializers, Caching (Redis, Memcached), Assets (CSS, SASS,, JavaScript, CoffeeScript, Pipelining), Bundler and dependency management, Tests (RSpec, Capybara), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. Debugging is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard IRB shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features syntax highlighting, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration- and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring REPL driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# Rubinius core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# Gist integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by IPython, Smalltalk and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Usage and Example =&lt;br /&gt;
&lt;br /&gt;
=== Usage ===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
For example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Pry Commands =&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
::''Description'':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
::''Description'':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
::''Description'': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
::''Description'':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
::''Description'': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::''Description'': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
::''Description'': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
::''Description'': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
::''Description'': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
::''Description'': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
= Remote debugging =&lt;br /&gt;
&lt;br /&gt;
= Comparison with other popular debugging tools =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88546</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88546"/>
		<updated>2014-09-26T00:33:23Z</updated>

		<summary type="html">&lt;p&gt;Gshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Debugging in Rails using Pry'''&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right|Pry REPL: a powerful IRB alternative and runtime developer console for Ruby.]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a Web application framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the model view controller, like Mailers, Routes (REST, HTTP-Verbs, Constraints), Environments and Initializers, Caching (Redis, Memcached), Assets (CSS, SASS,, JavaScript, CoffeeScript, Pipelining), Bundler and dependency management, Tests (RSpec, Capybara), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. Debugging is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard IRB shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features syntax highlighting, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration- and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place.&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring REPL driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# Rubinius core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# Gist integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by IPython, Smalltalk and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Usage and Example =&lt;br /&gt;
&lt;br /&gt;
=== Usage ===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
For example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Pry Commands =&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
::''Description'':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
::''Description'':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
::''Description'': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
::''Description'':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
::''Description'': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::''Description'': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
::''Description'': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
::''Description'': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
::''Description'': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
::''Description'': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
= Remote debugging =&lt;br /&gt;
&lt;br /&gt;
= Comparison with other popular debugging tools =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88543</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88543"/>
		<updated>2014-09-26T00:31:50Z</updated>

		<summary type="html">&lt;p&gt;Gshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Debugging in Rails using Pry'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right|alt=Pry REPL: a powerful IRB alternative and runtime developer console for Ruby.]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a Web application framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the model view controller, like Mailers, Routes (REST, HTTP-Verbs, Constraints), Environments and Initializers, Caching (Redis, Memcached), Assets (CSS, SASS,, JavaScript, CoffeeScript, Pipelining), Bundler and dependency management, Tests (RSpec, Capybara), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. Debugging is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard IRB shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features syntax highlighting, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration- and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place.&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring REPL driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# Rubinius core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# Gist integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by IPython, Smalltalk and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Usage and Example =&lt;br /&gt;
&lt;br /&gt;
=== Usage ===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
For example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Pry Commands =&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
::''Description'':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
::''Description'':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
::''Description'': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
::''Description'':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
::''Description'': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::''Description'': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
::''Description'': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
::''Description'': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
::''Description'': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
::''Description'': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
= Remote debugging =&lt;br /&gt;
&lt;br /&gt;
= Comparison with other popular debugging tools =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88541</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88541"/>
		<updated>2014-09-26T00:30:37Z</updated>

		<summary type="html">&lt;p&gt;Gshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Debugging in Rails using Pry =&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right|alt=Pry REPL: a powerful IRB alternative and runtime developer console for Ruby.]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a Web application framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the model view controller, like Mailers, Routes (REST, HTTP-Verbs, Constraints), Environments and Initializers, Caching (Redis, Memcached), Assets (CSS, SASS,, JavaScript, CoffeeScript, Pipelining), Bundler and dependency management, Tests (RSpec, Capybara), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. Debugging is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard IRB shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features syntax highlighting, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration- and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place.&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring REPL driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# Rubinius core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# Gist integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by IPython, Smalltalk and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Usage and Example =&lt;br /&gt;
&lt;br /&gt;
=== Usage ===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
For example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Pry Commands =&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
::''Description'':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
::''Description'':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
::''Description'': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
::''Description'':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
::''Description'': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::''Description'': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
::''Description'': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
::''Description'': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
::''Description'': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
::''Description'': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
= Remote debugging =&lt;br /&gt;
&lt;br /&gt;
= Comparison with other popular debugging tools =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88540</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88540"/>
		<updated>2014-09-26T00:30:16Z</updated>

		<summary type="html">&lt;p&gt;Gshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Debugging in Rails using Pry&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right|alt=Pry REPL: a powerful IRB alternative and runtime developer console for Ruby.]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a Web application framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the model view controller, like Mailers, Routes (REST, HTTP-Verbs, Constraints), Environments and Initializers, Caching (Redis, Memcached), Assets (CSS, SASS,, JavaScript, CoffeeScript, Pipelining), Bundler and dependency management, Tests (RSpec, Capybara), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. Debugging is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard IRB shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features syntax highlighting, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration- and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place.&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring REPL driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features ====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# Rubinius core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# Gist integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by IPython, Smalltalk and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Usage and Example =&lt;br /&gt;
&lt;br /&gt;
=== Usage ===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
For example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Pry Commands =&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
::''Description'':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
::''Description'':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
::''Description'': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
::''Description'':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
::''Description'': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::''Description'': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
::''Description'': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
::''Description'': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
::''Description'': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
::''Description'': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
= Remote debugging =&lt;br /&gt;
&lt;br /&gt;
= Comparison with other popular debugging tools =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88527</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=88527"/>
		<updated>2014-09-26T00:15:45Z</updated>

		<summary type="html">&lt;p&gt;Gshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right|alt=Pry REPL: a powerful IRB alternative and runtime developer console for Ruby.]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a Web application framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the model view controller, like Mailers, Routes (REST, HTTP-Verbs, Constraints), Environments and Initializers, Caching (Redis, Memcached), Assets (CSS, SASS,, JavaScript, CoffeeScript, Pipelining), Bundler and dependency management, Tests (RSpec, Capybara), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. Debugging is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard IRB shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features syntax highlighting, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration- and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place.&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring REPL driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# Rubinius core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# Gist integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by IPython, Smalltalk and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation=&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Usage and Example=&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
For example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Pry Commands=&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
::''Description'':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
::''Description'':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
::''Description'': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
::''Description'':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
::''Description'': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::''Description'': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
::''Description'': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
::''Description'': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
::''Description'': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
::''Description'': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
=Remote debugging=&lt;br /&gt;
&lt;br /&gt;
=Comparison with other popular debugging tools=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=See also=&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=87833</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=87833"/>
		<updated>2014-09-20T04:07:30Z</updated>

		<summary type="html">&lt;p&gt;Gshah: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right|alt=Pry REPL: a powerful IRB alternative and runtime developer console for Ruby.]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a Web application framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the model view controller, like Mailers, Routes (REST, HTTP-Verbs, Constraints), Environments and Initializers, Caching (Redis, Memcached), Assets (CSS, SASS,, JavaScript, CoffeeScript, Pipelining), Bundler and dependency management, Tests (RSpec, Capybara), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. Debugging is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard IRB shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features syntax highlighting, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration- and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place.&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring REPL driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# Rubinius core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# Gist integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by IPython, Smalltalk and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation=&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Usage and Example=&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
For example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Pry Commands=&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
::''Description'':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
::''Description'':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
::''Description'': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
::''Description'':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
::''Description'': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::''Description'': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
::''Description'': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
::''Description'': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
::''Description'': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
::''Description'': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
=See also=&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=87832</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=87832"/>
		<updated>2014-09-20T04:06:12Z</updated>

		<summary type="html">&lt;p&gt;Gshah: /* Pry Commands */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right|alt=Pry REPL: a powerful IRB alternative and runtime developer console for Ruby.]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a Web application framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the model view controller, like Mailers, Routes (REST, HTTP-Verbs, Constraints), Environments and Initializers, Caching (Redis, Memcached), Assets (CSS, SASS,, JavaScript, CoffeeScript, Pipelining), Bundler and dependency management, Tests (RSpec, Capybara), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. Debugging is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard IRB shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features syntax highlighting, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration- and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place.&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring REPL driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# Rubinius core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# Gist integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by IPython, Smalltalk and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation=&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Usage and Example=&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
Fr example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Pry Commands=&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
::''Description'':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
::''Description'':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
::''Description'': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
::''Description'':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
::''Description'': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::''Description'': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
::''Description'': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
::''Description'': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
::''Description'': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
::''Description'': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
::''Description'': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
::''Description'': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
=See also=&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=87831</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=87831"/>
		<updated>2014-09-20T04:04:13Z</updated>

		<summary type="html">&lt;p&gt;Gshah: /* Pry Commands */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right|alt=Pry REPL: a powerful IRB alternative and runtime developer console for Ruby.]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a Web application framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the model view controller, like Mailers, Routes (REST, HTTP-Verbs, Constraints), Environments and Initializers, Caching (Redis, Memcached), Assets (CSS, SASS,, JavaScript, CoffeeScript, Pipelining), Bundler and dependency management, Tests (RSpec, Capybara), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. Debugging is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard IRB shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features syntax highlighting, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration- and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place.&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring REPL driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# Rubinius core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# Gist integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by IPython, Smalltalk and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation=&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Usage and Example=&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
Fr example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Pry Commands=&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
::''Description'': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
::''Description'':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
:'''Description''':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
:'''Description''':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:'''Description''': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
:'''Description''': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
:'''Description''': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
:'''Description''': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
:The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
=See also=&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=87821</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=87821"/>
		<updated>2014-09-20T03:51:28Z</updated>

		<summary type="html">&lt;p&gt;Gshah: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right|alt=Pry REPL: a powerful IRB alternative and runtime developer console for Ruby.]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a Web application framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the model view controller, like Mailers, Routes (REST, HTTP-Verbs, Constraints), Environments and Initializers, Caching (Redis, Memcached), Assets (CSS, SASS,, JavaScript, CoffeeScript, Pipelining), Bundler and dependency management, Tests (RSpec, Capybara), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. Debugging is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard IRB shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features syntax highlighting, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration- and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place.&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring REPL driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# Rubinius core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# Gist integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by IPython, Smalltalk and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation=&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Usage and Example=&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
Fr example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Pry Commands=&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
:'''Description''': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
:'''Description''':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
:'''Description''':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
:'''Description''':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:'''Description''': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
:'''Description''': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
:'''Description''': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
:'''Description''': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
:The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
=See also=&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=87820</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=87820"/>
		<updated>2014-09-20T03:50:47Z</updated>

		<summary type="html">&lt;p&gt;Gshah: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right|alt=Pry REPL: a powerful IRB alternative and runtime developer console for Ruby.| - A powerful IRB alternative and runtime developer console for Ruby.]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a Web application framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the model view controller, like Mailers, Routes (REST, HTTP-Verbs, Constraints), Environments and Initializers, Caching (Redis, Memcached), Assets (CSS, SASS,, JavaScript, CoffeeScript, Pipelining), Bundler and dependency management, Tests (RSpec, Capybara), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. Debugging is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard IRB shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features syntax highlighting, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration- and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place.&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring REPL driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# Rubinius core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# Gist integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by IPython, Smalltalk and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation=&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Usage and Example=&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
Fr example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Pry Commands=&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
:'''Description''': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
:'''Description''':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
:'''Description''':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
:'''Description''':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:'''Description''': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
:'''Description''': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
:'''Description''': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
:'''Description''': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
:The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
=See also=&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=87814</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=87814"/>
		<updated>2014-09-20T03:43:39Z</updated>

		<summary type="html">&lt;p&gt;Gshah: /* Pry Commands */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right|alt=Pry REPL: a powerful IRB alternative and runtime developer console for Ruby.|''[[Pry]]'' - A powerful IRB alternative and runtime developer console for Ruby.]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a Web application framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the model view controller, like Mailers, Routes (REST, HTTP-Verbs, Constraints), Environments and Initializers, Caching (Redis, Memcached), Assets (CSS, SASS,, JavaScript, CoffeeScript, Pipelining), Bundler and dependency management, Tests (RSpec, Capybara), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. Debugging is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard IRB shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features syntax highlighting, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration- and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place.&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring REPL driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# Rubinius core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# Gist integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by IPython, Smalltalk and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation=&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Usage and Example=&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
Fr example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Pry Commands=&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
:'''Description''': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:2. _          &lt;br /&gt;
&lt;br /&gt;
:'''Description''':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
:'''Description''':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
:'''Description''':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:'''Description''': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
:'''Description''': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
:'''Description''': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
:'''Description''': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
:The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
=See also=&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=87812</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=87812"/>
		<updated>2014-09-20T03:43:20Z</updated>

		<summary type="html">&lt;p&gt;Gshah: /* Pry Commands */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right|alt=Pry REPL: a powerful IRB alternative and runtime developer console for Ruby.|''[[Pry]]'' - A powerful IRB alternative and runtime developer console for Ruby.]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a Web application framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the model view controller, like Mailers, Routes (REST, HTTP-Verbs, Constraints), Environments and Initializers, Caching (Redis, Memcached), Assets (CSS, SASS,, JavaScript, CoffeeScript, Pipelining), Bundler and dependency management, Tests (RSpec, Capybara), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. Debugging is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard IRB shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features syntax highlighting, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration- and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place.&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring REPL driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# Rubinius core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# Gist integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by IPython, Smalltalk and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation=&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Usage and Example=&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
Fr example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Pry Commands=&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
:'''Description''': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
:#  _          &lt;br /&gt;
&lt;br /&gt;
:'''Description''':  Last output&lt;br /&gt;
&lt;br /&gt;
:3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
:'''Description''':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
:4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
:5. _file_   &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
:6. wtf?  &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
:7. $&lt;br /&gt;
&lt;br /&gt;
:'''Description''':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
:8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
:9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Search history&lt;br /&gt;
&lt;br /&gt;
:10. _out_ &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
:11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:'''Description''': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
:12. cd .. &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Take out of a level&lt;br /&gt;
&lt;br /&gt;
:13. binding.pry&lt;br /&gt;
&lt;br /&gt;
:'''Description''': Breakpoint&lt;br /&gt;
&lt;br /&gt;
:14. edit --ex&lt;br /&gt;
&lt;br /&gt;
:'''Description''': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
:15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
:16. whereami&lt;br /&gt;
&lt;br /&gt;
:'''Description''': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
:17. ;  &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
:18. play -l &lt;br /&gt;
&lt;br /&gt;
:'''Description''': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
:The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
=See also=&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=87807</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=87807"/>
		<updated>2014-09-20T03:41:53Z</updated>

		<summary type="html">&lt;p&gt;Gshah: /* Pry Commands */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right|alt=Pry REPL: a powerful IRB alternative and runtime developer console for Ruby.|''[[Pry]]'' - A powerful IRB alternative and runtime developer console for Ruby.]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a Web application framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the model view controller, like Mailers, Routes (REST, HTTP-Verbs, Constraints), Environments and Initializers, Caching (Redis, Memcached), Assets (CSS, SASS,, JavaScript, CoffeeScript, Pipelining), Bundler and dependency management, Tests (RSpec, Capybara), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. Debugging is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard IRB shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features syntax highlighting, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration- and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place.&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring REPL driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# Rubinius core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# Gist integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by IPython, Smalltalk and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation=&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Usage and Example=&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
Fr example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Pry Commands=&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
:1. ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
'''Description''': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
#  _          &lt;br /&gt;
&lt;br /&gt;
'''Description''':  Last output&lt;br /&gt;
&lt;br /&gt;
3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
'''Description''':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
'''Description''': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
5. _file_   &lt;br /&gt;
&lt;br /&gt;
'''Description''': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
6. wtf?  &lt;br /&gt;
&lt;br /&gt;
'''Description''': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
7. $&lt;br /&gt;
&lt;br /&gt;
'''Description''':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
'''Description''': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
'''Description''': Search history&lt;br /&gt;
&lt;br /&gt;
10. _out_ &lt;br /&gt;
&lt;br /&gt;
'''Description''': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Description''': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
12. cd .. &lt;br /&gt;
&lt;br /&gt;
'''Description''': Take out of a level&lt;br /&gt;
&lt;br /&gt;
13. binding.pry&lt;br /&gt;
&lt;br /&gt;
'''Description''': Breakpoint&lt;br /&gt;
&lt;br /&gt;
14. edit --ex&lt;br /&gt;
&lt;br /&gt;
'''Description''': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
'''Description''': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
16. whereami&lt;br /&gt;
&lt;br /&gt;
'''Description''': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
17. ;  &lt;br /&gt;
&lt;br /&gt;
'''Description''': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
18. play -l &lt;br /&gt;
&lt;br /&gt;
'''Description''': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
=See also=&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=87806</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 gn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_gn&amp;diff=87806"/>
		<updated>2014-09-20T03:41:17Z</updated>

		<summary type="html">&lt;p&gt;Gshah: /* Features */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
[[File:Pry REPL Logo.png|right|alt=Pry REPL: a powerful IRB alternative and runtime developer console for Ruby.|''[[Pry]]'' - A powerful IRB alternative and runtime developer console for Ruby.]]&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt; is a Web application framework for Ruby. It was first released to the public in July 2004. Within months, it was a widely used development environment. Many multinational corporations are using it to create Web applications. It is the standard Web-development framework for Ruby. Models are objects that represent the components of an application that perform information processing in the problem domain. Views are objects that display some aspect of the model. They are the output mechanism for the models. Controllers are objects that control how user actions are interpreted. They are the input mechanism for the views and models.&lt;br /&gt;
&lt;br /&gt;
Since a Rails application goes beyond the model view controller, like Mailers, Routes (REST, HTTP-Verbs, Constraints), Environments and Initializers, Caching (Redis, Memcached), Assets (CSS, SASS,, JavaScript, CoffeeScript, Pipelining), Bundler and dependency management, Tests (RSpec, Capybara), gems, plugins and engines used in the application, one needs to know a lot of stuff to master debugging their own application&amp;lt;ref&amp;gt;http://nofail.de/2013/10/debugging-rails-applications-in-development/&amp;lt;/ref&amp;gt;. Debugging is one of the things a developer has to do most and there exists debuggers for Rails that are suitable for browsers and lack the ability to allow moving around in the call-stack and inspecting objects at runtime. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://pryrepl.org Pry]&amp;lt;/span&amp;gt; in literal sense means to look or inquire closely, curiously, or impertinently. Pry is a powerful alternative to the standard IRB shell for Ruby. It not only for debugging but also (and mainly) for inspecting objects. It features syntax highlighting, a flexible plugin architecture, runtime invocation and source and documentation browsing. It enables the user to browse source code, inspect objects, eliminates all the iteration- and startup time when running red/green cycles and is especially useful when you don’t know exactly how something should function in the first place.&lt;br /&gt;
&lt;br /&gt;
==== Pry: super-fast, painless, debugging for the (ruby) masses. ====&lt;br /&gt;
Pry aims to be more than an IRB replacement; it is an attempt to bring REPL driven programming to the Ruby language. Pry is also fairly flexible and allows significant user customization making it a good choice for implementing custom shells. The pry console gives you access to the method that raised the exception, you can use it to inspect the values of variables (no more print statements!), the source code of methods (no more flapping around with a text editor!), and even move up and down the call stack (like a real debugger!).&lt;br /&gt;
&lt;br /&gt;
Because the shell opens as though the exception were just about to be raised, you don't even need to re-run your program from the beginning in order to start debugging. It's optimized for the &amp;quot;exceptions-happen&amp;quot; workflow that you need when developing code.&lt;br /&gt;
&lt;br /&gt;
==== Features====&lt;br /&gt;
&lt;br /&gt;
Pry is written from scratch to provide a number of advanced features, some of these include&amp;lt;ref&amp;gt;http://pryrepl.org&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://andywenk.tumblr.com/post/23821244145/rails-debugging-with-pry&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# Source code browsing (including core C source with the pry-doc gem)&lt;br /&gt;
# Navigation around state (cd, ls and friends)&lt;br /&gt;
# Rubinius core source browsing&lt;br /&gt;
# Documentation browsing&lt;br /&gt;
# Live help system&lt;br /&gt;
# Open methods in editors (edit-method Class#method)&lt;br /&gt;
# Syntax highlighting&lt;br /&gt;
# Command shell integration (start editors, run git, and rake from within Pry)&lt;br /&gt;
# Gist integration&lt;br /&gt;
# Runtime invocation (use Pry as a developer console or debugger)&lt;br /&gt;
# Exotic object support (BasicObject instances, IClasses, ...)&lt;br /&gt;
# A powerful and flexible command system&lt;br /&gt;
# Ability to view and replay history&lt;br /&gt;
# Many convenience commands inspired by IPython, Smalltalk and other advanced REPLs&lt;br /&gt;
&lt;br /&gt;
= Installation=&lt;br /&gt;
&lt;br /&gt;
The steps you have to do are simple&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install pry&lt;br /&gt;
$ pry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could install pry on Rails by adding the pry-rails gem to your gem file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
group :development do&lt;br /&gt;
   gem 'pry'&lt;br /&gt;
   ...&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have got that settled, change back into the sample_app directory and install all the necessary dependencies:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting up the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:schema:load&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that some of you might need to prefix the above command with bundle exec.&lt;br /&gt;
&lt;br /&gt;
One final thing before we proceed to the actual stuff: Create .pryrc in your home directory and fill it in with the editor of your choice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% touch ~/.pryrc&lt;br /&gt;
Pry.config.editor = 'vim'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To launch pry through the terminal you simply write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and you’re greeted with a pry console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
% rails c&lt;br /&gt;
Loading development environment (Rails 3.2.16)&lt;br /&gt;
Frame number: 0/3&lt;br /&gt;
[1] sample_app »&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Usage and Example=&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
After you install Pry using the above mentioned install command,  you run your program using '''rescue foo.rb''' instead of '''ruby foo.rb'''. If not, just wrap chunks of your program in Pry::rescue{ }. Any exceptions that are unhandled within that block will be rescued by pry on your behalf. &lt;br /&gt;
&lt;br /&gt;
Whenever pry opens because of an exception you have two choices:&lt;br /&gt;
# Hit '''ctrl-d''' to let the exception bubble on its way&lt;br /&gt;
# Do some debugging. &lt;br /&gt;
&lt;br /&gt;
If you choose the second option, then you can use the full power of pry to fix the problem; and then try-again to verify the fix worked.&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
Fr example, lets assume the following piece of code&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def find_capitalized(a)&lt;br /&gt;
   a.select do |name|&lt;br /&gt;
     name.chars.first == name.chars.first.upcase&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if you run '''rescue foo.rb''',  you would get a output which would look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
    3:   a.select do |name|&lt;br /&gt;
 =&amp;gt; 4:     name.chars.first == name.chars.first.upcase&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
NoMethodError: undefined method `chars' for :direction:Symbol&lt;br /&gt;
from rescue.rb:4:in `block in find_capitalized'&lt;br /&gt;
[1] pry(main)&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well, clearly it's gone wrong. Let's move up the stack and see if we can find which code is calling this method with symbols:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[1] pry(main)&amp;gt; up&lt;br /&gt;
From: rescue.rb @ line 8 Object#extract_people:&lt;br /&gt;
&lt;br /&gt;
     8: def extract_people(opts)&lt;br /&gt;
 =&amp;gt;  9:   name_keys = find_capitalized(opts.keys)&lt;br /&gt;
    10: &lt;br /&gt;
    11:   name_keys.each_with_object({}) do |name, o|&lt;br /&gt;
    12:     o[name] = opts.delete name&lt;br /&gt;
    13:   end&lt;br /&gt;
    14: end&lt;br /&gt;
&lt;br /&gt;
[2] pry(main)&amp;gt; opts&lt;br /&gt;
=&amp;gt; {&amp;quot;Arthur&amp;quot;=&amp;gt;&amp;quot;Dent&amp;quot;, :direction=&amp;gt;:left}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's see if there's a better way of implementing find_capitalized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[3] pry(main)&amp;gt; down&lt;br /&gt;
[4] pry(main)&amp;gt; name.first&lt;br /&gt;
NoMethodError: undefined method `first' for :direction&lt;br /&gt;
from (pry):9:in `block in find_capitalized'&lt;br /&gt;
[5] pry(main)&amp;gt; name.capitalize&lt;br /&gt;
=&amp;gt; :Direction&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let's edit-method to fix the code, and try-again to verify the fix worked:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[6] pry(main)&amp;gt; edit-method&lt;br /&gt;
[7] pry(main)&amp;gt; whereami&lt;br /&gt;
From: rescue.rb @ line 2 Object#find_capitalized:&lt;br /&gt;
&lt;br /&gt;
    2: def find_capitalized(a)&lt;br /&gt;
 =&amp;gt; 3:   a.select do |name|&lt;br /&gt;
    4:     name.capitalize == name&lt;br /&gt;
    5:   end&lt;br /&gt;
    6: end&lt;br /&gt;
&lt;br /&gt;
[8] pry(main)&amp;gt; try-again&lt;br /&gt;
Arthur Dent moves left&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Pry Commands=&lt;br /&gt;
&lt;br /&gt;
There are a myriad of pry commands that are useful while debugging. Follwing is the list of some important list of commands that can be used while debugging using Pry&amp;lt;ref&amp;gt;http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://cirw.in/blog/pry-to-the-rescue&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://www.sitepoint.com/pry-friends-rails&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;https://github.com/ConradIrwin/pry-rescue&amp;lt;/ref&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
# ls &amp;lt;Object&amp;gt; &lt;br /&gt;
&lt;br /&gt;
'''Description''': It show all of the available methods that can be called by an object&lt;br /&gt;
&lt;br /&gt;
#  _          &lt;br /&gt;
&lt;br /&gt;
'''Description''':  Last output&lt;br /&gt;
&lt;br /&gt;
3. ? &amp;lt;Object&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
'''Description''':   Shows more information (doc) about an object, or method&lt;br /&gt;
&lt;br /&gt;
4. cat &amp;lt;File&amp;gt; &lt;br /&gt;
&lt;br /&gt;
'''Description''': Display the content of a file&lt;br /&gt;
&lt;br /&gt;
5. _file_   &lt;br /&gt;
&lt;br /&gt;
'''Description''': Represent the last file Pry touched&lt;br /&gt;
&lt;br /&gt;
6. wtf?  &lt;br /&gt;
&lt;br /&gt;
'''Description''': Print the stack trace, same as _ex_.backtrace&lt;br /&gt;
&lt;br /&gt;
7. $&lt;br /&gt;
&lt;br /&gt;
'''Description''':  Show source, shortcut for show-source&lt;br /&gt;
&lt;br /&gt;
8. edit &amp;lt;Method&amp;gt; &lt;br /&gt;
&lt;br /&gt;
'''Description''': Open file in $EDITOR, change file are auto reloaded&lt;br /&gt;
&lt;br /&gt;
9. &amp;lt;ctrl+r&amp;gt; &lt;br /&gt;
&lt;br /&gt;
'''Description''': Search history&lt;br /&gt;
&lt;br /&gt;
10. _out_ &lt;br /&gt;
&lt;br /&gt;
'''Description''': Array of all outputs values, also _in_&lt;br /&gt;
&lt;br /&gt;
11. cd &amp;lt;var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Description''': Step into an object, change the value of self&lt;br /&gt;
&lt;br /&gt;
12. cd .. &lt;br /&gt;
&lt;br /&gt;
'''Description''': Take out of a level&lt;br /&gt;
&lt;br /&gt;
13. binding.pry&lt;br /&gt;
&lt;br /&gt;
'''Description''': Breakpoint&lt;br /&gt;
&lt;br /&gt;
14. edit --ex&lt;br /&gt;
&lt;br /&gt;
'''Description''': Edit the file where the last exception was thrown&lt;br /&gt;
&lt;br /&gt;
15. .&amp;lt;Shell&amp;gt; &lt;br /&gt;
&lt;br /&gt;
'''Description''': Runs the &amp;lt;Shell&amp;gt; command&lt;br /&gt;
&lt;br /&gt;
16. whereami&lt;br /&gt;
&lt;br /&gt;
'''Description''': Print the context where the debugger is stopped&lt;br /&gt;
&lt;br /&gt;
17. ;  &lt;br /&gt;
&lt;br /&gt;
'''Description''': Would mute the return output by Ruby&lt;br /&gt;
&lt;br /&gt;
18. play -l &lt;br /&gt;
&lt;br /&gt;
'''Description''': Execute the line in the current debugging context&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just type help once you've installed pry.&lt;br /&gt;
&lt;br /&gt;
=See also=&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Debug_code#Print_debugging Debug code]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://object.io/site/2011/getting-to-know-ruby-debugger/ Ruby debugger]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Interactive_Ruby_Shell Interactive Ruby Shell]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[http://guides.rubyonrails.org/debugging_rails_applications.html Debugging Rails application tutorials]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gshah</name></author>
	</entry>
</feed>