<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom">
  <title>The Pragmatic Studio</title>
  <subtitle>Top developer training from the folks who wrote the books</subtitle>
  <author>
    <name>The Pragmatic Studio Crew</name>
  </author>
  <link rel="alternate" type="text/html" href="http://pragmaticstudio.com/blog" />
  
  <id>http://pragmaticstudio.com/blog</id>
  <updated>2013-04-24T15:31:20Z</updated>
  <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/PragmaticStudio" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="pragmaticstudio" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry>
    <title>Online Rails Course Now Available</title>
    <author>
      <name>Nicole Clark</name>
    </author>
    <link rel="alternate" type="text/html" href="http://pragmaticstudio.com/blog/2013/4/24/online-rails-course" />
    <id>http://pragmaticstudio.com/blog/2013/4/24/online-rails-course</id>
    <published>2013-04-24T15:31:20Z</published>
    <updated>2013-04-24T15:31:20Z</updated>
    <content type="html">&lt;p&gt;As a follow-up to our popular &lt;a href="http://pragmaticstudio.com/ruby"&gt;online Ruby course&lt;/a&gt;, today we're happy to announce the release of our &lt;a href="http://pragmaticstudio.com/rails"&gt;online Rails course&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;In this comprehensive online course you'll learn how to &lt;strong&gt;build a complete Rails 4 app step-by-step, from idea to deployment&lt;/strong&gt;. To see what the
course is all about, check out the introduction video:&lt;/p&gt;

&lt;div class="video"&gt;
&lt;iframe src="http://player.vimeo.com/video/64350363?title=0&amp;amp;byline=0&amp;amp;portrait=0&amp;amp;color=c8c8c8" width="640" height="360" frameborder="0" webkitAllowFullScreen mozallowfullscreen 
allowFullScreen&gt;&lt;/iframe&gt;
&lt;/div&gt;


&lt;p&gt;You'll learn the fundamentals every Rails developer should know, and how
to put all the pieces together, so you can confidently create your first Rails app
or jump right into an existing app. Throughout the course you'll also learn
key design principles and practices to help you craft robust and flexible
Rails apps.&lt;/p&gt;

&lt;h3&gt;What's Included&lt;/h3&gt;


&lt;p&gt;Here are a few of the things you’ll get:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;36 HD-quality videos&lt;/strong&gt; with personal instruction, live coding, and over 70 animated visuals. Watch the videos in your browser for an integrated learning experience, or download them for offline viewing.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A &lt;strong&gt;comprehensive online workbook&lt;/strong&gt; with hands-on exercises
so you can immediately apply what you learned in the videos. You'll end up incrementally building a complete Rails app from scratch on your own computer&amp;mdash;the same familiar environment where you'll craft your own Rails apps.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Example code and solutions&lt;/strong&gt; for two full-featured Rails apps, as well as &lt;strong&gt;cheat sheets&lt;/strong&gt; for commonly used conventions, commands, and shortcuts.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Access to a &lt;strong&gt;mailing list&lt;/strong&gt; exclusively for participants of this course. If you have any questions or problems at any point during the course, we're happy to help!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Unlimited access&lt;/strong&gt; to all the course material so you can rewatch the videos, redo the exercises, and revisit the course as often as you like!&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;Discounts&lt;/h3&gt;


&lt;p&gt;Already a Pragmatic Studio alumni? You'll automatically get a 25% discount
on the course by logging in to your
&lt;a href="http://pragmaticstudio.com/my_account"&gt;alumni account&lt;/a&gt; before purchasing the course.&lt;/p&gt;

&lt;p&gt;Have a team of 5 or more who need to get up to speed on Rails? &lt;a
href="mailto:info@pragmaticstudio.com"&gt;Drop us a line&lt;/a&gt; about discounted
team licenses.&lt;/p&gt;

&lt;p&gt;If you want to get started on the right foot with Rails and be on the fast track to building your own app, this is the course for you! &lt;a href="http://pragmaticstudio.com/rails"&gt;Start learning Rails today&lt;/a&gt; and work through the course when and where it's convenient for you.&lt;/p&gt;

&lt;p&gt;Thanks for your continued support, and we hope you enjoy the course!&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Filming the Online Rails Course</title>
    <author>
      <name>Nicole Clark</name>
    </author>
    <link rel="alternate" type="text/html" href="http://pragmaticstudio.com/blog/2013/4/16/filming-online-rails-course" />
    <id>http://pragmaticstudio.com/blog/2013/4/16/filming-online-rails-course</id>
    <published>2013-04-16T17:38:06Z</published>
    <updated>2013-04-16T17:38:06Z</updated>
    <content type="html">&lt;p&gt;We just finished filming our online Rails course based on Rails 4! By popular demand, the format is the same as our &lt;a href="http://pragmaticstudio.com/ruby"&gt;online Ruby course&lt;/a&gt;. It's like having your own personal Studio. Look for it by end of the month or &lt;a href="http://pragmaticstudio.com/notify"&gt;sign up to be notified&lt;/a&gt; when it's ready!&lt;/p&gt;

&lt;div style="text-align: center; padding:10px 0;"&gt;
&lt;img src="http://pragmaticstudio.com/images/blog/filming-online-rails.png"&gt;
&lt;/div&gt;

</content>
  </entry>
  <entry>
    <title>"View Source" On Ruby Methods </title>
    <author>
      <name>Mike Clark</name>
    </author>
    <link rel="alternate" type="text/html" href="http://pragmaticstudio.com/blog/2013/2/13/view-source-ruby-methods" />
    <id>http://pragmaticstudio.com/blog/2013/2/13/view-source-ruby-methods</id>
    <published>2013-02-13T21:14:18Z</published>
    <updated>2013-02-13T21:14:18Z</updated>
    <content type="html">&lt;p&gt;I've been spending a fair amount of time digging around the Rails source as of late, particularly to stay up to date with changes in Rails 4. For example, earlier today I was curious how the new &lt;tt&gt;update&lt;/tt&gt; method was implemented as compared to its &lt;tt&gt;update_attributes&lt;/tt&gt; predecessor. I find going directly to the source is the best way to answer these types of questions.&lt;/p&gt;

&lt;p&gt;Tracking down the definition of the &lt;tt&gt;update&lt;/tt&gt; method seems easy enough. Given that we have all the Rails source files, we can just run a quick search for occurrences of &lt;tt&gt;def update&lt;/tt&gt;. Trouble is, with that broad of a search you end up sifting through around 50 matches across 37 files. But of course we're only interested in the &lt;tt&gt;update&lt;/tt&gt; method of an ActiveRecord model. Ideally we could go directly to the source of that method. Thankfully, Ruby 1.9 lets us do exactly that.&lt;/p&gt;

&lt;p&gt;Suppose we have a &lt;tt&gt;Person&lt;/tt&gt; ActiveRecord model and in the Rails console we've created a new object like so:&lt;/p&gt;

&lt;pre lang="ruby"&gt;
&gt;&gt; person = Person.new
&lt;/pre&gt;


&lt;p&gt;In Rails 4, we can call the &lt;tt&gt;update&lt;/tt&gt; method on the &lt;tt&gt;person&lt;/tt&gt; object to update that object's attributes and save it to the database:&lt;/p&gt;

&lt;pre lang="ruby"&gt;
&gt;&gt; person.update(name: "Fred")
&lt;/pre&gt;


&lt;p&gt;We're interested in how that &lt;tt&gt;update&lt;/tt&gt; method is implemented. The first step is to get ahold of the method itself. We do that by calling the
&lt;tt&gt;method&lt;/tt&gt; method on the &lt;tt&gt;person&lt;/tt&gt; object, passing in the name of the method we want:&lt;/p&gt;

&lt;pre lang="ruby"&gt;
&gt;&gt; method = person.method(:update)
=&gt; #&lt;Method: Person(ActiveRecord::Persistence)#update&gt;
&lt;/pre&gt;


&lt;p&gt;Notice that this returns a &lt;tt&gt;Method&lt;/tt&gt; object that represents the
&lt;tt&gt;update&lt;/tt&gt; method. Methods aren't natively represented as objects in Ruby, but you can &lt;em&gt;objectify&lt;/em&gt; a method using this technique.&lt;/p&gt;

&lt;p&gt;Here's the cool part: Given a method object, we can ask it for its source location:&lt;/p&gt;

&lt;pre lang="ruby"&gt;
&gt;&gt; location = method.source_location
=&gt; ["/Users/mike/.rvm/gems/ruby-1.9.3-p385@rails4/bundler/gems/rails-5d58948fe72e/activerecord/lib/active_record/persistence.rb", 
     215]
&lt;/pre&gt;


&lt;p&gt;The &lt;tt&gt;source_location&lt;/tt&gt; method returns an array with two elements: the name of the source file that defines the method and the line number where it's defined. Pretty cool indeed!&lt;/p&gt;

&lt;p&gt;It sure would be convenient if we could automatically open that file in our favorite editor and position the cursor on the exact line where the method is defined. Indeed, we can! With SublimeText, for example, you just call the &lt;tt&gt;subl&lt;/tt&gt; command and separate the file name and the line number with a colon. So from inside of the Rails console, we can launch SublimeText and go directly to the &lt;tt&gt;update&lt;/tt&gt; method using:&lt;/p&gt;

&lt;pre lang="ruby"&gt;
&gt;&gt; `subl #{location[0]}:#{location[1]}`
&lt;/pre&gt;


&lt;p&gt;If you happen to be a TextMate user, you use the &lt;tt&gt;-l&lt;/tt&gt; option to pass in the line number:&lt;/p&gt;

&lt;pre lang="ruby"&gt;
&gt;&gt; `mate #{location[0]} -l #{location[1]}`
&lt;/pre&gt;


&lt;p&gt;And for the die-hard MacVim users:&lt;/p&gt;

&lt;pre lang="ruby"&gt;
&gt;&gt; `mvim #{location[0]} +#{location[1]}`
&lt;/pre&gt;


&lt;p&gt;Taking that a step further, we can bottle up these steps in a method so it's easy to hop straight into the source of any method. Just toss this method into your &lt;tt&gt;.irbrc&lt;/tt&gt; file:&lt;/p&gt;

