Created
September 26, 2017 12:29
-
-
Save fedorkk/929973807c20cb2f586b22816860ea4f to your computer and use it in GitHub Desktop.
This file contains 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
class PrintLineService | |
def initialize(context) | |
@context = context | |
end | |
def call | |
puts @context.line | |
end | |
end | |
class ContextFromArray | |
def initialize(arr) | |
@line = arr.join(', ') | |
end | |
def line | |
@line | |
end | |
end | |
class ContextFromLine | |
def initialize(line) | |
@line = line | |
end | |
def line | |
@line | |
end | |
end | |
# Используется примерно так: | |
c1 = ContextFromArray(['hello', 'world']) | |
PrintLineService.new(c1).call | |
# Возвращает 'Hello, world' | |
c2 = ContextFromLine.new('Bye, world') | |
PrintLineService.new(c2).call | |
# Возвращает 'Bye, world' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment