eqn 1.4.1 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -4
- data/lib/eqn/calculator.rb +10 -3
- data/lib/eqn/version.rb +1 -1
- 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: b233964ecca218e4954b73f14bf5012cf0c7d30d
|
4
|
+
data.tar.gz: 831f81cb25eefc402de5219089f4403eb1004c1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bbf42e68e90df5969c8bfc238c6b59f289a323dfc30ba2705b86271ca77cf87ae25880b5cf3bb41f13b4e8af302c6541e04caa77a6920f762e0b3a64fb844dc
|
7
|
+
data.tar.gz: dae0c84242de38d1c880f6c629568c3b11a05351fb37cefaa316287a9a7f7123166a8107f7f83e3e9d54b4a278b63c6ac4ea35279c0b171525b0eab79f51ce42
|
data/README.md
CHANGED
@@ -66,11 +66,18 @@ If you need distinct equations with variable sets, you can instantiate separate
|
|
66
66
|
$ calc_two = Eqn::Calculator.new('1 + abc', abc: 5.0)
|
67
67
|
$ calc_two.calc
|
68
68
|
# => 6.0
|
69
|
-
|
70
|
-
|
69
|
+
|
70
|
+
On calculator instances, variables can be set via key-value syntax, hash syntax, or as a method:
|
71
|
+
|
72
|
+
$ calc = Eqn::Calculator.new('1 + abc')
|
73
|
+
$ calc.set(:abc, 3.0)
|
74
|
+
$ calc.abc
|
75
|
+
# => 3.0
|
76
|
+
$ calc.set(abc: 4.0)
|
77
|
+
$ calc.abc
|
71
78
|
# => 4.0
|
72
|
-
$
|
73
|
-
$
|
79
|
+
$ calc.abc = 5.0
|
80
|
+
$ calc.abc
|
74
81
|
# => 5.0
|
75
82
|
|
76
83
|
### Functions
|
data/lib/eqn/calculator.rb
CHANGED
@@ -13,9 +13,16 @@ module Eqn
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
def method_missing(method)
|
17
|
-
|
18
|
-
|
16
|
+
def method_missing(method, *args)
|
17
|
+
if %i(calculate calc valid?).include?(method)
|
18
|
+
self.class.send(method, @eqn, @vars)
|
19
|
+
elsif (match = method.to_s.match(/^[A-Za-z]+=$/))
|
20
|
+
@vars[match.to_s.delete('=').intern] = args.first
|
21
|
+
elsif (var = method.to_s.match(/^[A-Za-z]+$/).to_s.intern) && @vars.key?(var)
|
22
|
+
@vars[var]
|
23
|
+
else
|
24
|
+
super
|
25
|
+
end
|
19
26
|
end
|
20
27
|
|
21
28
|
class << self
|
data/lib/eqn/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eqn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zach Schneider
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: treetop
|