juxt 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +6 -0
- data/lib/juxt.rb +1 -1
- data/lib/juxt/version.rb +1 -1
- data/spec/juxt_spec.rb +14 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -14,6 +14,12 @@ Example
|
|
14
14
|
{:foo => 'foo', :bar => 'bar'}.juxt :foo, :bar
|
15
15
|
# ['foo', 'bar']
|
16
16
|
|
17
|
+
# Procs and Lambdas are ok too
|
18
|
+
proc = Proc.new{ |m| m.class }
|
19
|
+
lambda = ->(m){ m.length + 100 }
|
20
|
+
'foo'.juxt proc, lambda
|
21
|
+
# [String, 103]
|
22
|
+
|
17
23
|
# Need to create a hash from some Object properties/method/attributes?
|
18
24
|
arr = ['foo', 'bar']
|
19
25
|
Hash[arr.map_juxt :upcase, :reverse]
|
data/lib/juxt.rb
CHANGED
data/lib/juxt/version.rb
CHANGED
data/spec/juxt_spec.rb
CHANGED
@@ -6,14 +6,28 @@ describe Juxt do
|
|
6
6
|
let(:arr3){ [] }
|
7
7
|
let(:obj1){ 'foo' }
|
8
8
|
let(:obj2){ {:foo => 'foo', :bar => 'bar'} }
|
9
|
+
let(:obj3){ Object.new }
|
9
10
|
|
10
11
|
describe 'Array#map_juxt' do
|
12
|
+
it "should call juxtapose for all array elements" do
|
13
|
+
arr1.first.should_receive(:juxtapose).with :upcase, :reverse
|
14
|
+
arr1.last.should_receive(:juxtapose).with :upcase, :reverse
|
15
|
+
arr1.map_juxt :upcase, :reverse
|
16
|
+
end
|
11
17
|
specify{ expect(arr1.map_juxt :upcase, :reverse).to eq [['FOO', 'oof'], ['BAR', 'rab']] }
|
12
18
|
specify{ expect(arr2.map_juxt :upcase, :reverse).to eq [['FOO', 'oof']] }
|
13
19
|
specify{ expect(arr3.map_juxt :upcase, :reverse).to eq [] }
|
14
20
|
end
|
15
21
|
|
16
22
|
describe 'Object#juxt' do
|
23
|
+
it "should execute a Proc or lambda with self as the only argument" do
|
24
|
+
obj3.stub(:method1){ 10 }
|
25
|
+
obj3.stub(:method2){ 20 }
|
26
|
+
proc = Proc.new{ |m| m.method1 + m.method2 }
|
27
|
+
lambda = ->(m){ m.method1 * m.method2 }
|
28
|
+
expect(obj3.juxt proc, lambda).to eq [30, 200]
|
29
|
+
end
|
30
|
+
|
17
31
|
describe String do
|
18
32
|
specify{ expect(obj1.juxt :upcase, :reverse).to eq ['FOO', 'oof'] }
|
19
33
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: juxt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|