README.md in ru-0.1.2 vs README.md in ru-0.1.3

- old
+ new

@@ -33,19 +33,21 @@ ```bash awk '{s+=$1} END {print s}' myfile ``` -Any method from Ruby Core and Active Support can be used. Ru also provides new methods to make transformations easier. Here are some variations on the above example: +Any method from Ruby Core and Active Support can be used. Ru also provides new methods (and modifies [#map](#map)) to make transformations easier. Here are some variations on the above example: ```bash ru 'map(:to_i, 10).sum' myfile ru 'map(:to_i).reduce(&:+)' myfile ru 'each_line.to_i.to_a.sum' myfile ru 'grep(/^\d+$/).map(:to_i).sum' myfile +ru 'map { |n| n.to_i }.reduce(&:+)' myfile ru 'reduce(0) { |sum, n| sum + n.to_i }' myfile ru 'each_line.match(/(\d+)/)[1].to_i.to_a.sum' myfile +ru 'map { |n| n.to_i }.reduce(0) { |sum, n| sum + n }' myfile ``` See [Examples](#examples) and [Methods](#methods) for more. Installation @@ -58,11 +60,11 @@ You can now use Ruby in your shell! For example, to sum a list of integers: ```bash -$ echo "2\n3" | ru 'map(:to_i).sum' +$ printf "2\n3" | ru 'map(:to_i).sum' 5 ``` Usage ----- @@ -70,11 +72,11 @@ See [Examples](#examples) below, too! Ru reads from stdin: ```bash -$ echo "2\n3" | ru 'map(:to_i).sum' +$ printf "2\n3" | ru 'map(:to_i).sum' 5 $ cat myfile | ru 'map(:to_i).sum' 5 ``` @@ -94,48 +96,12 @@ 5 ``` The code argument is run as if it has `$stdin.each_line.map(&:chomp).` prepended to it. The result is converted to a string and printed. So, if you run `ru 'map(&:to_i).sum'`, you can think of it as running `puts $stdin.each_line.map(&:chomp).map(&:to_i).sum`. -In addition to the methods provided by Ruby Core and Active Support, Ru provides other methods for performing transformations, like `each_line`, `files`, and `grep`. See [Methods](#methods) for more. +In addition to the methods provided by Ruby Core and Active Support, Ru provides other methods for performing transformations, like `each_line`, `files`, and `grep`, and it improves `map`. See [Methods](#methods) for more. -### Saving commands - -You can save commands for future use using `save`: - -```bash -$ ru save sum 'map(:to_i).sum' -Saved command: sum is 'map(:to_i).sum' -``` - -And run them later using `run`: - -```bash -$ echo "2\n3" | ru run sum -5 -$ ru run sum myfile -5 -``` - -To see all of your saved commands, use `list`: - -```bash -$ ru list -Saved commands: -sum map(:to_i).sum -``` - -### Options - -#### -h, --help - -Print a help page. - -#### -v, --version - -Print the installed version of Ru. - Examples -------- Let's compare the readability and conciseness of Ru relative to existing tools: @@ -230,11 +196,11 @@ #### files Converts the lines to `Ru::File` objects (see Ru::File below). ```bash -$ echo "foo.txt" | ru 'files.map(:updated_at).map(:strftime, ""%Y-%m-%d")' +$ printf "foo.txt" | ru 'files.map(:updated_at).map(:strftime, ""%Y-%m-%d")' 2014-11-08 ``` #### format(format='l') @@ -251,33 +217,33 @@ #### grep Selects lines which match the given regex. ```bash -$ echo "john\npaul\ngeorge" | ru 'grep(/o[h|r]/)' +$ printf "john\npaul\ngeorge" | ru 'grep(/o[h|r]/)' john george ``` #### map -This is the same as `Array#map`, but it adds a new syntax that allows you to easily pass arguments to a method. For example: +This is the same as [Array#map](http://www.ruby-doc.org/core-2.0/Array.html#method-i-map), but it adds a new syntax that allows you to easily pass arguments to a method. For example: ```bash -$ echo "john\npaul" | ru 'map(:[], 0)' +$ printf "john\npaul" | ru 'map(:[], 0)' j p -$ echo "john\npaul" | ru 'map(:center, 8, ".")' +$ printf "john\npaul" | ru 'map(:center, 8, ".")' ..john.. ..paul.. ``` Note that the examples above can also be performed with `each_line`: ```bash -$ echo "john\npaul" | ru 'each_line[0]' -$ echo "john\npaul" | ru 'each_line.center(8, ".")' +$ printf "john\npaul" | ru 'each_line[0]' +$ printf "john\npaul" | ru 'each_line.center(8, ".")' ``` Ru::File ------------ @@ -300,9 +266,54 @@ * `to_s` (alias for name) * `uid` * `updated_at` (alias for mtime) * `world_readable?` +Saved Commands +-------------- + +Ru lets you save commands by name, so that you can easily use them later. + +#### save + +Save a command for future use: + +```bash +$ ru save sum 'map(:to_i).sum' +Saved command: sum is 'map(:to_i).sum' +``` + +#### run + +Run a saved command: + +```bash +$ printf "2\n3" | ru run sum +5 +$ ru run sum myfile +5 +``` + +#### list + +List all of your saved commands: + +```bash +$ ru list +Saved commands: +sum map(:to_i).sum +``` + +Options +------- + +#### -h, --help + +Print a help page. + +#### -v, --version + +Print the installed version of Ru. Testing ------- Ru is tested against Active Support 3 and 4. If you'd like to submit a PR, please be sure to use [Appraisal](https://github.com/thoughtbot/appraisal) to test your changes in both contexts: