Permalink
Browse files

Updated README about working with methods.

  • Loading branch information...
1 parent ca3a68c commit 5929a26741afd372d3fa5283dcf1e01db863fba9 @rahulkmr rahulkmr committed Sep 11, 2011
Showing with 22 additions and 0 deletions.
  1. +22 −0 README.md
View
@@ -33,3 +33,25 @@ Some utils taken from the book "The Ruby Programming Language 6.8 Functional Pro
>> fib = +lambda {|n| return n if n <= 1; fib[n-1] + fib[n-2] }
>> fib[100]
=> 354224848179261915075
+
+### Working with methods.
+
+I couldn't think on anything else other than patching the `Symbol` module and overloading `+@`.
+
+ >> def sqr(x)
+ >> x * x
+ >> end
+
+ >> def inc(x);
+ >> x + 1
+ >> end
+
+ >> (+:sqr | +:inc)[5]
+ => 26
+
+You can mix methods and lambdas.
+
+ >> negate = lambda {|x| -x }
+ >> (+:sqr | +:inc | negate)[5]
+ => -26
+

0 comments on commit 5929a26

Please sign in to comment.