Skip to content

Instantly share code, notes, and snippets.

@michaelfeathers
Created June 7, 2014 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelfeathers/242d0ad0baa57765ced5 to your computer and use it in GitHub Desktop.
Save michaelfeathers/242d0ad0baa57765ced5 to your computer and use it in GitHub Desktop.
Literate Chaining Style in Ruby
module Kernel; def c text; self; end; end
puts ARGF.c("all files as text") .read
.c("convert to enumerable") .chars
.c("contiguous alphas and puncts") .chunk {|ch| ch =~ /[[:alnum:]]/ ? :alone : true }
.c("merging identifiers and nums") .map {|key,values| key == :alone ? values.join : values }
.c("array of idents and puncts") .flatten(1)
.c("adding line numbers") .zip((0...Float::INFINITY))
.c("formatting") .map {|token,line_no| "#{line_no}: #{token_map[token] || token}" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment