hexlet-pairs 0.1.0 → 1.0.0
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/.github/workflows/ci.yml +20 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +11 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +47 -0
- data/Makefile +8 -0
- data/README.md +22 -0
- data/lib/hexlet/pairs.rb +49 -0
- data/lib/hexlet/pairs/version.rb +5 -0
- data/pairs.gemspec +25 -0
- metadata +21 -8
- data/lib/pairs.rb +0 -45
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5a2eb18f3c135b536517372b683af1baef6e862276473cba1cd3f034e9d6a0ff
|
|
4
|
+
data.tar.gz: c9a0d76bd2033187957d821dd546449451ba21f125cf1b94fdb9b4fef0289285
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: adf597ba8901a89c094833e0eba33f24ac7d82f9276176e51ecf518f37d0ef26656b0951db07c39241fb7dea7245b4e91ab7b57b0c23e3607e02c92d41679021
|
|
7
|
+
data.tar.gz: 6886edf2d13555fbaeb9e0193798cd78b27ec1939dd53329f151062cd760fff9d0f9b0477ceab3e64f5d0d79a249d2d14a4149ec8f1db2cccdf6811643b1f459
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
- push
|
|
5
|
+
- pull_request
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
build:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
steps:
|
|
11
|
+
- uses: actions/checkout@v2
|
|
12
|
+
- uses: ruby/setup-ruby@v1
|
|
13
|
+
with:
|
|
14
|
+
ruby-version: 2.7.2
|
|
15
|
+
- name: Install
|
|
16
|
+
run: make install
|
|
17
|
+
- name: Run linter
|
|
18
|
+
run: make lint
|
|
19
|
+
- name: Run tests
|
|
20
|
+
run: make test
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
GEM
|
|
2
|
+
remote: https://rubygems.org/
|
|
3
|
+
specs:
|
|
4
|
+
ast (2.4.2)
|
|
5
|
+
diff-lcs (1.4.4)
|
|
6
|
+
parallel (1.20.1)
|
|
7
|
+
parser (3.0.0.0)
|
|
8
|
+
ast (~> 2.4.1)
|
|
9
|
+
rainbow (3.0.0)
|
|
10
|
+
regexp_parser (2.1.1)
|
|
11
|
+
rexml (3.2.4)
|
|
12
|
+
rspec (3.10.0)
|
|
13
|
+
rspec-core (~> 3.10.0)
|
|
14
|
+
rspec-expectations (~> 3.10.0)
|
|
15
|
+
rspec-mocks (~> 3.10.0)
|
|
16
|
+
rspec-core (3.10.1)
|
|
17
|
+
rspec-support (~> 3.10.0)
|
|
18
|
+
rspec-expectations (3.10.1)
|
|
19
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
20
|
+
rspec-support (~> 3.10.0)
|
|
21
|
+
rspec-mocks (3.10.2)
|
|
22
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
23
|
+
rspec-support (~> 3.10.0)
|
|
24
|
+
rspec-support (3.10.2)
|
|
25
|
+
rubocop (1.11.0)
|
|
26
|
+
parallel (~> 1.10)
|
|
27
|
+
parser (>= 3.0.0.0)
|
|
28
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
29
|
+
regexp_parser (>= 1.8, < 3.0)
|
|
30
|
+
rexml
|
|
31
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
|
32
|
+
ruby-progressbar (~> 1.7)
|
|
33
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
|
34
|
+
rubocop-ast (1.4.1)
|
|
35
|
+
parser (>= 2.7.1.5)
|
|
36
|
+
ruby-progressbar (1.11.0)
|
|
37
|
+
unicode-display_width (2.0.0)
|
|
38
|
+
|
|
39
|
+
PLATFORMS
|
|
40
|
+
ruby
|
|
41
|
+
|
|
42
|
+
DEPENDENCIES
|
|
43
|
+
rspec (~> 3.10)
|
|
44
|
+
rubocop (~> 1.1)
|
|
45
|
+
|
|
46
|
+
BUNDLED WITH
|
|
47
|
+
2.1.4
|
data/Makefile
ADDED
data/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# ruby-pairs
|
|
2
|
+
|
|
3
|
+
[](https://github.com/hexlet-components/ruby-pairs/actions)
|
|
4
|
+
|
|
5
|
+
## Usage example
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
require 'hexlet/pairs'
|
|
9
|
+
|
|
10
|
+
pair = Pairs.cons(3, 5)
|
|
11
|
+
|
|
12
|
+
puts Pairs.pair?(pair) # => true
|
|
13
|
+
|
|
14
|
+
puts Pairs.car(pair) # => 3
|
|
15
|
+
puts Pairs.cdr(pair) # => 5
|
|
16
|
+
|
|
17
|
+
puts Pairs.to_string(pair) # => '(3, 5)'
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
[](https://ru.hexlet.io/pages/about?utm_source=github&utm_medium=link&utm_campaign=ruby-pairs)
|
|
21
|
+
|
|
22
|
+
This repository is created and maintained by the team and the community of Hexlet, an educational project. [Read more about Hexlet (in Russian)](https://ru.hexlet.io/pages/about?utm_source=github&utm_medium=link&utm_campaign=ruby-pairs).
|
data/lib/hexlet/pairs.rb
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require "hexlet/pairs/version"
|
|
2
|
+
|
|
3
|
+
module Hexlet
|
|
4
|
+
module Pairs
|
|
5
|
+
def self.cons(left, right)
|
|
6
|
+
lambda { |message|
|
|
7
|
+
case message
|
|
8
|
+
when 'car'
|
|
9
|
+
left
|
|
10
|
+
when 'cdr'
|
|
11
|
+
right
|
|
12
|
+
else
|
|
13
|
+
raise "Unknown message #{message}"
|
|
14
|
+
end
|
|
15
|
+
}
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.check_pair(pair)
|
|
19
|
+
return if pair?(pair)
|
|
20
|
+
|
|
21
|
+
raise NoMethodError, pair.to_s
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.car(pair)
|
|
25
|
+
check_pair(pair)
|
|
26
|
+
pair.call('car')
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.cdr(pair)
|
|
30
|
+
pair.call('cdr')
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.pair?(pair)
|
|
34
|
+
pair.instance_of? Proc
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.to_string(pair)
|
|
38
|
+
rec = lambda { |pair_inner|
|
|
39
|
+
return pair_inner.to_s unless pair?(pair_inner)
|
|
40
|
+
|
|
41
|
+
left = car(pair_inner)
|
|
42
|
+
right = cdr(pair_inner)
|
|
43
|
+
"(#{rec.call(left)}, #{rec.call(right)})"
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
rec.call(pair)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
data/pairs.gemspec
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require_relative 'lib/hexlet/pairs/version'
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |spec|
|
|
4
|
+
spec.name = "hexlet-pairs"
|
|
5
|
+
spec.version = Hexlet::Pairs::VERSION
|
|
6
|
+
spec.authors = ["Hexlet"]
|
|
7
|
+
spec.email = ["info@hexlet.io"]
|
|
8
|
+
|
|
9
|
+
spec.summary = "Hexlet Ruby Pairs"
|
|
10
|
+
spec.description = "A SICP'ish Functional Pairs implemented in Ruby."
|
|
11
|
+
spec.homepage = "https://github.com/hexlet-components/ruby-pairs"
|
|
12
|
+
spec.license = "MIT"
|
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
|
14
|
+
|
|
15
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
16
|
+
spec.metadata["source_code_uri"] = "https://github.com/hexlet-components/ruby-pairs"
|
|
17
|
+
spec.metadata["changelog_uri"] = "https://github.com/hexlet-components/ruby-pairs"
|
|
18
|
+
|
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
21
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
22
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
23
|
+
end
|
|
24
|
+
spec.require_paths = ["lib"]
|
|
25
|
+
end
|
metadata
CHANGED
|
@@ -1,26 +1,39 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: hexlet-pairs
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Hexlet
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-03-
|
|
11
|
+
date: 2021-03-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
|
-
description:
|
|
14
|
-
email:
|
|
13
|
+
description: A SICP'ish Functional Pairs implemented in Ruby.
|
|
14
|
+
email:
|
|
15
|
+
- info@hexlet.io
|
|
15
16
|
executables: []
|
|
16
17
|
extensions: []
|
|
17
18
|
extra_rdoc_files: []
|
|
18
19
|
files:
|
|
19
|
-
-
|
|
20
|
+
- ".github/workflows/ci.yml"
|
|
21
|
+
- ".gitignore"
|
|
22
|
+
- ".rubocop.yml"
|
|
23
|
+
- Gemfile
|
|
24
|
+
- Gemfile.lock
|
|
25
|
+
- Makefile
|
|
26
|
+
- README.md
|
|
27
|
+
- lib/hexlet/pairs.rb
|
|
28
|
+
- lib/hexlet/pairs/version.rb
|
|
29
|
+
- pairs.gemspec
|
|
20
30
|
homepage: https://github.com/hexlet-components/ruby-pairs
|
|
21
31
|
licenses:
|
|
22
32
|
- MIT
|
|
23
|
-
metadata:
|
|
33
|
+
metadata:
|
|
34
|
+
homepage_uri: https://github.com/hexlet-components/ruby-pairs
|
|
35
|
+
source_code_uri: https://github.com/hexlet-components/ruby-pairs
|
|
36
|
+
changelog_uri: https://github.com/hexlet-components/ruby-pairs
|
|
24
37
|
post_install_message:
|
|
25
38
|
rdoc_options: []
|
|
26
39
|
require_paths:
|
|
@@ -29,7 +42,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
29
42
|
requirements:
|
|
30
43
|
- - ">="
|
|
31
44
|
- !ruby/object:Gem::Version
|
|
32
|
-
version:
|
|
45
|
+
version: 2.3.0
|
|
33
46
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
34
47
|
requirements:
|
|
35
48
|
- - ">="
|
|
@@ -39,5 +52,5 @@ requirements: []
|
|
|
39
52
|
rubygems_version: 3.0.3
|
|
40
53
|
signing_key:
|
|
41
54
|
specification_version: 4
|
|
42
|
-
summary:
|
|
55
|
+
summary: Hexlet Ruby Pairs
|
|
43
56
|
test_files: []
|
data/lib/pairs.rb
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
module Pairs
|
|
2
|
-
def self.cons(left, right)
|
|
3
|
-
lambda { |message|
|
|
4
|
-
case message
|
|
5
|
-
when 'car'
|
|
6
|
-
left
|
|
7
|
-
when 'cdr'
|
|
8
|
-
right
|
|
9
|
-
else
|
|
10
|
-
raise "Unknown message #{message}"
|
|
11
|
-
end
|
|
12
|
-
}
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def self.check_pair(pair)
|
|
16
|
-
return if pair?(pair)
|
|
17
|
-
|
|
18
|
-
raise NoMethodError, pair.to_s
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def self.car(pair)
|
|
22
|
-
check_pair(pair)
|
|
23
|
-
pair.call('car')
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def self.cdr(pair)
|
|
27
|
-
pair.call('cdr')
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def self.pair?(pair)
|
|
31
|
-
pair.instance_of? Proc
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def self.to_string(pair)
|
|
35
|
-
rec = lambda { |pair_inner|
|
|
36
|
-
return pair_inner.to_s unless pair?(pair_inner)
|
|
37
|
-
|
|
38
|
-
left = car(pair_inner)
|
|
39
|
-
right = cdr(pair_inner)
|
|
40
|
-
"(#{rec.call(left)}, #{rec.call(right)})"
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
rec.call(pair)
|
|
44
|
-
end
|
|
45
|
-
end
|