hqt

Ruby Currying

hqt
Feb 11th, 2017
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.30 KB | None | 0 0
  1. # Created by Huynh Quang Thao
  2. # Date: 02/12/2017
  3. # simple example of currying.
  4.  
  5. # finding value of a^base
  6. def f(base, n)
  7.   return 1 if base == 0
  8.   return n if base == 1
  9.   return n * f(base-1, n)
  10. end
  11.  
  12. square = method(:f).curry[2]
  13. triple = method(:f).curry[3]
  14.  
  15. puts square[4]
  16. puts triple[3]
Advertisement
Add Comment
Please, Sign In to add comment