From 35b08385f2666c9ebdae8d8906b674e2382a7827 Mon Sep 17 00:00:00 2001 From: Gianni Chiappetta Date: Thu, 28 May 2015 18:42:30 -0400 Subject: [PATCH] Play nicely with message forwarding * Indicate whether a value can properly respond to a message --- lib/monads/monad.rb | 4 ++++ spec/monads/optional_spec.rb | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/lib/monads/monad.rb b/lib/monads/monad.rb index 26e0bbd..8db637c 100644 --- a/lib/monads/monad.rb +++ b/lib/monads/monad.rb @@ -12,6 +12,10 @@ def method_missing(*args, &block) end end + def respond_to_missing?(method_name, include_all = false) + value.respond_to? method_name, include_all + end + private def ensure_monadic_result(&block) diff --git a/spec/monads/optional_spec.rb b/spec/monads/optional_spec.rb index 2ae6e46..6178d31 100644 --- a/spec/monads/optional_spec.rb +++ b/spec/monads/optional_spec.rb @@ -94,6 +94,10 @@ module Monads it 'returns the message’s result wrapped in an Optional' do expect(optional.challenge.value).to eq response end + + it 'correctly indicated whether a value can respond to a message' do + expect(optional).to respond_to :challenge + end end end end