Skip to content

Instantly share code, notes, and snippets.

@rsayers
Created September 6, 2012 17:47
Show Gist options
  • Select an option

  • Save rsayers/3658923 to your computer and use it in GitHub Desktop.

Select an option

Save rsayers/3658923 to your computer and use it in GitHub Desktop.
Literate programming in Ruby
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