Guest User

Untitled

a guest
Dec 11th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. module StringApply
  2. def apply(*funcs)
  3. funcs.inject(self) { |product, func| func.call(product) }
  4. end
  5. end
  6.  
  7. module ArrayApply
  8. def apply(*funcs)
  9. # funcs.inject(self) { |product, func| func.call(product) }
  10. map { |item| funcs.inject(item) { |product, func| func.call(product) } }
  11. end
  12. end
  13.  
  14. String.include StringApply
  15. Array.include ArrayApply
  16.  
  17. module ProcRefinement
  18. refine Proc do
  19. def [](*args)
  20. curry.(*args)
  21. end
  22. end
  23. end
  24.  
  25. module ApplyRefinement
  26. refine Object do
  27. def apply(*funcs)
  28. funcs.inject(self) { |product, func| func.call(product) }
  29. end
  30. end
  31. end
  32.  
  33. s = 'ahoj'
  34.  
  35. func = -> (a) { puts a; a }
  36. s.apply(func,
  37. func,
  38. func)
Add Comment
Please, Sign In to add comment