Pull members up, push members down
The Pull Members Up refactoring allows you to move class members to a specified superclass. Push Members Down moves class members to a subclass.
Pull members up
To pull members up:
Place a caret at the class name or any place within a class:
From the main menu, choose
.In the invoked dialog, select the desired members and the superclass where these members will be placed:
Click OK.
Before | After |
---|---|
cat.rb file
class Cat < Mammal
def move
puts "move"
end
def speak
puts "Meow"
end
end
| animal.rb file
class Animal
def move
puts "move"
end
end
cat.rb file
class Cat < Mammal
def speak
puts "Meow"
end
end
|
Push members down
To push members down:
Place a caret at the class name or any place within a class.
From the main menu, choose
.In the invoked dialog, select the desired members that will be moved to a subclass:
Click OK.
Before | After |
---|---|
animal.rb file
class Animal
def breathe
puts "inhale and exhale"
end
def move
puts "move"
end
end
mammal.rb file
class Mammal < Animal
end
| animal.rb file
class Animal
def move
puts "move"
end
end
mammal.rb file
class Mammal < Animal
def breathe
puts "inhale and exhale"
end
end
|
Last modified: 16 November 2021