Archive

Archive for December, 2010

vim-ruby-refactoring – Extract Method

31 December, 2010 1 comment

This post is part of a series which documents the vim-ruby-refactoring plugin.

IMPORTANT: As well as installing the vim-ruby-refactoring plugin, you must also install the matchit.vim plugin for this refactoring to work.

Extract Method

Extracts a selection into a method and places it above the current method.

The refactoring: http://www.refactoring.com/catalog/extractMethod.html

Example

Before refactoring:
ExtractMethod_Before
Visually select lines you wish to extract
Hit your <leader-key> then type rem
You will now see a prompt to enter the new method name: 
Method name: print_details

After refactoring:
ExtractMethod_After
A new method print_details has been added above the print_owing method containing the contents of the selected lines.

rem is the default binding for this refactoring, think Refactor Extract Method.

Advertisements

vim-ruby-refactoring – Rename Instance Variable

31 December, 2010 1 comment

This post is part of a series which documents the vim-ruby-refactoring plugin.

IMPORTANT: As well as installing the vim-ruby-refactoring plugin, you must also install the matchit.vim plugin for this refactoring to work.

Rename Instance Variable

Renames the selected instance variable.

Example

Before refactoring:
RenameInstanceVar_Before
Visually select the instance variable you wish to rename
Hit your <leader-key> then type rriv
You will now see a prompt to enter the new variable name: 
Rename to: new_name

After refactoring:
RenameInstanceVar_After
The instance variable @name has been renamed to @new_name in both locations within the class.

rriv is the default binding for this refactoring, think Refactor Rename Instance Variable.

vim-ruby-refactoring – Rename Local Variable

31 December, 2010 1 comment

This post is part of a series which documents the vim-ruby-refactoring plugin.

IMPORTANT: As well as installing the vim-ruby-refactoring plugin, you must also install the matchit.vim plugin for this refactoring to work.

Rename Local Variable

Renames the selected local variable.

Example

Before refactoring:
RenameVar_Before
Visually select the local variable you wish to rename
Hit your <leader-key> then type rrlv
You will now see a prompt to enter the new variable name: 
Rename to: is_mac_os

After refactoring:
RenameVar_After
The local variable mac_os has been renamed to is_mac_os in both locations within the method.

rrlv is the default binding for this refactoring, think Refactor Rename Local Variable.

vim-ruby-refactoring – Extract Local Variable

31 December, 2010 1 comment

This post is part of a series which documents the vim-ruby-refactoring plugin.

Extract Local Variable

Extracts a visual selection into a local variable.

The refactoring: http://www.refactoring.com/catalog/introduceExplainingVariable.html

Example

Before refactoring:
ExtractVar_Before
Visually select the value you wish to extract
Hit your <leader-key> then type relv
You will now see a prompt to enter the variable name: 
Variable name: mac_os

After refactoring:
ExtractVar_After
The value platform.upcase.include?(‘MAC’) has been extracted into a local variable mac_os.

relv is the default binding for this refactoring, think Refactor Extract Local Variable.

vim-ruby-refactoring – Extract to Let

30 December, 2010 1 comment

This post is part of a series which documents the vim-ruby-refactoring plugin.

Extract to Let

This is an RSpec specific refactoring which will extract an initialisation line and create a let method for you.

Example

Before refactoring:
ExtractLet_Before 
Move the cursor on to the line you wish to extract
Hit your <leader-key> then type rel

After refactoring:
ExtractLet_After
The let method is created above the it block, using the initialisation line – account = Account.new.

rel is the default binding for this refactoring, think Refactor Extract Let.

vim-ruby-refactoring – Extract Constant

30 December, 2010 1 comment

This post is part of a series which documents the vim-ruby-refactoring plugin.

Extract Constant

Extracts a selection into a constant which is placed at the top of the current module or class.

The refactoring: http://www.refactoring.com/catalog/replaceMagicNumberWithSymbolicConstant.html

Example

Before refactoring:
ExtractConstant_Before 
Visually select the value you wish to extract
Hit your <leader-key> then type rec
You will now see a prompt to enter the constant name: 
Constant name: Gravitational_Constant

After refactoring:
ExtractConstant_After
The value 9.81 has been extracted into a constant GRAVITATIONAL_CONSTANT which is placed at the top of the module.

rec is the default binding for this refactoring, think Refactor Extract Constant.

vim-ruby-refactoring – Convert Post Conditional

30 December, 2010 1 comment

This post is part of a series which documents the vim-ruby-refactoring plugin.

Convert Post Conditional

Converts a post conditional expression to a conditional expression.

Example

Before refactoring:

ConvertPostConditional_Before
Move the cursor onto the line which contains the post conditional expression
Hit your <leader-key> then type rcpc

After refactoring:

ConvertPostConditional_After
The post conditional expression is split across 3 lines and converted into a standard if expression.

rcpc is the default binding for this refactoring, think Refactor Convert Post Conditional.