ruby - proverb

This commit is contained in:
2018-11-16 16:53:20 -05:00
parent c5e159ed19
commit b54cd4cc6a
3 changed files with 140 additions and 0 deletions

21
ruby/proverb/proverb.rb Normal file
View File

@ -0,0 +1,21 @@
# 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