Class: NRSER::Types::Respond
Overview
Type holding an Message and response type. Satisfied by objects that respond with a value that satisfies the respond type when sent the message.
Instance Attribute Summary collapse
-
#message ⇒ NRSER::Message
readonly
Message that will be sent to tested values.
-
#publicly ⇒ Boolean
readonly
TODO document ‘publicly` attribute.
-
#response ⇒ NRSER::Types::Type
readonly
Type tested values must respond with when sent the message.
Instance Method Summary collapse
-
#explain ⇒ String
See Type#explain.
-
#initialize(to:, with:, publicly: true, **options) ⇒ Respond
constructor
Instantiate a new ‘Respond`.
-
#test?(value) ⇒ Boolean
Test value for membership.
Methods inherited from Type
#===, #builtin_inspect, #check, #check!, #from_data, #from_s, #has_from_data?, #has_from_s?, #has_to_data?, #inspect, #intersection, #name, #not, #respond_to?, #test, #to_data, #to_s, #union, #xor
Constructor Details
#initialize(to:, with:, publicly: true, **options) ⇒ Respond
Instantiate a new ‘Respond`.
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/nrser/types/responds.rb', line 42 def initialize to:, with:, publicly: true, ** @message = NRSER::Message.from *to @publicly = publicly @response = NRSER::Types.make with super ** end |
Instance Attribute Details
#message ⇒ NRSER::Message (readonly)
Message that will be sent to tested values.
19 20 21 |
# File 'lib/nrser/types/responds.rb', line 19 def @message end |
#publicly ⇒ Boolean (readonly)
TODO document ‘publicly` attribute.
34 35 36 |
# File 'lib/nrser/types/responds.rb', line 34 def publicly @publicly end |
#response ⇒ NRSER::Types::Type (readonly)
Type tested values must respond with when sent the message.
26 27 28 |
# File 'lib/nrser/types/responds.rb', line 26 def response @response end |
Instance Method Details
#explain ⇒ String
See Type#explain.
63 64 65 66 67 68 69 70 71 |
# File 'lib/nrser/types/responds.rb', line 63 def explain args_str = .args.map( &:inspect ).join ', ' if .block args_str += ', ' + .block.to_s end "##{ .symbol }(#{ args_str })#{ RESPONDS_WITH }#{ response.explain }" end |
#test?(value) ⇒ Boolean
Test value for membership.
80 81 82 |
# File 'lib/nrser/types/responds.rb', line 80 def test? value response.test .send_to( value, publicly: publicly ) end |