Provides shorthand methods for creating Factrey::Refs and Defers.
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