Skip to content

Instantly share code, notes, and snippets.

@fedorkk
Created September 26, 2017 12:29
Show Gist options
  • Save fedorkk/929973807c20cb2f586b22816860ea4f to your computer and use it in GitHub Desktop.
Save fedorkk/929973807c20cb2f586b22816860ea4f to your computer and use it in GitHub Desktop.
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