Skip to content

Instantly share code, notes, and snippets.

@vanpelt
Created December 3, 2008 00:21
Show Gist options
  • Save vanpelt/31359 to your computer and use it in GitHub Desktop.
Save vanpelt/31359 to your computer and use it in GitHub Desktop.
fragments = [
["The %s %s %s",
proc do |*args|
raise ArgumentError unless args.all{|a| a.respond_to?(:name) && a.respond_to?(:score)}
[args[0].name, args[0].score > args[1].score ? "beat the" : "won against", args[1].name]
end]
]
class Team
attr_reader :name, :score
def initialize(name, score)
@name = name
@score = score
end
end
fragments.map do |f|
f[0] % f[1].call(Team.new("Cubs", 10), Team.new("Bears",5))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment