Created
June 1, 2020 21:36
-
-
Save mattapayne/ed3e455256a49eee762573cd2fc1c301 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Things | |
TYPE_ONE = 'type_one'.freeze | |
TYPE_TWO = 'type_two'.freeze | |
TYPE_THREE = 'type_three'.freeze | |
class ThingFactory | |
class << self | |
def call(type, args) | |
case type | |
when TYPE_ONE | |
TypeOne.new(args) | |
when TYPE_TWO | |
TypeTwo.new(args) | |
when TYPE_THREE | |
TypeThree.new(args) | |
end | |
end | |
end | |
end | |
class TypeOne | |
def initialize(args) | |
@args = args | |
end | |
def do_work | |
# do something using @args | |
end | |
end | |
class TypeTwo | |
def initialize(args) | |
@args = args | |
end | |
def do_work | |
# do something using @args | |
end | |
end | |
class TypeThree | |
def initialize(args) | |
@args = args | |
end | |
def do_work | |
# do something using @args | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment