guruby 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/guruby/expr.rb +19 -1
- data/lib/guruby/var.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce1569b34b64f28b94bf6fee645dee1558048082
|
4
|
+
data.tar.gz: b60a693f6504a11594ea9c81309bc89893104f40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9603e3ecf122e06f510bccb6adbcac0481eb056d668bc3e3b8d57c5fdea2dd96c1a1cf7c04244607edfa8c6244c24d3f9e52f115696d272d5d08a96c45e2b7b
|
7
|
+
data.tar.gz: 9b8650d311a06606f717bb33be0b569123f143c52603641e35f1b454966dc3bccd4fec1d74b1656a5f13eda037a6572da28849190ceb1c4722d937f7fce86c80
|
data/lib/guruby/expr.rb
CHANGED
@@ -17,10 +17,28 @@ module Guruby
|
|
17
17
|
# Add the variable to the expression
|
18
18
|
self + other * 1.0
|
19
19
|
else
|
20
|
-
fail TypeError
|
20
|
+
fail TypeError
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
+
# Add terms from the other expression to this one
|
25
|
+
def add(other)
|
26
|
+
case other
|
27
|
+
when LinExpr
|
28
|
+
@terms.merge!(other.terms) { |_, c1, c2| c1 + c2 }
|
29
|
+
when Variable
|
30
|
+
if @terms.key? other
|
31
|
+
@terms[other] += 1.0
|
32
|
+
else
|
33
|
+
@terms[other] = 1.0
|
34
|
+
end
|
35
|
+
else
|
36
|
+
fail TypeError
|
37
|
+
end
|
38
|
+
|
39
|
+
self
|
40
|
+
end
|
41
|
+
|
24
42
|
# Produce a string representing the expression
|
25
43
|
def inspect
|
26
44
|
@terms.map do |var, coeff|
|
data/lib/guruby/var.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Mior
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|