Module: Factrey::Ref::ShorthandMethods

Included in:
DSL
Defined in:
lib/factrey/ref/shorthand_methods.rb

Overview

Provides shorthand methods for creating Factrey::Refs and Defers.

Instance Method Summary collapse

Instance Method Details

#ref(name = nil) ⇒ Ref, ...

Examples:

include Factrey::Ref::ShorthandMethods

# `ref(symbol)` returns a `Ref` instance
ref(:foo)
# `ref` returns a `Ref::Builder` instance; thus, we can write
ref.foo
# `ref { ... }` returns a `Ref::Defer` instance
ref { |foo, bar| foo + bar }

Returns:



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/factrey/ref/shorthand_methods.rb', line 17

def ref(name = nil, &)
  if name
    raise ArgumentError, "both name and block given" if block_given?

    Ref.new(name)
  elsif block_given?
    Defer.new(&)
  else
    Builder.new
  end
end