ruby-mext 0.11.1 → 0.12.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '094c5745084c9527985efb474ba101f4ce83b826955f54534f41071646868d38'
4
- data.tar.gz: 9d0ef46bf135611facfda70ba041c3e799d275734d3643d22e72dbd6fe165ce8
3
+ metadata.gz: b1542a3a7929927112b1f1485a73d8e0e5477d6b404d092af4e762860516cb0c
4
+ data.tar.gz: 7d055f6c6ed14db1b51044be59231c8aad1ad92a89d5f42bcf5fd47f900413f4
5
5
  SHA512:
6
- metadata.gz: a856aa40fd55d4cff9ab626b761fb6dc8ef1dbd8fc08fb7132f657927b6e61bf7ce0d9e5843a6cb6691e513b8afd3786b8c1ba5bca5648b879cb196a886f6d57
7
- data.tar.gz: 95a2004a86d7f311558f326032f0690493c35e7cb3a854fbbbcc5e0551bdaf8ed5ded763b0fd2a08ac3d1b0d088b2d7dba55ceda56654d79b3d0a75c8c1ba4b4
6
+ metadata.gz: 2b75d6ca804c60b656c11ebfa6041006d038b9e40925394799896108eb53ddadc56ededf2c918ff33336f831d3b581d5d5219d3a9998a272d4ebb23645fdfbc9
7
+ data.tar.gz: 82cc1096f3c593fdc610b43a3862d40c6ae9750e6d8a99e48940ff5df582e19d1c16cba013738dee97bf6f1e03fb45c1f5b8887de3aa0706411ddbb4aadfae12
@@ -0,0 +1,50 @@
1
+ class Array
2
+
3
+ #
4
+ # modifying the behaviour of scalar multiplication for +Array+s
5
+ # has the unintended side-effect of killing any +File.join()+ path which
6
+ # contains a +['..'] * n+ idiomatic figure.
7
+ #
8
+ # Better not tamper with it and use another name
9
+ #
10
+
11
+ SCALAR_OPERATIONS = [ :+, :-, ]
12
+ SCALAR_NEW_OPERATIONS = [ :smul, :/, :%, :**, ]
13
+
14
+ SCALAR_OPERATIONS.each do
15
+ |m|
16
+ orig_meth = "orig_#{m.to_s}".to_sym
17
+ alias_method orig_meth, m
18
+ define_method(m) { |sc| scalarop(m, sc) }
19
+ end
20
+
21
+ SCALAR_NEW_OPERATIONS.each do
22
+ |m|
23
+ define_method(m) { |sc| scalarop_new(m, sc) }
24
+ end
25
+
26
+ protected
27
+
28
+ def scalarop_new(op, other)
29
+ self.map { |el| el.send(op, other) }
30
+ end
31
+
32
+ def scalarop(op, other)
33
+ orig_meth = "orig_#{op.to_s}".to_sym
34
+ return self.send(orig_meth, other) unless other.kind_of?(Numeric)
35
+ scalarop_new(op, other)
36
+ end
37
+
38
+ end
39
+
40
+ #
41
+ # we add an +:smul+ method to scalars in order to seamlessly interoperate
42
+ # with the array version of +:smul+
43
+ #
44
+ class Numeric
45
+
46
+ def smul(other)
47
+ self * other
48
+ end
49
+
50
+ end
data/lib/mext/array.rb CHANGED
@@ -8,4 +8,5 @@ end
8
8
  vectorize
9
9
  choose
10
10
  dotop
11
+ scalarop
11
12
  ).each { |f| require File.join(Mext::ARRAY_PATH, f) }
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mext
2
- VERSION = '0.11.1'
2
+ VERSION = '0.12.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-mext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.1
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicola Bernardini
@@ -117,6 +117,7 @@ files:
117
117
  - lib/mext/array.rb
118
118
  - lib/mext/array/choose.rb
119
119
  - lib/mext/array/dotop.rb
120
+ - lib/mext/array/scalarop.rb
120
121
  - lib/mext/array/vectorize.rb
121
122
  - lib/mext/exceptions.rb
122
123
  - lib/mext/math.rb