chainedexpressions 0.2 → 0.3

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
  SHA1:
3
- metadata.gz: 8ca3ff7d238ea1837df9515a15ca665ea9ee0dc9
4
- data.tar.gz: d6cb0e3b60799c6327e010fa997efafda9cd9365
3
+ metadata.gz: a0080d860307a431d8e18cb9960c58e891b2e8ec
4
+ data.tar.gz: c14be71435652bf0f82c42dc9b1b5fe70461e37e
5
5
  SHA512:
6
- metadata.gz: ab8145ace1efc8a8e8a67ff750e83dffe5ec4b65285e1c39af3b5d8d3b38c9b5a67db4297d96361ce887bd9f9291fb639fcb7b746dc6a603feb8236d93e6a41c
7
- data.tar.gz: 25ffadf8397664d56c5c84d0cc74025815acf96afa63bbad4a72652d3caa51c1eb4a9ef8193d620a640a23b537dd958cb43babcd360f8e17039fd6b66c540f89
6
+ metadata.gz: 9744d7c4d860e29fc650c1baa30aecc2cbd96ce19983e57d0c12c8843f0ad3df313a6fec06c89d876fb77465d767e556cb81e82072909757632ac2590d0cba99
7
+ data.tar.gz: c4b5aa883017e5d0d9becfbed909997af89fb29a2148332a0b0925b71060e364edbffbb66497e5bdc1f00670cbf66dddf1f322af598c9489dc32cb4c8f23715a
@@ -13,40 +13,49 @@ module ChainedExpressions
13
13
  :< => :lt,
14
14
  :<= => :lte,
15
15
  :>= => :gte,
16
- :> => :gt,
16
+ :> => :gt
17
17
  }
18
18
 
19
+ refine Numeric do
20
+ def eval_expression(op, n)
21
+ case op
22
+ when :< then (self <=> n) == -1
23
+ when :<= then (self <=> n) == -1 || (self <=> n) == 0
24
+ when :>= then (self <=> n) == 0 || (self <=> n) == 1
25
+ when :> then (self <=> n) == 1
26
+ end
27
+ end
28
+ end
29
+
19
30
  %w(TrueClass FalseClass).each { |c|
20
31
  eval <<-EOM
21
32
  refine #{c} do
22
- $operators.each { |k, o|
23
- define_method o do |n|
24
- $f.exp_true? k, n
33
+ $operators.each { |op, o|
34
+ define_method o do |n|
35
+ prev = $prev
36
+ $prev = n
37
+ prev.eval_expression op, n
25
38
  end
26
39
 
27
- alias_method k, o
40
+ alias_method op, o
28
41
  }
29
42
  end
30
43
  EOM
31
44
  }
32
45
 
33
- refine Fixnum do
34
- def exp_true?(op, n)
35
- case op
36
- when :< then (self <=> n) == -1
37
- when :<= then (self <=> n) == -1 || (self <=> n) == 0
38
- when :>= then (self <=> n) == 0 || (self <=> n) == 1
39
- when :> then (self <=> n) == 1
40
- end
41
- end
46
+ %w(Fixnum Float Bignum).each { |c|
47
+ eval <<-EOM
48
+ refine #{c} do
49
+ $operators.each { |op, o|
50
+ define_method o do |n|
51
+ $prev = n
52
+ eval_expression op, n
53
+ end
42
54
 
43
- $operators.each { |k, o|
44
- define_method o do |n|
45
- $f = n
46
- self.exp_true? k, n
55
+ alias_method op, o
56
+ }
47
57
  end
58
+ EOM
59
+ }
60
+ end
48
61
 
49
- alias_method k, o
50
- }
51
- end
52
- end
@@ -9,5 +9,5 @@
9
9
  #++
10
10
 
11
11
  module ChainedExpressions
12
- VERSION = '0.2'
12
+ VERSION = '0.3'
13
13
  end
@@ -10,39 +10,28 @@
10
10
 
11
11
  require 'rspec'
12
12
  require 'chainedexpressions'
13
-
14
13
  using ChainedExpressions
15
14
 
16
15
  describe ChainedExpressions do
17
16
  it 'can evaluate true expressions' do
18
- (20 < 25).should be true
19
-
20
- (20 < 25 < 30).should be true
21
- (20 < 25 < 30).should be true
22
-
23
- (20 <= 25 <= 30 <= 30 <= 35).should be true
24
- (20 <= 25 <= 30 <= 30 <= 35).should be true
25
-
26
- (35 > 30 > 25 > 20).should be true
17
+ (20 < 25 ).should be true
18
+ (20 < 25 < 30 ).should be true
27
19
  (35 > 30 > 25 > 20).should be true
28
20
 
29
- (35 >= 30 >= 30 >= 25 >= 20).should be true
30
- (35 >= 30 >= 30 >= 25 >= 20).should be true
21
+ (20 <= 25 <= 30 <= 30 <= 35).should be true
22
+ (35 >= 30 >= 30 >= 25 >= 20).should be true
23
+ (20.5 >= 10 >= 2.5 >= 2.5 ).should be true
31
24
  end
32
25
 
33
26
  it 'can evaluate false expressions' do
34
- (30 < 25).should be false
35
-
36
- (30 < 25 < 20).should be false
37
- (30 < 25 < 20).should be false
38
-
39
- (35 <= 30 <= 30 <= 25 <= 20).should be false
40
- (35 <= 30 <= 30 <= 25 <= 20).should be false
41
-
42
- (20 > 25 > 30 > 35).should be false
27
+ (30 < 25 ).should be false
28
+ (30 < 25 < 20 ).should be false
43
29
  (20 > 25 > 30 > 35).should be false
44
30
 
45
- (20 >= 25 >= 30 >= 30 >= 35).should be false
46
- (20 >= 25 >= 30 >= 30 >= 35).should be false
31
+ (35 <= 30 <= 30 <= 25 <= 20).should be false
32
+ (20 >= 25 >= 30 >= 30 >= 35).should be false
33
+ (20.5 >= 10 >= 2.5 >= 3.5 ).should be false
34
+
35
+ ([1, 2])
47
36
  end
48
37
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chainedexpressions
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Giovanni Capuano