Skip to content

Instantly share code, notes, and snippets.

@armandofox
Created May 11, 2021 16:39
Show Gist options
  • Save armandofox/a100b89babb3e1dfc3f0fbbe98fcd820 to your computer and use it in GitHub Desktop.
Save armandofox/a100b89babb3e1dfc3f0fbbe98fcd820 to your computer and use it in GitHub Desktop.
srp_example.rb
class Moviegoer
attr_accessor :name, :street, :phone_number, :zipcode
validates :phone_number, # ...
validates :zipcode, # ...
def format_phone_number ; ... ; end
def check_zipcode ; ... ; end
def format_address(street, phone_number, zipcode) # data clump
# do formatting, calling format_phone_number and check_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 check_zipcode ; ... ; end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment