<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -3,7 +3,7 @@ Feature: Extract Method
   As a developer
   I want to extract methods
 
-  Scenario: Simple code, no variables
+  Scenario: Simple code, no variables, one method
     Given I have the following code:
       &quot;&quot;&quot;
         def the_method(firstArg, secondArg)
@@ -28,5 +28,42 @@ Feature: Extract Method
           puts /to be/
           puts 'refactored'
         end
+      
+      &quot;&quot;&quot;
+
+  Scenario: Simple code, no variables, many methods
+    Given I have the following code:
+      &quot;&quot;&quot;
+        def the_method(firstArg, secondArg)
+          puts :code
+          puts /to be/
+          puts 'refactored'
+        end
 
+        def more()
+          n = 3+2/7
+          puts &quot;other #{n}&quot;
+          n
+        end
+      &quot;&quot;&quot;
+    And lines from 3 to 4 are selected
+    And I want them to be in the method called 'new_method'
+    When I call 'extract method'
+    Then the code should be:
+      &quot;&quot;&quot;
+        def the_method(firstArg, secondArg)
+          puts :code
+          new_method()
+        end
+
+        def new_method()
+          puts /to be/
+          puts 'refactored'
+        end
+
+        def more()
+          n = 3+2/7
+          puts &quot;other #{n}&quot;
+          n
+        end
       &quot;&quot;&quot;</diff>
      <filename>features/extract_method.feature</filename>
    </modified>
    <modified>
      <diff>@@ -5,7 +5,7 @@ module Rfactor
     def initialize(code)
       @code = code
       @ast = RubyParser.new.parse(code)
-      @line_finder = LineFinder.new(@ast, code.last_line)
+      @line_finder = LineFinder.new(@ast)
     end
     
     def extract_method(args)
@@ -23,7 +23,7 @@ module Rfactor
         line_number = n + 1 # not 0-based
         if line_number == method_lines.first
           identation = extract_identation_level_from line
-          extracted_method &lt;&lt; &quot;\n\n#{identation}&quot;
+          extracted_method &lt;&lt; &quot;\n#{identation}&quot;
           extracted_method &lt;&lt; &quot;def #{args[:name]}()\n&quot;
         end
         if selected_lines.include? line_number
@@ -31,12 +31,13 @@ module Rfactor
           extracted_method &lt;&lt; line
         elsif line_number &gt; method_lines.last &amp;&amp; !added
           added = true
-          new_code &lt;&lt; extracted_method &lt;&lt; &quot;end\n&quot;
+          new_code &lt;&lt; extracted_method &lt;&lt; &quot;#{identation}end\n&quot;
+          new_code &lt;&lt; line
         else
           new_code &lt;&lt; line
         end
       end
-      new_code &lt;&lt; extracted_method &lt;&lt; &quot;#{identation}end\n&quot; unless added
+      new_code &lt;&lt; &quot;\n#{extracted_method}#{identation}end\n&quot; unless added
       new_code
     end
     </diff>
      <filename>lib/rfactor/code.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,15 +2,14 @@ module Rfactor
 
   class LineFinder
     
-    def initialize(ast, last_line)
+    def initialize(ast)
       @ast = ast
-      @last_line = last_line
     end
     
     def method_lines(line_in_code)
       processor = MethodLineFinderProcessor.new(line_in_code)
       processor.process(@ast)
-      Range.new(processor.method_line, processor.last_method_line || @last_line, true)
+      Range.new(processor.method_line, processor.last_method_line)
     end
   end
   
@@ -27,18 +26,14 @@ module Rfactor
       @last_method_line = 0
     end
     
-    def process_defn(exp, next_exp)
+    def process_defn(exp)
       current = exp.line
       if current &gt; @method_line &amp;&amp; current &lt; @line
         @method_line = current
-        @last_method_line = next_exp.line if next_exp
+        @last_method_line = exp.endline
       end
       exp
-    end
-    
-    def last_method_line
-      @last_method_line if @last_method_line &gt; @method_line
-    end
+    end    
   end
 
 end</diff>
      <filename>lib/rfactor/line_finder.rb</filename>
    </modified>
    <modified>
      <diff>@@ -18,19 +18,19 @@ describe Rfactor::LineFinder do
   
   before(:each) do
     @ast = RubyParser.new.parse(CODE)
-    @finder = Rfactor::LineFinder.new(@ast, CODE.last_line)
+    @finder = Rfactor::LineFinder.new(@ast)
   end
   
   it &quot;should find method start line&quot; do
     @finder.method_lines(3).first.should == 2
   end
   
-  it &quot;should use next method line as last line&quot; do
-    @finder.method_lines(3).last.should == 8
+  it &quot;should find method end line&quot; do
+    @finder.method_lines(3).last.should == 6
   end
   
-  it &quot;should use file last line if position is last method method&quot; do
-    @finder.method_lines(9).last.should == 11
+  it &quot;it should find method end line even if the method is the last&quot; do
+    @finder.method_lines(9).last.should == 10
   end
   
 end
\ No newline at end of file</diff>
      <filename>spec/line_finder_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>940a7b92e2e49c0a1972448653019df625c16183</id>
    </parent>
  </parents>
  <author>
    <name>Fabio Kung</name>
    <email>fabio.kung@gmail.com</email>
  </author>
  <url>http://github.com/fabiokung/rfactor/commit/f37189daf12f58fd86c9564df275edc9ed09d370</url>
  <id>f37189daf12f58fd86c9564df275edc9ed09d370</id>
  <committed-date>2009-02-04T02:04:19-08:00</committed-date>
  <authored-date>2009-02-04T02:04:19-08:00</authored-date>
  <message>getting method end lines from modified Ruby Parser AST</message>
  <tree>6fb3de52f7d132f0291da5387d1f997781ba17d7</tree>
  <committer>
    <name>Fabio Kung</name>
    <email>fabio.kung@gmail.com</email>
  </committer>
</commit>
