uberscore 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +13 -3
- data/lib/uberscore.rb +5 -8
- data/lib/uberscore/version.rb +1 -1
- data/spec/uberscore_spec.rb +4 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 894935b0dfd33503f11260092e7fee095f982411
|
4
|
+
data.tar.gz: acf71c91e87c65f63a8a021bca156b8a17ec2310
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f107dfbf6866dd8cdf836c7b8e945ee922d338008b4e0b0b4d84fa1253433cd66400587af0a6f011c51941b3c1e234d587e3d37119e2e67873fe6bec5a3a228
|
7
|
+
data.tar.gz: 7e82391b4153664708809f488fd86fff909eeb1390ec8683ad2db9714e2686ccdbed6dc1c327f5141758bb5705bc70bc9dfd98021075657f361d4762024c69f5
|
data/README.md
CHANGED
@@ -18,12 +18,22 @@ Born to make your Ruby blocks more concise.
|
|
18
18
|
# Subscript.
|
19
19
|
[{ name: "foo" }, { name: "bar" }].map { |hash| hash[:name] }
|
20
20
|
[{ name: "foo" }, { name: "bar" }].map(&_[:name])
|
21
|
+
```
|
22
|
+
|
23
|
+
# Name Conflict
|
24
|
+
The method name `_` conflicts with the last expression shortcut in Pry and IRB.
|
25
|
+
If you wish to name the method differently, define the constant `UBERSCORE_METHOD_NAME`
|
26
|
+
before requiring the gem.
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
UBERSCORE_METHOD_NAME = :it # or any other name.
|
30
|
+
|
31
|
+
require "uberscore"
|
21
32
|
|
22
|
-
|
23
|
-
[[1, 2], [3, 4]].map(&_ + _)
|
24
|
-
[[1, 2], [3, 4]].map { |a, b| a + b }
|
33
|
+
[{ name: "foo" }, { name: "bar" }].map(&it[:name])
|
25
34
|
```
|
26
35
|
|
36
|
+
|
27
37
|
## Installation
|
28
38
|
|
29
39
|
Add this line to your application's Gemfile:
|
data/lib/uberscore.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require "uberscore/version"
|
2
2
|
|
3
|
+
UBERSCORE_METHOD_NAME = :_ unless defined? UBERSCORE_METHOD_NAME
|
4
|
+
|
3
5
|
module Uberscore
|
4
6
|
class Context < BasicObject
|
5
7
|
class << self
|
@@ -23,17 +25,12 @@ module Uberscore
|
|
23
25
|
|
24
26
|
def to_proc
|
25
27
|
->(object) do
|
26
|
-
@call_chain.reduce(object) do |
|
27
|
-
|
28
|
-
args = [args.first.to_proc.(current.size > 2 ? current.drop(1) : current[1]), *args.drop(2)]
|
29
|
-
current = current[0]
|
30
|
-
end
|
31
|
-
|
32
|
-
current.public_send(method_name, *args, &block)
|
28
|
+
@call_chain.reduce(object) do |block_parameter, (method_name, method_arguments, block)|
|
29
|
+
block_parameter.public_send(method_name, *method_arguments, &block)
|
33
30
|
end
|
34
31
|
end
|
35
32
|
end
|
36
33
|
end
|
37
34
|
|
38
|
-
Kernel.send(:define_method,
|
35
|
+
Kernel.send(:define_method, UBERSCORE_METHOD_NAME) { Context.__new_uberscore_context__ }
|
39
36
|
end
|
data/lib/uberscore/version.rb
CHANGED
data/spec/uberscore_spec.rb
CHANGED
@@ -2,6 +2,10 @@ require_relative "../lib/uberscore"
|
|
2
2
|
require "pry"
|
3
3
|
|
4
4
|
describe Uberscore do
|
5
|
+
it "works" do
|
6
|
+
expect(%w[A B C].map(&_.downcase)).to eq(%w[a b c])
|
7
|
+
end
|
8
|
+
|
5
9
|
it "chains method calls" do
|
6
10
|
expect(%w[0x 0d ea].map(&_.hex.divmod(13)[1] == 0)).to eq(%w[0x 0d ea].map { |element| element.hex.divmod(13)[1] == 0 })
|
7
11
|
end
|
@@ -17,10 +21,4 @@ describe Uberscore do
|
|
17
21
|
it "can subscript" do
|
18
22
|
expect([{ name: "foo" }, { name: "bar" }].map(&_[:name])).to eq([{ name: "foo" }, { name: "bar" }].map { |hash| hash[:name] })
|
19
23
|
end
|
20
|
-
|
21
|
-
it "can use multiple parameters" do
|
22
|
-
expect([[1, 2], [3, 4]].map(&_ + _)).to eq([3, 7])
|
23
|
-
expect([[1, 2], [3, 4]].map(&_ + _ * 10)).to eq([21, 43])
|
24
|
-
expect([[1, 2, "100"], [3, 4, "200"]].map(&_ + _ * _.to_i)).to eq([201, 803])
|
25
|
-
end
|
26
24
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uberscore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ox0dea
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-07-
|
12
|
+
date: 2015-07-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|