Class: Factrey::Ref::Defer

Inherits:
Object
  • Object
show all
Defined in:
lib/factrey/ref/defer.rb

Overview

A thin wrapper around Proc to represent the procedure using the results of the reference resolution. Each argument name is considered as a reference. These references are resolved and the results are passed to the Proc.

Factrey::Refs and Defers are usually created through ShorthandMethods#ref.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&body) ⇒ Defer

Returns a new instance of Defer.

Examples:

Factrey::Ref::Defer.new { |foo, bar| foo + bar }


19
20
21
22
23
24
# File 'lib/factrey/ref/defer.rb', line 19

def initialize(&body)
  body.parameters.all? { _1[0] == :req || _1[0] == :opt } or
    raise ArgumentError, "block must take only fixed positional arguments"

  @body = body
end

Instance Attribute Details

#bodyProc (readonly)

Returns:

  • (Proc)


12
13
14
# File 'lib/factrey/ref/defer.rb', line 12

def body
  @body
end

Instance Method Details

#refsArray<Ref>

Returns:



15
# File 'lib/factrey/ref/defer.rb', line 15

def refs = @body.parameters.map { Ref.new(_1[1]) }