symbolic 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/.gitignore +1 -0
  2. data/README +25 -1
  3. data/Rakefile +1 -1
  4. data/lib/symbolic.rb +2 -1
  5. metadata +1 -1
data/.gitignore CHANGED
@@ -17,5 +17,6 @@ tmtags
17
17
  coverage
18
18
  rdoc
19
19
  pkg
20
+ *.gemspec
20
21
 
21
22
  ## PROJECT::SPECIFIC
data/README CHANGED
@@ -1 +1,25 @@
1
- Symbolic math for ruby.
1
+ Symbolic math for ruby.
2
+
3
+ Available as gem from gemcutter: gem install symbolic
4
+
5
+ Simple example:
6
+
7
+ Symbolic.enabled = true
8
+
9
+ x = var :name => 'x'
10
+ y = var :name => 'y'
11
+
12
+ f = (4 - 2*(-x) + y*(-1.0))*x - 0*y + 0 - 2
13
+ g = Math.cos(y)
14
+
15
+ puts f # => (4+2*x-y)*x-2
16
+
17
+ p f.undefined_variables.map &:name # => ["x", "y"]
18
+ x.value = 2
19
+ y.value = 4
20
+
21
+ puts f.value # => 6
22
+
23
+ puts g # => cos(y)
24
+ y.value = 0
25
+ puts g.value # => 1.0
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ begin
5
5
  require 'jeweler'
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "symbolic"
8
- gem.version = '0.0.1'
8
+ gem.version = '0.0.2'
9
9
  gem.summary = %Q{Symbolic math for ruby}
10
10
  gem.email = "ravwar@gmail.com"
11
11
  gem.homepage = "http://github.com/brainopia/symbolic"
data/lib/symbolic.rb CHANGED
@@ -176,7 +176,7 @@ module Symbolic
176
176
  end
177
177
 
178
178
  class Variable < Operatable
179
- attr_accessor :value
179
+ attr_accessor :value, :name
180
180
 
181
181
  @@index = 0
182
182
 
@@ -200,6 +200,7 @@ module Symbolic
200
200
 
201
201
  class Expression < Operatable
202
202
  def initialize(var1, var2, operation)
203
+ var1, var2 = var2, var1 if operation == '*' && var2.is_a?(Numeric)
203
204
  @var1, @var2, @operation = var1, var2, operation
204
205
  end
205
206
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: symbolic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - brainopia