Module: Ramda::Internal::CurriedMethod
- Defined in:
- lib/ramda/internal/curried_method.rb
Overview
Curried Method
Instance Method Summary collapse
- #curried(name, &block) ⇒ Object (also: #curried_method)
-
#curried_method_body(name, arity, &block) ⇒ Object
rubocop:disable Metrics/MethodLength.
- #debug_log(name, args, result) ⇒ Object
-
#replace_placeholder(basic_args, &block) ⇒ Object
rubocop:enable Metrics/MethodLength.
Instance Method Details
#curried(name, &block) ⇒ Object Also known as: curried_method
8 9 10 |
# File 'lib/ramda/internal/curried_method.rb', line 8 def curried(name, &block) define_method(name, &curried_method_body(name, block.arity, &block)) end |
#curried_method_body(name, arity, &block) ⇒ Object
rubocop:disable Metrics/MethodLength
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ramda/internal/curried_method.rb', line 15 def curried_method_body(name, arity, &block) Ramda::Internal::FunctionWithArity.call(arity) do |*args| begin if args.index(Ramda.__) replace_placeholder(args, &block).curry else result = args.empty? ? block : block.call(*args) debug_log(name, args, result) if ::Ramda::DEBUG_MODE result end rescue StandardError => e ::Ramda.exception_handler.call(e, name) end end.curry end |
#debug_log(name, args, result) ⇒ Object
42 43 44 |
# File 'lib/ramda/internal/curried_method.rb', line 42 def debug_log(name, args, result) puts "-> #{name}(#{args.join(', ')}) # #{result}" end |
#replace_placeholder(basic_args, &block) ⇒ Object
rubocop:enable Metrics/MethodLength
32 33 34 35 36 37 38 39 40 |
# File 'lib/ramda/internal/curried_method.rb', line 32 def replace_placeholder(basic_args, &block) Ramda::Internal::FunctionWithArity.call(basic_args.count(Ramda.__)) do |*new_args| cloned_args = basic_args.dup new_args.each { |arg| cloned_args[cloned_args.index(Ramda.__)] = arg } result = block.call(*cloned_args) debug_log(name, cloned_args, result) if ::Ramda::DEBUG_MODE result end end |