Sha256: e4b600e8295860900b5e54734675e496cf15d1d80934bfd7107e7bf32a746df9

Contents?: true

Size: 1.19 KB

Versions: 16

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

class Sinclair
  class MethodDefinition
    # @abstract
    # @author darthjee
    #
    # Define a method from block
    class BlockDefinition < MethodDefinition
      build_with MethodBuilder::BlockMethodBuilder

      # @param name    [String,Symbol] name of the method
      # @param block   [Proc] block with code to be added as method
      # @param options [Hash] Options of construction
      # @option options cached [Boolean] Flag telling to create
      #   a method with cache
      def initialize(name, **options, &block)
        @block = block
        super(name, **options)
      end

      default_value :block?, true
      default_value :string?, false

      # Returns the block that will be used for method creattion
      #
      # @return [Proc]
      def method_block
        return block unless cached?

        case cached
        when :full
          BlockHelper.full_cached_method_proc(name, &block)
        else
          BlockHelper.cached_method_proc(name, &block)
        end
      end

      private

      # @method block
      # @private
      #
      # Block with code to be added as method
      # @return [Proc]
      attr_reader :block
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
sinclair-2.1.1 lib/sinclair/method_definition/block_definition.rb
sinclair-2.1.0 lib/sinclair/method_definition/block_definition.rb
sinclair-2.0.1 lib/sinclair/method_definition/block_definition.rb
sinclair-2.0.0 lib/sinclair/method_definition/block_definition.rb
sinclair-1.16.3 lib/sinclair/method_definition/block_definition.rb
sinclair-1.16.2 lib/sinclair/method_definition/block_definition.rb
sinclair-1.16.1 lib/sinclair/method_definition/block_definition.rb
sinclair-1.16.0 lib/sinclair/method_definition/block_definition.rb
sinclair-1.15.0 lib/sinclair/method_definition/block_definition.rb
sinclair-1.14.2 lib/sinclair/method_definition/block_definition.rb
sinclair-1.14.1 lib/sinclair/method_definition/block_definition.rb
sinclair-1.14.0 lib/sinclair/method_definition/block_definition.rb
sinclair-1.13.0 lib/sinclair/method_definition/block_definition.rb
sinclair-1.12.1 lib/sinclair/method_definition/block_definition.rb
sinclair-1.12.0 lib/sinclair/method_definition/block_definition.rb
sinclair-1.11.0 lib/sinclair/method_definition/block_definition.rb