Class: Dry::Types::Constructor::Function::MethodCall Private

Inherits:
Dry::Types::Constructor::Function show all
Defined in:
lib/dry/types/constructor/function.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Coercion via a method call on a known object

Direct Known Subclasses

PrivateCall, PublicCall

Defined Under Namespace

Classes: PrivateCall, PrivateSafeCall, PublicCall

Instance Attribute Summary collapse

Attributes inherited from Dry::Types::Constructor::Function

#fn

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Dry::Types::Constructor::Function

#<<, #>>, #arity, #call, #wrapper?, yields_block?

Constructor Details

#initialize(fn) ⇒ MethodCall

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of MethodCall.



112
113
114
115
116
# File 'lib/dry/types/constructor/function.rb', line 112

def initialize(fn)
  super
  @target = fn.receiver
  @name = fn.name
end

Instance Attribute Details

#nameObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



110
111
112
# File 'lib/dry/types/constructor/function.rb', line 110

def name
  @name
end

#targetObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



110
111
112
# File 'lib/dry/types/constructor/function.rb', line 110

def target
  @target
end

Class Method Details

.[](fn, safe) ⇒ MethodCall

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



105
106
107
108
# File 'lib/dry/types/constructor/function.rb', line 105

def self.[](fn, safe)
  public = fn.receiver.respond_to?(fn.name)
  MethodCall.call_class(fn.name, public, safe).new(fn)
end

.call_class(method, public, safe) ⇒ Function

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Choose or build the base class

Returns:



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/dry/types/constructor/function.rb', line 32

def self.call_class(method, public, safe)
  @cache.fetch_or_store([method, public, safe]) do
    if public
      ::Class.new(PublicCall) do
        include PublicCall.call_interface(method, safe)

        define_method(:__to_s__) do
          "#<PublicCall for :#{method}>"
        end
      end
    elsif safe
      PrivateCall
    else
      PrivateSafeCall
    end
  end
end

Instance Method Details

#to_astObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



118
119
120
# File 'lib/dry/types/constructor/function.rb', line 118

def to_ast
  [:method, target, name]
end