diff options
| author | mokha <mokha@cisco.com> | 2018-02-13 19:26:26 -0700 |
|---|---|---|
| committer | mokha <mokha@cisco.com> | 2018-02-13 19:26:26 -0700 |
| commit | 659211e442a6cee0a1a4cf020ff22c2301ceac3a (patch) | |
| tree | 9f37897dcffdf0d3eb90508761289e72192676d8 /lib | |
| parent | 3883fe135d524743e0527f5a9deede323caf8c61 (diff) | |
metaprogram the animals.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/xsay.rb | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/lib/xsay.rb b/lib/xsay.rb index 25099e9..032d202 100644 --- a/lib/xsay.rb +++ b/lib/xsay.rb @@ -3,16 +3,13 @@ require "thor" module Xsay class CLI < Thor - desc "cat <message>", "xsay cat meow" - def cat(message) - template = IO.read(File.expand_path("xsay/templates/cat.template", File.dirname(__FILE__))) - render(message, template) - end + Dir[File.expand_path("xsay/templates/*.template", File.dirname(__FILE__))].each do |filename| + animal = File.basename(filename).split(".")[0] - desc "hippo <message>", "xsay hippo meow" - def hippo(message) - template = IO.read(File.expand_path('xsay/templates/hippo.template', File.dirname(__FILE__))) - render(message, template) + desc "#{animal} <message>", "xsay #{animal} hello" + define_method animal do |message| + render(message, IO.read(filename)) + end end private |
