Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update README

  • Loading branch information...
commit 2ea0290dc28394d5eddccb39a7025633af8a39f7 1 parent aa99aa2
@ConradIrwin ConradIrwin authored
Showing with 19 additions and 7 deletions.
  1. +19 −7 README.markdown
View
26 README.markdown
@@ -13,7 +13,12 @@ However the real strength in the library comes from allowing you to call methods
[1,"2",3].select &X.is_a?(String)
# => ["2"]
-And, as everything in ruby is a method, create readable expressions without the noise of a one-argument block:
+And to chain method calls:
+
+ [1, 2, 3].map &X.to_f.to_s
+ # => ["1.0", "2.0", "3.0"]
+
+As everything in Ruby is a method call, you can create readable expressions without the noise of a one-argument block:
[{1 => 2}, {1 => 3}].map &X[1]
# => [2, 3]
@@ -27,10 +32,11 @@ And, as everything in ruby is a method, create readable expressions without the
[{}].each &X[1] = 2
# => [{1 => 2}]
-As an added bonus, the effect is transitive — you can chain method calls:
+You can use this in any place a block is expected, for example to create a lambda:
- [1, 2, 3].map &X.to_f.to_s
- # => ["1.0", "2.0", "3.0"]
+ normalizer = lambda &X.to_s.downcase
+ normalizer.call :HelloWorld
+ # => "helloworld"
Gotchas
-------
@@ -64,14 +70,20 @@ Secondly, other arguments or operands will only be evaluated once, and not every
Bugs
----
-If you create an assigning callable (e.g. `X[a] = b`, `X.a = b` ) without an immediate preceding `&`, then `b.class#to_proc` will return the assigning callable the first time, and only the first time, you call it. If you want to get access to an assigning callable that you've defined using `&X`, you must do: `lambda &X[a] = b` instead.
-
+In normal usage there are no known bugs. That said, if you accidentally miss the `&` from in front of the `X`, in an expression that ends in an assignment (e.g. `X.formatter = :inspect`); then the `#to_proc` method of the object assigned will respond with the expression generated by that `X` the next time you call it from anywhere else in the same thread.
Epilogue
--------
+`&X` has been tested on MRI ruby 1.8.6, 1.8.7 and 1.9.2 and jruby 1.5.3. It is thread-safe.
+
For bug-fixes or enhancements, please contact the author: Conrad Irwin <conrad.irwin@gmail.com>
-For an up-to-date version, try http://github.com/rapportive-oss/ampex
+For an up-to-date version, try <https://github.com/rapportive-oss/ampex>
This library is copyrighted under the MIT license, see LICENSE.MIT for details.
+
+See also
+--------
+
+* <https://github.com/danielribeiro/RubyUnderscore> — which uses an underscore in place of `&X` and works by rewriting the syntax tree.
Please sign in to comment.
Something went wrong with that request. Please try again.