Class: RubyLambdas::Import

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby/lambdas/core/import.rb

Class Method Summary collapse

Class Method Details

.call(from:, to:) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ruby/lambdas/core/import.rb', line 3

def self.call(from:, to:)
  to_export = from::ToExport

  to_export.constants.each do |function_name|
    function = to_export.const_get(function_name)

    to.const_set(
      function_name,
      function.arity == 1 ? function : function.curry
    )
  end

  return unless from.const_defined?(:ALIASES)

  from::ALIASES.each do |name, new_names|
    Array(new_names)
      .each { |new_name| to.const_set(new_name, to.const_get(name)) }
  end
end