Skip to content

Instantly share code, notes, and snippets.

Created May 5, 2015 02:31
Show Gist options
  • Save anonymous/8deaba7f10190285bae5 to your computer and use it in GitHub Desktop.
Save anonymous/8deaba7f10190285bae5 to your computer and use it in GitHub Desktop.
module DefaultOrder
module_function
def order(data)
data
end
end
module RandomOrder
module_function
def order(data)
data.shuffle
end
end
class House
DATA =[
"the cat that killed",
"the rat that ate",
"the malt that lay in",
"the house that Jack built"
]
def initialize
@data = orderer.order(DATA)
end
def recite
(1..@data.length).map {|i| line(i)}.join("\n")
end
def line(number)
"This is #{phrase(number)}.\n"
end
def phrase(number)
@data.last(number).join(" ")
end
def orderer
DefaultOrder
end
end
class RandomHouse < House
def orderer
RandomOrder
end
end
puts House.new.recite
puts "="*88
puts "="*88
puts "="*88
puts RandomHouse.new.recite
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment