Skip to content

Instantly share code, notes, and snippets.

@chrismytton
Last active December 14, 2015 05:19
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save chrismytton/5034580 to your computer and use it in GitHub Desktop.
Save chrismytton/5034580 to your computer and use it in GitHub Desktop.
Literate Ruby

Literate Ruby

Inspired by Literate CoffeeScript.

$ cat hello.rb.md
Here's a simple program

    puts "Hello, world"
$ ruby litrb.rb < hello.rb.md
Hello, world

Here's a simple program

puts "Hello, world"
eval ARGF.readlines.select { |l| l[/^([ ]{4}|\t)/] }.join
@rmosolgo
Copy link

Thanks, very cool! The only problem I had is that if you mark your code with a tab, it trims the first three letters off. I made a little tweak, then used it to make https://github.com/rmosolgo/aiddata-codes.

(although I ran grep -E '^[[ctl-V + TAB]]' > app.rb to get a heroku-deployable version)

@chrismytton
Copy link
Author

@rmosolgo Hi! Gist doesn't seem to do notifications, but I've updated the script to handle tabs. Basically I've dropped the map completely (because ruby doesn't care about whitespace).

Had a look at your projects, love the use of litrb with sinatra! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment