class NRSER::Types::Respond
This {Type} is used to test how the values in question respond to specific messages (method calls).
{Respond} instances hold a {#message} and {#response} type. Instances that respond when sent the message with a value that satisfies the response type are members.
@example Type
whose members have non-empty string names.
type = Types:Respond.new \ to: :name, with: Types.non_empty_str
Attributes
Message
that will be sent to tested values.
@return [NRSER::Message]
Controls whether the {#message} will be sent using `#public_send` (the default) or `#send` - which has access to private and protected methods.
@return [Boolean]
Type
tested values must respond with when sent the message.
@return [Type]
Public Class Methods
Instantiate a new instance.
See construction example in the class header: {Respond}.
@param [String | Symbol
| Array] to
Fed in to {NRSER::Message.from} to create the {#message}. Must be a lone string or symbol representing the method name to call, or an Array with the string or symbol methods name in the first entry (and whatever other parameters can follow it).
@param [Type | Object] with
The type members must respond with. If `with:` is not a {Type} it will be made into on via {Types.make}.
@param [Boolean] publicly
Chooses between using `#public_send` and `#send` to send the {#message}.
@param [Hash] options
Additional options that will be passed up to {Type#initialize}.
# File lib/nrser/types/responds.rb, line 82 def initialize to:, with:, publicly: true, **options @message = NRSER::Message.from *to @publicly = publicly @response = NRSER::Types.make with super **options end
Public Instance Methods
See {Type#explain}.
@param (see Type#explain
) @return (see Type#explain
) @raise (see Type#explain
)
# File lib/nrser/types/responds.rb, line 103 def explain args_str = message.args.map( &:inspect ).join ', ' if message.block args_str += ', ' + message.block.to_s end "##{ message.symbol }(#{ args_str })#{ RESPONDS_WITH }#{ response.explain }" end
Test value for membership.
@param (see Type#test?
) @return (see Type#test?
) @raise (see Type#test?
)
# File lib/nrser/types/responds.rb, line 120 def test? value response.test message.send_to( value, publicly: publicly ) end