#!/usr/bin/env ruby # This code comes from http://ruby-it.org/pages/Currying # Check the page for copyright notice and explanations let somma arg1 arg2 = arg1+arg2 ;; let somma_due = somma 2 ;; somma_due 10 ;; - : int = 12 def curry(funz, *alcuni_arg) proc { |*altri_arg| funz[*(alcuni_arg + altri_arg)] } end >> def curry(funz, *alcuni_arg) >> proc { |*altri_arg| funz[*(alcuni_arg + altri_arg)] } >> end => nil >> def somma(arg1,arg2) arg1+arg2 end => nil >> s=method :somma => # >> somma_2 = curry(s, 2) => # >> somma_2[10] => 12 >> def somma_5(a1,a2,a3,a4,a5) a1+a2+a3+a4+a5 end => nil >> s=method :somma_5 => # >> somma_4_e_1 =curry s, 1 => # >> somma_4_e_1[2,3,4,5] => 15 >> somma_1_e_4 =curry s, 1, 2,3,4 => # >> somma_1_e_4[5] => 15