ajvargo / ruby-refactor

A minor mode for Emacs that provides some Ruby refactoring methods.
63 stars 19 forks source link

Allow user to specify an argument list when extracting a method. #21

Closed dodecaphonic closed 10 years ago

dodecaphonic commented 10 years ago

When extracting a method, it's often required that the new method take in arguments (and that the replaced block provide them). Thus, when extracting a new method, ruby-refactor will ask for an optional argument list, to be specified as a comma-separated string. For instance:

def foo(bar)
  baz = biz
  bar.complicated_thing(baz) do
    run_complicated_logic
  end
end

Let's say you want to extract the bar.complicated_thing block into a method. You'll need to pass bar and baz into the new extracted method to keep things working. So, you'll do:

Method name: do_complicated_thing
Argument list (empty if none): bar, baz

That, in turn, will create the following code:

# Extracting the meat
def foo(bar)
  baz = biz
  do_complicated_thing(bar, baz)
end

def do_complicated_thing(bar, baz)
  bar.complicated_thing(baz) do
    run_complicated_logic
  end
end
wanthony commented 10 years ago

Nice, this is a great idea :+1:.

edipofederle commented 10 years ago

This pull request will be merged into master?

dodecaphonic commented 10 years ago

Sorry to bug you, but any chance this will be merged?