Bugs: Browse | Submit New | Admin

[#2507] rrb-extract-method fails to extract to a class method

Date:
2005-09-23 14:22
Priority:
3
Submitted By:
Pat Eyler (pate)
Assigned To:
Nobody (None)
Category:
None
State:
Open
Summary:
rrb-extract-method fails to extract to a class method

Detailed description
Given the example code:

#!/usr/bin/env ruby

class MyClass

  def MyClass.my_long_method
    # pretend that this method is too long
    @foo = "foo"
    @bar = "bar"

    #this is what I want to extract into MyClass.swap_vars
    @foo, @bar = @bar, @foo
  end

end


Using the emacs interface, if I try to extract the line '@foo, @bar = @bar, @foo' into a class method called
MyClass.swap_vars, the operation fails with the message:

fail to refactor:  MyClass.swap_varsw is not a valid name for methods

Add A Comment: Notepad

Please login


Followup

Message
Date: 2005-09-24 13:45
Sender: Ippei Ohbayashi

You can extract that if you specify new method
as "swap_vars" , not "MyClass.swap_vars".
Date: 2005-09-24 05:45
Sender: Pat Eyler

looks like it's a problem with lib/rrb/scriptfiles.rb.  An initial
fix is:

in this diff:
149c149,151
<     /^[a-z_][a-zA-Z0-9_]*[!?]?$/ =~ id && !keyword?(
id )
---
>     /^[a-z_][a-zA-Z0-9_]*[!?]?$/ =~ id ||
>       /^[A-Z][a-zA-Z0-9_]*\.[a-z_][a-zA-Z0-9_]*[!?]?$/ =~
id &&
>       !keyword?( id )


I've tested it with:
require 'test/unit' unless defined? $ZENTEST and $ZENTEST
require 'scriptfile'

module TestRRB
  class TestScriptFile < Test::Unit::TestCase

    def test_valid_method
      assert_not_nil( RRB.valid_method?('my_method') )
      assert_not_nil( RRB.valid_method?('my_method?') )
      assert_not_nil( RRB.valid_method?('my_method!') )
      assert_not_nil( RRB.valid_method?('my_this2that_method') )
      assert_not_nil( RRB.valid_method?('myCamelCaseMethod') )
      assert_not_nil( RRB.valid_method?('MyClass.my_method') ) 
      assert_nil( RRB.valid_method?('My_method') ) 
      assert_nil( RRB.valid_method?('1_method') ) 
      assert_nil( RRB.valid_method?('MyClass.in_a_chain.my_method')
)
    end

  end
end

Attached Files:

Name Description Download
No Files Currently Attached

Changes:

No Changes Have Been Made to This Item