Posts

Showing posts from June, 2020

Currying: A Ruby approach

Image
Hi, This is  Shubham Mishra  from India,  this is the part of  Ruby on Rails  exploration journey.  In this post we will discuss about the ruby's one of the underworld approach: Currying (not 🥘 this one 😅). I thing it would be better to understand it first by diagrammatically. Let understand curry in ruby in a snap. Lets suppose we want to sum up 3 numbers [1,2,3], Normal Ruby approach : Normal Sum in RUBY Curried Sum: Curry in Ruby Simple, isn't it!,😉😉, Ok if you are not in a hurry then you should now go through the Code level reading to understand it even better. Practice it :  Curry in Ruby, Play here See the OutPut: #<Method: main.sum> Normal Sum: 6 Curried Sum 👇: #<Proc:0x000055c305dbb0f0 (lambda)> #<Proc:0x000055c305dbace0 (lambda)> 6 Now, understand each part: The sum() method is the normal ruby code, where (*) is splat operator, which takes more than one arguments. Then we have method(:sum), which is the reference f