Class: Module

Inherits:
Object show all
Includes:
CacheMethods, Tins::Annotate, Tins::ClassMethod, Tins::Concern::ModuleMixin, Tins::Constant, Tins::DSLAccessor, Tins::Delegate, Tins::Deprecate, Tins::FromModule, Tins::Implement, Tins::ParameterizedModule
Defined in:
lib/tins/xt/concern.rb,
lib/tins/memoize.rb,
lib/tins/xt/annotate.rb,
lib/tins/xt/deprecate.rb,
lib/tins/xt/dslkit.rb,
lib/tins/xt/implement.rb,
lib/tins/xt/named.rb

Overview

Extends the core Module class with the concern functionality.

This line makes the concern configuration methods available to all modules in the system, allowing any module to be configured as a concern.

Direct Known Subclasses

Tins::NullClass

Constant Summary

Constants included from Tins::Implement

Tins::Implement::MESSAGES

Constants included from Tins::Delegate

Tins::Delegate::UNSET

Instance Method Summary collapse

Methods included from Tins::Implement

#implement, #implement_in_submodule

Methods included from Tins::FromModule

#parameterize

Methods included from Tins::ParameterizedModule

#parameterize_for

Methods included from Tins::Delegate

#delegate

Methods included from Tins::ClassMethod

#class_attr_accessor, #class_attr_reader, #class_attr_writer, #class_define_method

Methods included from Tins::Eigenclass

#eigenclass_class_eval, #eigenclass_eval

Methods included from Tins::DSLAccessor

#dsl_accessor, #dsl_lazy_accessor, #dsl_reader

Methods included from Tins::Constant

#constant

Methods included from Tins::Deprecate

#deprecate

Methods included from Tins::Concern::ModuleMixin

#tins_concern_args, #tins_concern_configure

Methods included from Tins::Annotate

#annotate

Instance Method Details

#memoize_function(*function_ids) ⇒ Symbol+

Deprecated.

Use ‘memoize function:` from the mize gem instead.

Memoize a function (class method) so that its return value is cached based only on the arguments, shared across all instances of the class.

Parameters:

  • function_ids (Array<Symbol>)

    One or more function names to memoize

  • opts (Hash)

    a customizable set of options

Returns:

  • (Symbol, Array<Symbol>)

    The memoized function name(s)



108
109
110
111
112
113
114
115
116
# File 'lib/tins/memoize.rb', line 108

def memoize_function(*function_ids)
  warn "[DEPRECATION] `memoize_function` is deprecated. Please use `memoize function:` from mize gem."
  function_ids.extend(ExtractLastArgumentOptions)
  function_ids, opts = function_ids.extract_last_argument_options
  function_ids.each do |function|
    memoize function:, **opts.slice(:freeze)
  end
  function_ids.size == 1 ? function_ids.first : function_ids
end

#memoize_method(*method_ids) ⇒ Symbol+

Deprecated.

Use ‘memoize method:` from the mize gem instead.

Memoize a method so that its return value is cached based on the arguments and the object instance. Each instance maintains its own cache.

Parameters:

  • method_ids (Array<Symbol>)

    One or more method names to memoize

  • opts (Hash)

    a customizable set of options

Returns:

  • (Symbol, Array<Symbol>)

    The memoized method name(s)



87
88
89
90
91
92
93
94
95
96
# File 'lib/tins/memoize.rb', line 87

def memoize_method(*method_ids)
  warn "[DEPRECATION] `memoize_method` is deprecated. Please use `memoize method:` from mize gem."
  method_ids.extend(ExtractLastArgumentOptions)
  method_ids, opts = method_ids.extract_last_argument_options
  method_ids.each do |method|
    memoize method:, **opts.slice(:freeze)
  end
  include CacheMethods
  method_ids.size == 1 ? method_ids.first : method_ids
end

#named(name, method, *args) {|Object| ... } ⇒ Module

Adds a dynamically created method to all instances of the class. The method will call the specified method with optional args and combine any provided named_block with runtime blocks.

Examples:

Create a class-level method

Array.named(:sum_all, :reduce) { |acc, x| acc + x }
[1, 2, 3].sum_all  # => 6

Parameters:

  • name (Symbol)

    The name of the method to create

  • method (Symbol)

    The existing method to delegate to

  • args (Array)

    Optional arguments to pre-bind to the delegated method

Yields:

  • (Object)

    Optional block to be used as the method’s block

Returns:



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/tins/xt/named.rb', line 64

def named(name, method, *args, &named_block)
  name = name.to_sym
  m = Tins::Named.new {
    define_method(name) do |*rest, &block|
      block = named_block if named_block
      __send__(method, *(args + rest), &block)
    end
  }
  if m.respond_to?(:set_temporary_name)
    m.set_temporary_name "#{m.class} for method #{name.inspect}"
  end
  include m
end