Skip to content
Browse files

Use Null Object for output

  • Loading branch information...
1 parent a9bf1e6 commit e9f6623deb257aa4592326df85c332f41160eda3 @avdi committed Jan 10, 2010
Showing with 10 additions and 0 deletions.
  1. +10 −0 lib/cowsay.rb
View
10 lib/cowsay.rb
@@ -1,6 +1,16 @@
require 'active_support'
require 'logger'
module Cowsay
+ class NullObject
+ def method_missing(*args, &block)
+ self
+ end
+ end
+
+ def Maybe(value)
+ value.nil? ? NullObject.new : value
+ end
+
class Cow
def initialize(options={})
@io_class = options.fetch(:io_class){IO}

0 comments on commit e9f6623

Please sign in to comment.
Something went wrong with that request. Please try again.