Class: Sinclair::MethodDefinition::BlockDefinition Abstract Private

Inherits:
Sinclair::MethodDefinition show all
Defined in:
lib/sinclair/method_definition/block_definition.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

This class is abstract.

Define a method from block

Author:

  • darthjee

Constant Summary

Constants inherited from Sinclair::MethodDefinition

DEFAULT_OPTIONS

Instance Attribute Summary

Attributes inherited from Sinclair::MethodDefinition

#name

Attributes included from OptionsParser

#options

Instance Method Summary collapse

Methods inherited from Sinclair::MethodDefinition

build_with, default_value, for, from

Methods included from OptionsParser

#options_object

Constructor Details

#initialize(name, **options, &block) ⇒ BlockDefinition

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of BlockDefinition.

Parameters:

  • name (String, Symbol)

    name of the method

  • block (Proc)

    block with code to be added as method

  • options (Hash)

    Options of construction

Options Hash (**options):

  • cached (Boolean)

    Flag telling to create a method with cache



17
18
19
20
# File 'lib/sinclair/method_definition/block_definition.rb', line 17

def initialize(name, **options, &block)
  @block = block
  super(name, **options)
end

Instance Method Details

#build(klass, type) ⇒ Symbol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Builds the method defined

The method is built using Sinclair::MethodBuilder::BlockMethodBuilder

Parameters:

Returns:

  • (Symbol)

    the name of the method built

See Also:



10
# File 'lib/sinclair/method_definition/block_definition.rb', line 10

build_with MethodBuilder::BlockMethodBuilder

#method_blockProc

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the block that will be used for method creattion

Returns:

  • (Proc)


28
29
30
31
32
33
34
35
36
37
# File 'lib/sinclair/method_definition/block_definition.rb', line 28

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