Permalink
Browse files

Added origin to NullObject

  • Loading branch information...
1 parent e9f6623 commit 9abc344f737ed5ea828957d65196b9f29d46e1d2 Avdi Grimm committed Jan 11, 2010
Showing with 10 additions and 3 deletions.
  1. +10 −3 lib/cowsay.rb
View
@@ -2,6 +2,14 @@
require 'logger'
module Cowsay
class NullObject
+ def initialize
+ @origin = caller.first
+ end
+
+ def __null_origin__
+ @origin
+ end
+
def method_missing(*args, &block)
self
end
@@ -22,6 +30,7 @@ def say(message, options={})
if options[:strings] && options[:strings][:eyes]
command << " -e '#{options[:strings][:eyes]}'"
end
+ out = options.fetch(:out) { NullObject.new }
messages = case message
when Array then message
@@ -41,9 +50,7 @@ def say(message, options={})
end
end
output = results.join("\n")
- if options[:out]
- options[:out] << output
- end
+ out << output
destination = case options[:out]
when nil then "return value"
when File then options[:out].path

0 comments on commit 9abc344

Please sign in to comment.