Created
September 6, 2012 17:47
-
-
Save rsayers/3658923 to your computer and use it in GitHub Desktop.
Literate programming in Ruby
This file contains hidden or 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
| def lit(src) | |
| eval src.split("\n").delete_if { |l| l[0]!='>' }.map {|l| l[1,l.length] }.join("\n") | |
| end | |
| lit <<src | |
| This is a big wall of text with no Ruby code... | |
| Does this work? | |
| 1 1 + . | |
| I bet it didn't... maybe the following works: | |
| > puts 8675309 | |
| Yay! | |
| You can create functions that span multiple lines | |
| > def foo | |
| We interrupt this program to bring you the following: | |
| > 12 ; end; | |
| Now, we can run foo: | |
| > puts foo | |
| src |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment