Created
June 7, 2014 19:46
-
-
Save michaelfeathers/242d0ad0baa57765ced5 to your computer and use it in GitHub Desktop.
Literate Chaining Style 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
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