Skip to content

Instantly share code, notes, and snippets.

@dasibre
Last active December 30, 2015 15:18
Show Gist options
  • Save dasibre/7847127 to your computer and use it in GitHub Desktop.
Save dasibre/7847127 to your computer and use it in GitHub Desktop.
Before
class Moviegoer
attr_accessor :name, :street, :phone_number, :zip_code
validates :phone_number, #...
validates :zipcode, #...
def format_phone_number ; ... ; end
def verify_zipcode ; ... ; end
def format_address(street, phone_number, zipcode) #data_clump
#do formatting, calling format_phone_number and verify_zipcode
end
end
# After applying Extract Class:
class Moviegoer
attr_accessor :name
has_one :address
end
class Address
belongs_to :moviegoer
attr_accessor :phone_number, :zipcode
validates :phone_number, # ...
validates :zipcode, # ...
def format_address ; ... ; end # no arguments - operates on 'self'
private # no need to expose these now:
def format_phone_number ; ... ; end
def verify_zipcode ; ... ; end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment