RobertDober/lab42_core

View on GitHub
lib/lab42/core/behavior/proc_behavior.rb

Summary

Maintainability
A
0 mins
Test Coverage
require 'forwarder'
module Lab42
  module Behavior
    class ProcBehavior
      include Behavior
      attr_reader :behavior

      extend Forwarder
      forward_all :arity, :call, :to_proc, to: :behavior

      private
      def initialize proc=nil, &blk
        @behavior = proc || blk || ->{}
      end
    end # class ProcBehavior

    class ::Proc
      def to_behavior
        Lab42::Behavior::ProcBehavior.new self
      end
    end
  end # module Behavior
end # module Lab42
# SPDX-License-Identifier: Apache-2.0