procer 0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- metadata +27 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3839f7c654ff0e80881ead31ea6a4ddfb75969f07ed640e79a51034c5002298
|
4
|
+
data.tar.gz: 1e992239045802735804b40e628f23c0cbf3c84c67d1e90662e2b22963daf0d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f398b858c487391979c4d8b32470187a4dc3cb612d5c14ee2cd875f6de7995479ea98f7239834868cbe525160b816fb3b8e9a23cc20f2f58f9942cb447196a7f
|
7
|
+
data.tar.gz: 76d5eabd79f9eae5a4a23bbf5ed66dc4f0b612904de27e1cd48d4f76532ae520d9c9742008e7309f8711abee5bf7f3e11e68574b6bb51a7655147546622782cf
|
metadata
CHANGED
@@ -1,42 +1,45 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: procer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jesús Gómez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: "# Procer\n\
|
13
|
+
description: "# Procer\n\n**NOTE: Experimental. Use it to experience what a default
|
14
|
+
`to_proc`\ncould have been. For production code, I recommend an explicit\ntransformation,
|
15
|
+
like the one provided by the gem `jgomo3-func`**.\n\nA reasonable good default `to_proc`
|
16
|
+
method for all objects.\n\nInstall with:\n\n```\ngem install procer\n```\n\nWhen
|
14
17
|
you require Procer, all objects will have a default `to_proc`\nmethod which will
|
15
18
|
try to call one of the following methods, in the\ngiven order:\n\n - `call`\n -
|
16
|
-
`[]`\n - `===`\n \n Many methods which receive a block, can benefit
|
19
|
+
`[]`\n - `===`\n \n Many methods which receive a block, can benefit greatly from
|
17
20
|
this\n because you can now pass an object to perform the block role.\n \n Think
|
18
|
-
of the Enumerable module and all
|
19
|
-
not `to_proc`. So they will be
|
21
|
+
of the Enumerable module and all its methods.\n \n Many objects define `===`, but
|
22
|
+
not `to_proc`. So they will be nicely\n usable in a `case/when` expression, but
|
20
23
|
not in other contexts.\n \n This is the case of classes and ranges, which you can
|
21
24
|
use in\n `case/when` expressions, but they don't define `to_proc`.\n \n Now they
|
22
25
|
do define `to_proc` so they are useful in those contexts.\n \n Examples:\n \n ```ruby\n
|
23
26
|
require 'procer'\n \n[1, 2, '3', '4', 5, 6].filter(&Numeric)\n# => [1, 2, 5, 6]\n\n[-10,
|
24
27
|
100, -2, 3, 20, -33].filter(&(0..50))\n# => [3, 20]\n```\n\nAlso, Hashes already
|
25
|
-
implement `to_proc` and that is
|
26
|
-
|
27
|
-
'
|
28
|
-
|
29
|
-
|
30
|
-
= ['zero', 'one', 'two']\n[2, 0, 1].map(&table)\n# => ['two', 'zero', 'one']\n```\n\
|
31
|
-
you could have
|
28
|
+
implement `to_proc` and that is useful\nwith Enumerator. We can use it as a transformation
|
29
|
+
table with `map`:\n\n```ruby\n\ntable = {\n 1 => 'one',\n 2 => 'two',\n 3 =>
|
30
|
+
'three'\n}\n\n[3, 1, 2].map(&table)\n# => ['three, 'one, 'two']\n```\n\nSadly, Arrays,
|
31
|
+
even when they have the same interface as hashes as a\nfunction of indices, don't
|
32
|
+
implement `to_proc` and so they can't be used\nin the same way. Until now.\n\n```ruby\ntable
|
33
|
+
= ['zero', 'one', 'two']\n[2, 0, 1].map(&table)\n# => ['two', 'zero', 'one']\n```\n\nAlternatively,
|
34
|
+
you could have used `values_at`:\n\n```ruby\ntable.values_at([3, 1, 2]) # In the
|
32
35
|
Hash example\ntable.values_at([2, 0, 1]) # In the Array example\n```\n\nBut the
|
33
36
|
map solution is more generic and `table` can be anything that\nimplements `to_proc`
|
34
|
-
and not something that
|
35
|
-
object implements `[]` that will triumph over\n`===`. It was
|
36
|
-
to use Integers as the object, as\nthey implement `[]` as a way to access
|
37
|
-
form:\n\n```ruby\n5 # b101\n[5[2], 5[1], 5[0]] # [1, 0, 1]\n```\n\nSo
|
38
|
-
work like that:\n\n```ruby\n[2, 4, 5].map(&5)\n# Actual => [1, 0,
|
39
|
-
=> [false, false, true]\n```\n"
|
37
|
+
and not something that necessarily implements\n`values_at`.\n\nNotice that if the
|
38
|
+
object implements `[]` that will triumph over\n`===`. It was unexpected when I
|
39
|
+
tried to use Integers as the object, as\nthey implement `[]` as a way to access
|
40
|
+
their binary form:\n\n```ruby\n5 # b101\n[5[2], 5[1], 5[0]] # [1, 0, 1]\n```\n\nSo
|
41
|
+
the proc will work like that:\n\n```ruby\n[2, 4, 5].map(&5)\n# Actual => [1, 0,
|
42
|
+
0]\n# I was expecting => [false, false, true]\n```\n"
|
40
43
|
email: jgomo3@gmail.com
|
41
44
|
executables: []
|
42
45
|
extensions: []
|
@@ -46,7 +49,10 @@ files:
|
|
46
49
|
homepage: https://github.com/jgomo3/procer/
|
47
50
|
licenses:
|
48
51
|
- MIT
|
49
|
-
metadata:
|
52
|
+
metadata:
|
53
|
+
'Intended Audience :: Programmers': classifier
|
54
|
+
'Intended Audience :: Developers': classifier
|
55
|
+
'Topic :: Programming :: Experimental': classifier
|
50
56
|
post_install_message:
|
51
57
|
rdoc_options: []
|
52
58
|
require_paths:
|
@@ -62,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
62
68
|
- !ruby/object:Gem::Version
|
63
69
|
version: '0'
|
64
70
|
requirements: []
|
65
|
-
rubygems_version: 3.
|
71
|
+
rubygems_version: 3.1.4
|
66
72
|
signing_key:
|
67
73
|
specification_version: 4
|
68
74
|
summary: Provides a reasonable good default `to_proc` method to all objects
|