Class: NRSER::Types::Respond
Overview
Instance Attribute Summary collapse
-
#message ⇒ NRSER::Message
readonly
Message that will be sent to tested values.
-
#publicly ⇒ Boolean
readonly
Controls whether the #message will be sent using ‘#public_send` (the default) or `#send` - which has access to private and protected methods.
-
#response ⇒ 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 instance.
-
#test?(value) ⇒ Boolean
Test value for membership.
Methods inherited from Type
#===, #builtin_inspect, #check, #check!, #default_name, #default_symbolic, #from_data, #from_s, #has_from_data?, #has_from_s?, #has_to_data?, #inspect, #intersection, #name, #not, #respond_to?, #symbolic, #test, #to_data, #to_proc, #to_s, #union, #xor
Constructor Details
#initialize(to:, with:, publicly: true, **options) ⇒ Respond
Instantiate a new instance.
See construction example in the class header: NRSER::Types::Respond.
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/nrser/types/responds.rb', line 82 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.
39 40 41 |
# File 'lib/nrser/types/responds.rb', line 39 def @message end |
#publicly ⇒ Boolean (readonly)
Controls whether the #message will be sent using ‘#public_send` (the default) or `#send` - which has access to private and protected methods.
55 56 57 |
# File 'lib/nrser/types/responds.rb', line 55 def publicly @publicly end |
#response ⇒ Type (readonly)
Type tested values must respond with when sent the message.
46 47 48 |
# File 'lib/nrser/types/responds.rb', line 46 def response @response end |
Instance Method Details
#explain ⇒ String
See Type#explain.
103 104 105 106 107 108 109 110 111 |
# File 'lib/nrser/types/responds.rb', line 103 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.
120 121 122 |
# File 'lib/nrser/types/responds.rb', line 120 def test? value response.test .send_to( value, publicly: publicly ) end |