Skip to content

Instantly share code, notes, and snippets.

@Sihui
Last active January 11, 2018 04:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sihui/db17fe6891e5fb6af58f4d95701ef2c2 to your computer and use it in GitHub Desktop.
Save Sihui/db17fe6891e5fb6af58f4d95701ef2c2 to your computer and use it in GitHub Desktop.
Design Pattern: Builder and Car
class SportsCarBuilder
attr_reader :car
def initialize
@car = ''
end
def build_car_frame
car << "This is a sport car\n"
end
def add_engine
car << " with a powerful engine\n"
end
def add_front_wheels
car << " with two front wheels suitable for mountain paths\n"
end
def add_back_wheels
car << " with two back wheels suitable for mountain paths\n"
end
def add_dashboard
car << " with a fancy sporty dashboard\n"
end
def add_energy_source
car << " with a big fuel tank\n"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment