to_proc 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a477419f523b6d4e09104704fccd5ec663757f27
4
- data.tar.gz: b9e556edcecedfbaa67abac06b2f2ad7d5ebba68
2
+ SHA256:
3
+ metadata.gz: db8d4d9cff38b15eb0ef2b5e24ee7f70e9e1b557b2d92e5778b6b480bcd9434a
4
+ data.tar.gz: 5a5d7738df0d5a6722a90bf7690c4bca2711ae03602182443bf3b1f2c47802b9
5
5
  SHA512:
6
- metadata.gz: 2e9ec8062c64cb8f667c0619fa741f4ff0961c00a8274e245378c6b6211c748edc72d84a3cb7802a1726b500c5bcddcadda227ce42d3858e284d658556bcbad3
7
- data.tar.gz: 005fe5fcd842d234f2d2b615aa43436877a86e172c0a4d656f40a13b78c36938d09d3aac75dd228a4ad4201f90edf133229b185296eddcbe41fbfd65525f6a2c
6
+ metadata.gz: 8349cba98f70bc0cb71b128f7469bb1082630899d2aff2b1c12571a02dfe37e8200ee32c34e1f95009112716811026ed92641ca144e6aea8a87fe923d3bcd3b4
7
+ data.tar.gz: be359ea5c6098164b348bd79c93d0c42c095b94c417d0ef58f7431b9789990aba1dca3da9e3e347f71f9e2ff7794ae4d856bc205d2e65efc25ef9c43dd52b2e8
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rspec'
@@ -0,0 +1,26 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.3)
5
+ rspec (3.8.0)
6
+ rspec-core (~> 3.8.0)
7
+ rspec-expectations (~> 3.8.0)
8
+ rspec-mocks (~> 3.8.0)
9
+ rspec-core (3.8.2)
10
+ rspec-support (~> 3.8.0)
11
+ rspec-expectations (3.8.4)
12
+ diff-lcs (>= 1.2.0, < 2.0)
13
+ rspec-support (~> 3.8.0)
14
+ rspec-mocks (3.8.1)
15
+ diff-lcs (>= 1.2.0, < 2.0)
16
+ rspec-support (~> 3.8.0)
17
+ rspec-support (3.8.2)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ rspec
24
+
25
+ BUNDLED WITH
26
+ 1.17.2
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2019 by Anatoly Chernow <chertoly@gmail.com>
2
+
3
+ Permission to use, copy, modify, and distribute this software for any
4
+ purpose with or without fee is hereby granted, provided that the above
5
+ copyright notice and this permission notice appear in all copies.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
@@ -0,0 +1,11 @@
1
+ require 'to_proc/refine/object'
2
+ require 'to_proc/refine/class'
3
+ require 'to_proc/refine/array'
4
+
5
+ module ToProc
6
+ module Refine
7
+ include Object
8
+ include Class
9
+ include Array
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ require 'to_proc'
2
+
3
+ module ToProc
4
+ module Refine
5
+ module Array
6
+ refine ::Array do
7
+ def to_proc
8
+ if size == 2
9
+ case
10
+ when self[0].is_a?(Symbol)
11
+ method, argument = self
12
+ return -> receiver { receiver.send method, argument }
13
+ when self[1].is_a?(Symbol)
14
+ receiver, method = self
15
+ return -> argument { receiver.send method, argument }
16
+ end
17
+ end
18
+
19
+ arguments = self
20
+ -> receiver { receiver.to_proc[*arguments] }
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,11 @@
1
+ require 'to_proc'
2
+
3
+ module ToProc
4
+ module Refine
5
+ module Class
6
+ refine ::Class do
7
+ include ToProc[:new]
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'to_proc'
2
+
3
+ module ToProc
4
+ module Refine
5
+ module Object
6
+ refine ::Object do
7
+ include ToProc[:[]]
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,31 @@
1
+ require 'to_proc/refine/array'
2
+
3
+ using ToProc::Refine::Array
4
+
5
+ describe ToProc::Refine::Array do
6
+ describe 'when the size is 2' do
7
+ it 'has a special proc when the first element is a Symbol' do
8
+ array_of_arrays = [[:a, :b, :c], [:b, :c, :d], [:e, :f, :g]]
9
+ arrays_which_include_a = array_of_arrays.select &[:include?, :a]
10
+ expect(arrays_which_include_a).to eq [[:a, :b, :c]]
11
+ end
12
+
13
+ it 'has a special proc when the second element is a Symbol' do
14
+ array = [:a, :b, :c]
15
+ another_array = [1, :a, 2, :c, :d].select &[array, :include?]
16
+ expect(another_array).to eq [:a, :c]
17
+ end
18
+ end
19
+
20
+ describe 'when of any size' do
21
+ it 'has a special proc' do
22
+ proc0 = -> first, second, third { "#{first}#{second}#{third}" }
23
+ proc1 = proc { |first| first }
24
+ array = [proc0, proc1]
25
+
26
+ result = array.map &[:a, :b, :c]
27
+
28
+ expect(result).to eq ['abc', :a]
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,18 @@
1
+ require 'to_proc/refine/class'
2
+
3
+ using ToProc::Refine::Class
4
+
5
+ class MClass
6
+ attr_reader :value
7
+
8
+ def initialize value
9
+ @value = value
10
+ end
11
+ end
12
+
13
+ describe ToProc::Refine::Class do
14
+ it do
15
+ array = [1, 2, 3].map(&MClass).map(&:value)
16
+ expect(array).to eq [1, 2, 3]
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ require 'to_proc/refine/object'
2
+
3
+ using ToProc::Refine::Object
4
+
5
+ module MObject
6
+ def self.[] number
7
+ number + 1
8
+ end
9
+ end
10
+
11
+ describe ToProc::Refine::Object do
12
+ it do
13
+ array = [1, 2, 3].map &MObject
14
+ expect(array).to eq [2, 3, 4]
15
+ end
16
+ end
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |g|
2
2
  g.name = 'to_proc'
3
3
  g.files = `git ls-files`.split($/)
4
- g.version = '0.0.7'
4
+ g.version = '0.0.8'
5
5
  g.summary = 'What if almost any object were a proc?'
6
6
  g.authors = ['Anatoly Chernow']
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: to_proc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anatoly Chernow
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-02 00:00:00.000000000 Z
11
+ date: 2019-09-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -16,16 +16,26 @@ executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
+ - Gemfile
20
+ - Gemfile.lock
21
+ - LICENSE
19
22
  - lib/to_proc.rb
20
23
  - lib/to_proc/all.rb
21
24
  - lib/to_proc/core/Array.rb
22
25
  - lib/to_proc/core/Class.rb
23
26
  - lib/to_proc/core/Object.rb
24
27
  - lib/to_proc/key.rb
28
+ - lib/to_proc/refine.rb
29
+ - lib/to_proc/refine/array.rb
30
+ - lib/to_proc/refine/class.rb
31
+ - lib/to_proc/refine/object.rb
25
32
  - lib/to_proc/sugar.rb
26
33
  - lib/to_proc/try.rb
27
34
  - lib/to_proc/two.rb
28
35
  - lib/to_proc/value.rb
36
+ - spec/refine/array_spec.rb
37
+ - spec/refine/class_spec.rb
38
+ - spec/refine/object_spec.rb
29
39
  - to_proc.gemspec
30
40
  homepage:
31
41
  licenses: []
@@ -45,8 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
45
55
  - !ruby/object:Gem::Version
46
56
  version: '0'
47
57
  requirements: []
48
- rubyforge_project:
49
- rubygems_version: 2.5.2
58
+ rubygems_version: 3.0.3
50
59
  signing_key:
51
60
  specification_version: 4
52
61
  summary: What if almost any object were a proc?