exercism/ruby/proverb/proverb.rb

22 lines
445 B
Ruby
Raw Normal View History

2018-11-16 16:53:20 -05:00
# Proverb class
class Proverb
def initialize(*args, qualifier: nil)
@inputs = args.to_a
@qualifier = "#{qualifier} " if qualifier
end
def to_s
lines.join("\n") + "And all for the want of a #{@qualifier}#{@inputs[0]}."
end
private
def lines
@inputs.map.with_index do |_, index|
next if index == @inputs.length - 1
"For want of a #{@inputs[index]} the #{@inputs[index + 1]} was lost."
end
end
end