&lt;pre lang="ruby"&gt;
def source_for(object, method)
  location = object.method(method).source_location
  `subl #{location[0]}:#{location[1]}` if location
  location
end
&lt;/pre&gt;


&lt;p&gt;Then from your Rails console you can use:&lt;/p&gt;

&lt;pre lang="ruby"&gt;
&gt;&gt; source_for(Person.new, :update)
&lt;/pre&gt;


&lt;p&gt;The &lt;tt&gt;Person&lt;/tt&gt; class also defines an &lt;tt&gt;update&lt;/tt&gt; &lt;em&gt;class&lt;/em&gt; method, and to see the source for it you'd use:&lt;/p&gt;

&lt;pre lang="ruby"&gt;
&gt;&gt; source_for(Person, :update)
&lt;/pre&gt;


&lt;p&gt;Taking it a step further, you can make the &lt;tt&gt;source_for&lt;/tt&gt; method a bit more flexible. For example, suppose we wanted to look up the source for instance methods defined in Ruby modules, such as a Rails helper. We'd like to be able to use this&lt;/p&gt;

&lt;pre lang="ruby"&gt;
&gt;&gt; source_for(ApplicationHelper, :some_helper)
&lt;/pre&gt;


&lt;p&gt;But that won't work because the &lt;tt&gt;some_helper&lt;/tt&gt; method isn't defined on the &lt;tt&gt;ApplicationHelper&lt;/tt&gt; module. It's an instance method, not a class method. And modules can't be instantiated, so we can't pass in &lt;tt&gt;ApplicationHelper.new&lt;/tt&gt;.&lt;/p&gt;

&lt;p&gt;Based on &lt;a href="https://gist.github.com/jimweirich/4950443"&gt;Jim Weirich's suggestion&lt;/a&gt;, here's a slightly more involved version of the &lt;tt&gt;source_for&lt;/tt&gt; method that handles both cases:&lt;/p&gt;

&lt;pre lang="ruby"&gt;
def source_for(object, method_sym)
  if object.respond_to?(method_sym, true)
    method = object.method(method_sym)
  elsif object.is_a?(Module)
    method = object.instance_method(method_sym)
  end
  location = method.source_location
  `subl #{location[0]}:#{location[1]}` if location
  location
rescue
  nil
end
&lt;/pre&gt;


&lt;p&gt;First it checks if the method is defined on the object. If so, we go ahead and call the &lt;tt&gt;method&lt;/tt&gt; method to get ahold of the method just like before. Otherwise, we check to see if the object is a module. In that case, we then use the &lt;tt&gt;instance_method&lt;/tt&gt; method to get ahold of the instance method defined on that module. Problem solved!&lt;/p&gt;

&lt;p&gt;Supporting modules has an interesting side effect. Suppose we want to look up a method on an object that requires a bunch of initialization parameters. In the original version of the &lt;tt&gt;source_for&lt;/tt&gt; method, we'd need to call &lt;tt&gt;source_for&lt;/tt&gt; something like this&lt;/p&gt;

&lt;pre lang="ruby"&gt;
&gt;&gt; source_for(MotherOfAllClasses.new(a, b, c, d), :some_method)
&lt;/pre&gt;


&lt;p&gt;It's inconvenient to have to supply all those initialization parameters just to get an object for the sake of finding the intended method. But given the revised &lt;tt&gt;source_for&lt;/tt&gt; we can instead use&lt;/p&gt;

&lt;pre lang="ruby"&gt;
&gt;&gt; source_for(MotherOfAllClasses, :some_method)
&lt;/pre&gt;


&lt;p&gt;This works simply because classes in Ruby are also modules. Let's trace through the &lt;tt&gt;source_for&lt;/tt&gt; method for this case. First, we check whether
&lt;tt&gt;MotherOfAllClasses&lt;/tt&gt; responds to the &lt;tt&gt;some_method&lt;/tt&gt; method. It doesn't because &lt;tt&gt;some_method&lt;/tt&gt; is an &lt;em&gt;instance&lt;/em&gt; method, not a &lt;em&gt;class&lt;/em&gt; method. So then we check if &lt;tt&gt;MotherOfAllClasses&lt;/tt&gt; is a module, which it is because all classes in Ruby are also modules. That being the case, the &lt;tt&gt;instance_method&lt;/tt&gt; method returns the &lt;tt&gt;some_method&lt;/tt&gt; method we're interested in.&lt;/p&gt;

&lt;p&gt;We've been using &lt;tt&gt;source_for&lt;/tt&gt; from within the Rails console, but you can use this method from within any &lt;tt&gt;irb&lt;/tt&gt; session to view the source for methods in any gems, external libraries, or even your own code!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Thanks to &lt;a href="http://twitter.com/jimweirich"&gt;Jim Weirich&lt;/a&gt; and
&lt;a href="http://twitter.com/erniemiller"&gt;Ernie Miller&lt;/a&gt; for their suggestions!&lt;/em&gt;&lt;/p&gt;
</content>
  </entry>
</feed>
