symbolic 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
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.1.4'
8
+ gem.version = '0.1.5'
9
9
  gem.summary = 'Symbolic math for ruby'
10
10
  gem.description = %Q{Symbolic math can be really helpful if you want to simplify some giant equation or if you don't want to get a performance hit re-evaluating big math expressions every time when few variables change.}
11
11
  gem.email = "ravwar@gmail.com"
@@ -1,6 +1,6 @@
1
1
  module Kernel
2
- def var(options={})
3
- Symbolic::Variable.new options
2
+ def var(options={}, &proc)
3
+ Symbolic::Variable.new options, &proc
4
4
  end
5
5
 
6
6
  def symbolic
@@ -1,9 +1,15 @@
1
1
  module Symbolic
2
2
  class Variable < Operatable
3
- attr_accessor :value, :name
3
+ attr_accessor :name, :proc
4
+ attr_writer :value
4
5
 
5
- def initialize(options)
6
+ def initialize(options={}, &proc)
6
7
  @name, @value = options.values_at(:name, :value)
8
+ @proc = proc
9
+ end
10
+
11
+ def value
12
+ @value || @proc && @proc.call
7
13
  end
8
14
 
9
15
  def to_s
@@ -11,7 +17,7 @@ module Symbolic
11
17
  end
12
18
 
13
19
  def undefined_variables
14
- @value ? [] : [self]
20
+ value ? [] : [self]
15
21
  end
16
22
  end
17
23
  end
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.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - brainopia