Created
January 20, 2009 20:20
-
-
Save wuputah/49647 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this works fine, but it uses a local variable with no purpose | |
factorial = lambda do |n| | |
return 1 if n <= 1 | |
n * factorial.call(n - 1) | |
end | |
puts factorial.call(5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts lambda do |n| | |
return 1 if n <= 1 | |
n * SELF.call(n - 1) | |
end.call(5) | |
# what do you use for 'SELF' that actually works? | |
# or, is there an another way to do this (while still using anonymous functions)? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment