JoergWMittag-boole 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2009 Jörg W Mittag <JoergWMittag+Boole@GoogleMail.Com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.rst ADDED
@@ -0,0 +1,126 @@
1
+ =======
2
+ Boole
3
+ =======
4
+ ---------------------------------------------------------------------------
5
+ A message-sending based re-implementation of Boolean operators in pure Ruby
6
+ ---------------------------------------------------------------------------
7
+
8
+ .. admonition:: Abstract
9
+
10
+ Boole_ is a message-sending based re-implementation of the
11
+ Boolean operators ``if``, ``unless``, ``and``, ``or`` and
12
+ ``not`` in pure Ruby. Lazy Evaluation / Short-circuiting is
13
+ achieved through the use of blocks and lambda expressions.
14
+
15
+ .. _Boole: https://JoergWMittag.GitHub.Com/Boole/
16
+
17
+ .. contents::
18
+
19
+ What
20
+ ====
21
+
22
+ This library contains sample re-implementations of the Boolean
23
+ operators ``if``, ``unless``, ``and``, ``or`` and ``not`` in pure
24
+ Ruby. The style is heavily inspired by Smalltalk_ and its
25
+ relatives: the operators become messages that take block
26
+ parameters and are sent to the conditionals.
27
+
28
+ Operator / keyword style::
29
+
30
+ if condition1 && condition2
31
+ then_block
32
+ elsif condition3
33
+ elsif_block
34
+ else
35
+ else_block
36
+ end
37
+
38
+ becomes::
39
+
40
+ condition1.and { condition2 }.ifelse ->() { then_block }, ->() { condition3.ifelse ->() { elsif_block }, ->() { else_block } }
41
+
42
+ .. _Smalltalk: http://Smalltalk.Org/
43
+
44
+ Why
45
+ ===
46
+
47
+ Every so often, there is a discussion on either the Ruby-Talk_ or
48
+ Ruby-Core_ mailinglists, whether the number of operators that are
49
+ not backed by methods should be reduced. In Ruby 1.9, ``!`` and
50
+ ``!=`` have already become methods, but ``if``, ``unless``,
51
+ ``and`` and ``or`` are still builtin operators.
52
+
53
+ One argument that is sometimes brought up is that because of the
54
+ short-circuiting nature of those operators, implementing them as
55
+ methods is impossible or at least hard. I just wanted to see
56
+ *how* hard it really is!
57
+
58
+ .. _Ruby-Talk: http://Ruby-Forum.Com/forum/4/
59
+ .. _Ruby-Core: http://Ruby-Forum.Com/forum/14/
60
+
61
+ How
62
+ ===
63
+
64
+ All the operators become methods. The logic is achieved through
65
+ polymorphism: basically, ``NilClass`` and ``FalseClass`` get one
66
+ set of implementations, ``Object`` gets the opposite set.
67
+
68
+ Lazy Evaluation is achieved with blocks: if a block is not
69
+ supposed to be evaluated, it is simply never ``yield``\ ed to.
70
+
71
+ Installation
72
+ ============
73
+
74
+ ::
75
+
76
+ gem install JoergWMittag-boole
77
+
78
+ Usage
79
+ =====
80
+
81
+ ::
82
+
83
+ begin require 'rubygems'; rescue LoadError
84
+ else begin gem 'JoergWMittag-boole', '~> 0.0.1'; rescue Gem::LoadError; end end
85
+ require 'boole'
86
+
87
+ true.and { nil.or { 42 } }.if { puts "It's true!" }
88
+
89
+ false.ifelse ->() { puts "You'll never see this." }, ->() { puts 'But this!' }
90
+
91
+ Acknowledgements
92
+ ================
93
+
94
+ Style
95
+ -----
96
+
97
+ The API style is heavily influenced by Smalltalk_.
98
+
99
+ Implementation
100
+ --------------
101
+
102
+ The implementation is literally textbook: every introductory CS
103
+ text should have it.
104
+
105
+ Specs
106
+ -----
107
+
108
+ The Specs were directly lifted from the RubySpec_ project.
109
+
110
+ .. _RubySpec: http://RubySpec.Org/
111
+
112
+ License
113
+ =======
114
+
115
+ My original work is licensed under the `MIT X11 License`_.
116
+
117
+ .. include:: LICENSE.txt
118
+ :literal:
119
+
120
+ The `RubySpec license`_ is also MIT X11.
121
+
122
+ .. include:: spec/LICENSE.txt
123
+ :literal:
124
+
125
+ .. _MIT X11 License: https://GitHub.Com/JoergWMittag/Boole/tree/master/LICENSE.txt
126
+ .. _RubySpec license: https://GitHub.Com/RubySpec/RubySpec/tree/master/LICENSE
data/Rakefile.rb ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby1.9
2
+ # vim: filetype=ruby, fileencoding=UTF-8, tabsize=2, shiftwidth=2
3
+
4
+ require 'rake'
5
+
6
+ taskdir = File.expand_path File.join(File.dirname(__FILE__), 'tasks')
7
+ $LOAD_PATH.unshift taskdir unless $LOAD_PATH.include? taskdir
8
+
9
+ FileList[File.join taskdir, '**', '*_task.rb'].each { |raketask| load raketask }
data/boole.gemspec ADDED
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env ruby1.9
2
+ # vim: filetype=ruby, fileencoding=UTF-8, tabsize=2, shiftwidth=2
3
+
4
+ #Copyright (c) 2009 Jörg W Mittag <JoergWMittag+B001e@GoogleMail.Com>
5
+ #This code is licensed under the terms of the MIT License (see LICENSE.txt)
6
+
7
+ begin
8
+ require 'rubygems'
9
+ require 'yaml'
10
+ require 'pp'
11
+ rescue Object => e
12
+ $exception = e
13
+ end
14
+
15
+ basedir = File.expand_path File.dirname(__FILE__)
16
+ $LOAD_PATH.unshift basedir unless $LOAD_PATH.include? basedir
17
+
18
+ #filelist = YAML.load DATA.read
19
+
20
+ filelist = %w[boole.gemspec
21
+ lib/boole
22
+ lib/boole/extensions
23
+ lib/boole/extensions/core
24
+ lib/boole/extensions/core/false_class_extensions.rb
25
+ lib/boole/extensions/core/nil_class_extensions.rb
26
+ lib/boole/extensions/core/object_extensions.rb
27
+ lib/boole/extensions/core/true_class_extensions.rb
28
+ lib/boole/falsiness.rb
29
+ lib/boole/truthiness.rb
30
+ lib/boole.rb
31
+ LICENSE.txt
32
+ Rakefile.rb
33
+ README.rst
34
+ spec/and_spec.rb
35
+ spec/boole_suite.rb
36
+ spec/if_spec.rb
37
+ spec/LICENSE.txt
38
+ spec/not_spec.rb
39
+ spec/or_spec.rb
40
+ spec/spec_helper.rb
41
+ spec/unless_spec.rb
42
+ tasks/gem_task.rb
43
+ tasks/spec_task.rb
44
+ tasks/_default_task.rb]
45
+
46
+ pp filelist
47
+
48
+ speclist = filelist.grep /^spec/
49
+
50
+ $spec = Gem::Specification.new do |s|
51
+ s.name = 'boole'
52
+ # s.summary = 'Message-sending based re-implementation of the Boolean operators.'
53
+ s.summary = "Exception = #{$exception.inspect}"
54
+ s.version = '0.0.1'
55
+ s.author = 'Jörg W Mittag'
56
+ s.email = 'JoergWMittag+Boole@GoogleMail.Com'
57
+ s.homepage = 'https://JoergWMittag.GitHub.Com/Boole/'
58
+ s.rubyforge_project = 'boole'
59
+ s.required_ruby_version = Gem::Requirement.new '~> 1.9.1'
60
+ s.files = filelist
61
+ s.test_files = speclist
62
+ s.description = "#{YAML.dump $exception}"
63
+ # s.description = <<-'HERE'
64
+ #Boole is a message-sending based re-implementation of the
65
+ #Boolean operators 'if', 'unless', 'and', 'or' and 'not' in
66
+ #pure Ruby. Lazy Evaluation / Short-circuiting is achieved
67
+ #through the use of blocks and lambda expressions.
68
+ # HERE
69
+ end
70
+
71
+ __END__
72
+
73
+ ---
74
+ - boole.gemspec
75
+ - lib/boole
76
+ - lib/boole/extensions
77
+ - lib/boole/extensions/core
78
+ - lib/boole/extensions/core/false_class_extensions.rb
79
+ - lib/boole/extensions/core/nil_class_extensions.rb
80
+ - lib/boole/extensions/core/object_extensions.rb
81
+ - lib/boole/extensions/core/true_class_extensions.rb
82
+ - lib/boole/falsiness.rb
83
+ - lib/boole/truthiness.rb
84
+ - lib/boole.rb
85
+ - LICENSE.txt
86
+ - Rakefile.rb
87
+ - README.rst
88
+ - spec/and_spec.rb
89
+ - spec/boole_suite.rb
90
+ - spec/if_spec.rb
91
+ - spec/LICENSE.txt
92
+ - spec/not_spec.rb
93
+ - spec/or_spec.rb
94
+ - spec/spec_helper.rb
95
+ - spec/unless_spec.rb
96
+ - tasks/gem_task.rb
97
+ - tasks/spec_task.rb
98
+ - tasks/_default_task.rb
data/lib/boole.rb ADDED
@@ -0,0 +1,9 @@
1
+ # vim: filetype=ruby, fileencoding=UTF-8, tabsize=2, shiftwidth=2
2
+
3
+ libdir = File.expand_path(File.dirname __FILE__).gsub(/(.*lib).*?/, '\1')
4
+ $LOAD_PATH.unshift libdir unless $LOAD_PATH.include? libdir
5
+
6
+ require 'boole/extensions/core/object_extensions'
7
+ require 'boole/extensions/core/true_class_extensions'
8
+ require 'boole/extensions/core/false_class_extensions'
9
+ require 'boole/extensions/core/nil_class_extensions'
@@ -0,0 +1,20 @@
1
+ # vim: filetype=ruby, fileencoding=UTF-8, tabsize=2, shiftwidth=2
2
+
3
+ libdir = File.expand_path(File.dirname __FILE__).gsub(/(.*lib).*?/, '\1')
4
+ $LOAD_PATH.unshift libdir unless $LOAD_PATH.include? libdir
5
+
6
+ require 'boole/falsiness'
7
+
8
+ module Boole
9
+ module Extensions
10
+ module Core
11
+ module FalseClassExtensions
12
+ include Boole::Falsiness
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ class FalseClass
19
+ include Boole::Extensions::Core::FalseClassExtensions
20
+ end
@@ -0,0 +1,20 @@
1
+ # vim: filetype=ruby, fileencoding=UTF-8, tabsize=2, shiftwidth=2
2
+
3
+ libdir = File.expand_path(File.dirname __FILE__).gsub(/(.*lib).*?/, '\1')
4
+ $LOAD_PATH.unshift libdir unless $LOAD_PATH.include? libdir
5
+
6
+ require 'boole/falsiness'
7
+
8
+ module Boole
9
+ module Extensions
10
+ module Core
11
+ module NilClassExtensions
12
+ include Boole::Falsiness
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ class NilClass
19
+ include Boole::Extensions::Core::NilClassExtensions
20
+ end
@@ -0,0 +1,20 @@
1
+ # vim: filetype=ruby, fileencoding=UTF-8, tabsize=2, shiftwidth=2
2
+
3
+ libdir = File.expand_path(File.dirname __FILE__).gsub(/(.*lib).*?/, '\1')
4
+ $LOAD_PATH.unshift libdir unless $LOAD_PATH.include? libdir
5
+
6
+ require 'boole/truthiness'
7
+
8
+ module Boole
9
+ module Extensions
10
+ module Core
11
+ module ObjectExtensions
12
+ include Boole::Truthiness
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ class Object
19
+ include Boole::Extensions::Core::ObjectExtensions
20
+ end
@@ -0,0 +1,20 @@
1
+ # vim: filetype=ruby, fileencoding=UTF-8, tabsize=2, shiftwidth=2
2
+
3
+ libdir = File.expand_path(File.dirname __FILE__).gsub(/(.*lib).*?/, '\1')
4
+ $LOAD_PATH.unshift libdir unless $LOAD_PATH.include? libdir
5
+
6
+ require 'boole/truthiness'
7
+
8
+ module Boole
9
+ module Extensions
10
+ module Core
11
+ module TrueClassExtensions
12
+ include Boole::Truthiness
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ class TrueClass
19
+ include Boole::Extensions::Core::TrueClassExtensions
20
+ end
@@ -0,0 +1,35 @@
1
+ # vim: filetype=ruby, fileencoding=UTF-8, tabsize=2, shiftwidth=2
2
+
3
+ libdir = File.expand_path(File.dirname __FILE__).gsub(/(.*lib).*?/, '\1')
4
+ $LOAD_PATH.unshift libdir unless $LOAD_PATH.include? libdir
5
+
6
+ module Boole
7
+ module Falsiness
8
+ def if
9
+ end
10
+
11
+ def ifelse _ = nil, else_branch = ->() {}
12
+ else_branch.call
13
+ end
14
+
15
+ def unless
16
+ yield if block_given?
17
+ end
18
+
19
+ def unlesselse unless_branch = ->() {}, _ = nil
20
+ ifelse _, unless_branch
21
+ end
22
+
23
+ def and
24
+ self
25
+ end
26
+
27
+ def or
28
+ yield
29
+ end
30
+
31
+ def not
32
+ true
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,35 @@
1
+ # vim: filetype=ruby, fileencoding=UTF-8, tabsize=2, shiftwidth=2
2
+
3
+ libdir = File.expand_path(File.dirname __FILE__).gsub(/(.*lib).*?/, '\1')
4
+ $LOAD_PATH.unshift libdir unless $LOAD_PATH.include? libdir
5
+
6
+ module Boole
7
+ module Truthiness
8
+ def if
9
+ yield if block_given?
10
+ end
11
+
12
+ def ifelse then_branch = ->() {}, _ = nil
13
+ then_branch.call
14
+ end
15
+
16
+ def unless
17
+ end
18
+
19
+ def unlesselse _ = nil, else_branch = ->() {}
20
+ ifelse else_branch, _
21
+ end
22
+
23
+ def and
24
+ yield
25
+ end
26
+
27
+ def or
28
+ self
29
+ end
30
+
31
+ def not
32
+ false
33
+ end
34
+ end
35
+ end
data/spec/LICENSE.txt ADDED
@@ -0,0 +1,26 @@
1
+ The specs were originally ported and heavily modified from the
2
+ RubySpec project <http://RubySpec.Org/>. This is the original
3
+ license:
4
+
5
+ Copyright (c) 2008 Engine Yard, Inc. All rights reserved.
6
+
7
+ Permission is hereby granted, free of charge, to any person
8
+ obtaining a copy of this software and associated documentation
9
+ files (the "Software"), to deal in the Software without
10
+ restriction, including without limitation the rights to use,
11
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the
13
+ Software is furnished to do so, subject to the following
14
+ conditions:
15
+
16
+ The above copyright notice and this permission notice shall be
17
+ included in all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26
+ OTHER DEALINGS IN THE SOFTWARE.
data/spec/and_spec.rb ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby1.9
2
+ # vim: filetype=ruby, fileencoding=UTF-8, tabsize=2, shiftwidth=2
3
+
4
+ require File.expand_path File.join(File.dirname(__FILE__), 'spec_helper')
5
+
6
+ require 'boole'
7
+
8
+ describe "The 'and' operator" do
9
+ it 'short-circuits evaluation at the first condition to be false' do
10
+ x = nil
11
+ true.and { false.and { x = 1 } }
12
+ x.must_be_nil
13
+ end
14
+
15
+ it 'evaluates to the first condition not to be true' do
16
+ (:yes.and { 1.and { nil.and { true } } }).must_be_nil
17
+ (:yes.and { 1.and { false.and { true } } }).must_equal false
18
+ end
19
+
20
+ it 'evaluates to the last condition if all are true' do
21
+ (:yes.and { 1 }).must_equal 1
22
+ (1.and { :yes }).must_equal :yes
23
+ end
24
+
25
+ it 'evaluates the full set of chained conditions during assignment' do
26
+ x, y = nil
27
+ x = 1.and { y = 2 }
28
+ # "1 && y = 2" is evaluated and then assigned to x
29
+ x.must_equal 2
30
+ end
31
+
32
+ it 'when used in assignment, evaluates and assigns expressions individually' do
33
+ x, y = nil
34
+ (x = 1).and { y = 2 }
35
+ # evaluates (x=1) and (y=2)
36
+ x.must_equal 1
37
+ end
38
+ end
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby1.9
2
+ # vim: filetype=ruby, fileencoding=UTF-8, tabsize=2, shiftwidth=2
3
+
4
+ specdir = File.expand_path(File.dirname __FILE__).gsub(/(.*spec).*?/, '\1')
5
+ $LOAD_PATH.unshift specdir unless $LOAD_PATH.include? specdir
6
+
7
+ require 'spec_helper'
8
+
9
+ Dir[File.join specdir, '**', '*_spec.rb'].each { |spec| require spec }
data/spec/if_spec.rb ADDED
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env ruby1.9
2
+ # vim: filetype=ruby, fileencoding=UTF-8, tabsize=2, shiftwidth=2
3
+
4
+ require File.expand_path File.join(File.dirname(__FILE__), 'spec_helper')
5
+
6
+ require 'boole'
7
+
8
+ describe 'The if expression' do
9
+ before do
10
+ @result = []
11
+ end
12
+
13
+ it 'evaluates body if expression is true' do
14
+ true.if { @result << 123 }
15
+ @result.must_equal [123]
16
+ end
17
+
18
+ it 'does not evaluate body if expression is false' do
19
+ false.if { @result << 123 }
20
+ @result.must_equal []
21
+ end
22
+
23
+ it 'does not evaluate else-body if expression is true' do
24
+ true.ifelse ->() { @result << 123 }, ->() { @result << 456 }
25
+ @result.must_equal [123]
26
+ end
27
+
28
+ it 'evaluates only else-body if expression is false' do
29
+ false.ifelse ->() { @result << 123 }, ->() { @result << 456 }
30
+ @result.must_equal [456]
31
+ end
32
+
33
+ it 'returns result of then-body evaluation if expression is true' do
34
+ true.if { 123 }.must_equal 123
35
+ end
36
+
37
+ it 'returns result of last statement in then-body if expression is true' do
38
+ true.if do
39
+ :foo
40
+ :bar
41
+ end.must_equal :bar
42
+ end
43
+
44
+ it 'returns result of then-body evaluation if expression is true and else part is present' do
45
+ true.ifelse(->() { 123 }, ->() { 456 }).must_equal 123
46
+ end
47
+
48
+ it 'returns result of else-body evaluation if expression is false' do
49
+ false.ifelse(->() { 123 }, ->() { 456 }).must_equal 456
50
+ end
51
+
52
+ it 'returns nil if then-body is empty and expression is true' do
53
+ true.if.must_be_nil
54
+ end
55
+
56
+ it 'returns nil if then-body is empty, expression is true and else part is present' do
57
+ true.ifelse(->() {}, ->() { 456 }).must_be_nil
58
+ end
59
+
60
+ it 'returns nil if then-body is empty, expression is true and else part is empty' do
61
+ true.ifelse.must_be_nil
62
+ end
63
+
64
+ it 'returns nil if else-body is empty and expression is false' do
65
+ false.ifelse(->() { 123 }).must_be_nil
66
+ end
67
+
68
+ it 'returns nil if else-body is empty, expression is false and then-body is empty' do
69
+ false.ifelse.must_be_nil
70
+ end
71
+
72
+ it 'considers an expression with nil result as false' do
73
+ nil.ifelse(->() { 123 }, ->() { 456 }).must_equal 456
74
+ end
75
+
76
+ it 'considers a non-nil and non-boolean object in expression result as true' do
77
+ MiniTest::Mock.new.ifelse(->() { 123 }, ->() { 456 }).must_equal 123
78
+ end
79
+
80
+ it 'considers a zero integer in expression result as true' do
81
+ 0.ifelse(->() { 123 }, ->() { 456 }).must_equal 123
82
+ end
83
+
84
+ it 'evaluates subsequent elsif statements and execute body of first matching' do
85
+ false.ifelse(->() { 123 }, ->() { false.ifelse ->() { 234 }, ->() { true.ifelse ->() { 345 }, ->() { true.if { 456 } } } }).must_equal 345
86
+ end
87
+
88
+ it 'evaluates else-body if no if/elsif statements match' do
89
+ false.ifelse(->() { 123 }, ->() { false.ifelse ->() { 234 }, ->() { false.ifelse ->() { 345 }, ->() { 456 } } }).must_equal 456
90
+ end
91
+ end
data/spec/not_spec.rb ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby1.9
2
+ # vim: filetype=ruby, fileencoding=UTF-8, tabsize=2, shiftwidth=2
3
+
4
+ require File.expand_path File.join(File.dirname(__FILE__), 'spec_helper')
5
+
6
+ require 'boole'
7
+
8
+ describe "The 'not' operator" do
9
+ it 'turns false to true' do
10
+ false.not.must_equal true
11
+ end
12
+
13
+ it 'turns nil to true' do
14
+ nil.not.must_equal true
15
+ end
16
+
17
+ it 'turns true to false' do
18
+ true.not.must_equal false
19
+ end
20
+
21
+ it 'turns anything not nil to false' do
22
+ MiniTest::Mock.new.not.must_equal false
23
+ end
24
+ end
data/spec/or_spec.rb ADDED
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby1.9
2
+ # vim: filetype=ruby, fileencoding=UTF-8, tabsize=2, shiftwidth=2
3
+
4
+ require File.expand_path File.join(File.dirname(__FILE__), 'spec_helper')
5
+
6
+ require 'boole'
7
+
8
+ describe "The 'or' operator" do
9
+ it 'evaluates to true if any of its operands are true' do
10
+ (false.or { true.or { nil } }).if { @result = true }
11
+ @result.must_equal true
12
+ end
13
+
14
+ it 'evaluates to false if all of its operands are false' do
15
+ (false.or { nil }).if { @result = true }
16
+ @result.must_be_nil
17
+ end
18
+
19
+ it 'is evaluated before assignment operators' do
20
+ x = nil.or { true }
21
+ x.must_equal true
22
+ end
23
+
24
+ it 'is evaluated after variables are assigned' do
25
+ (x = nil).or { true }
26
+ x.must_be_nil
27
+ end
28
+ end
@@ -0,0 +1,11 @@
1
+ # vim: filetype=ruby, fileencoding=UTF-8, tabsize=2, shiftwidth=2
2
+
3
+ require 'minitest/spec'
4
+ require 'minitest/mock'
5
+ require 'minitest/autorun'
6
+
7
+ libdir = File.expand_path File.join(File.dirname(__FILE__), 'lib').gsub(/(.*)spec.*?/, '\1')
8
+ $LOAD_PATH.unshift libdir unless $LOAD_PATH.include? libdir
9
+
10
+ specdir = File.expand_path(File.dirname __FILE__).gsub(/(.*spec).*?/, '\1')
11
+ $LOAD_PATH.unshift specdir unless $LOAD_PATH.include? specdir
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby1.9
2
+ # vim: filetype=ruby, fileencoding=UTF-8, tabsize=2, shiftwidth=2
3
+
4
+ require File.expand_path File.join(File.dirname(__FILE__), 'spec_helper')
5
+
6
+ require 'boole'
7
+
8
+ describe 'The unless expression' do
9
+ it 'evaluates the unless body when the expression is false' do
10
+ false.unlesselse ->() { @result = true }, ->() { @result = false }
11
+ @result.must_equal true
12
+ end
13
+
14
+ it 'returns the last statement in the body' do
15
+ false.unless do
16
+ :foo
17
+ :bar
18
+ end.must_equal :bar
19
+ end
20
+
21
+ it 'evaluates the else body when the expression is true' do
22
+ true.unlesselse(->() { :foo }, ->() { :bar }).must_equal :bar
23
+ end
24
+
25
+ it 'does not return a value when the expression is true' do
26
+ true.unless.must_be_nil
27
+ end
28
+ end
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env rake1.9
2
+ # vim: filetype=ruby, fileencoding=UTF-8, tabsize=2, shiftwidth=2
3
+
4
+ require 'rake'
5
+
6
+ taskdir = File.expand_path(File.dirname __FILE__).gsub(/(.*tasks).*?/, '\1')
7
+ $LOAD_PATH.unshift taskdir unless $LOAD_PATH.include? taskdir
8
+
9
+ task :default => :spec
data/tasks/gem_task.rb ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env rake1.9
2
+ # vim: filetype=ruby, fileencoding=UTF-8, tabsize=2, shiftwidth=2
3
+
4
+ require 'rake'
5
+ require 'rake/gempackagetask'
6
+ require 'rubygems'
7
+
8
+ taskdir = File.expand_path(File.dirname __FILE__).gsub(/(.*tasks).*?/, '\1')
9
+ $LOAD_PATH.unshift taskdir unless $LOAD_PATH.include? taskdir
10
+
11
+ basedir = File.expand_path File.join(taskdir, '..')
12
+ $LOAD_PATH.unshift basedir unless $LOAD_PATH.include? basedir
13
+
14
+ load Dir[File.expand_path File.join(basedir, '*.gemspec')].first
15
+
16
+ Rake::GemPackageTask.new($spec) do |pkg|
17
+ pkg.need_tar = true
18
+ pkg.need_tar_gz = true
19
+ pkg.need_tar_bz2 = true
20
+ pkg.need_zip = true
21
+ end
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env rake1.9
2
+ # vim: filetype=ruby, fileencoding=UTF-8, tabsize=2, shiftwidth=2
3
+
4
+ require 'rake'
5
+
6
+ taskdir = File.expand_path(File.dirname __FILE__).gsub(/(.*tasks).*?/, '\1')
7
+ $LOAD_PATH.unshift taskdir unless $LOAD_PATH.include? taskdir
8
+
9
+ desc 'Run the Specs'
10
+ task :spec do
11
+ FileList[File.join taskdir, '..', 'spec', '**', '*_suite.rb'].each { |specsuite| require specsuite }
12
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: JoergWMittag-boole
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - "J\xC3\xB6rg W Mittag"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-22 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: "--- !ruby/exception:SecurityError message: Insecure operation - gem_original_require"
17
+ email: JoergWMittag+Boole@GoogleMail.Com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - boole.gemspec
26
+ - lib/boole
27
+ - lib/boole/extensions
28
+ - lib/boole/extensions/core
29
+ - lib/boole/extensions/core/false_class_extensions.rb
30
+ - lib/boole/extensions/core/nil_class_extensions.rb
31
+ - lib/boole/extensions/core/object_extensions.rb
32
+ - lib/boole/extensions/core/true_class_extensions.rb
33
+ - lib/boole/falsiness.rb
34
+ - lib/boole/truthiness.rb
35
+ - lib/boole.rb
36
+ - LICENSE.txt
37
+ - Rakefile.rb
38
+ - README.rst
39
+ - spec/and_spec.rb
40
+ - spec/boole_suite.rb
41
+ - spec/if_spec.rb
42
+ - spec/LICENSE.txt
43
+ - spec/not_spec.rb
44
+ - spec/or_spec.rb
45
+ - spec/spec_helper.rb
46
+ - spec/unless_spec.rb
47
+ - tasks/gem_task.rb
48
+ - tasks/spec_task.rb
49
+ - tasks/_default_task.rb
50
+ has_rdoc: false
51
+ homepage: https://JoergWMittag.GitHub.Com/Boole/
52
+ post_install_message:
53
+ rdoc_options: []
54
+
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.9.1
62
+ version:
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ version:
69
+ requirements: []
70
+
71
+ rubyforge_project: boole
72
+ rubygems_version: 1.2.0
73
+ signing_key:
74
+ specification_version: 2
75
+ summary: "Exception = #<SecurityError: Insecure operation - gem_original_require>"
76
+ test_files:
77
+ - spec/and_spec.rb
78
+ - spec/boole_suite.rb
79
+ - spec/if_spec.rb
80
+ - spec/LICENSE.txt
81
+ - spec/not_spec.rb
82
+ - spec/or_spec.rb
83
+ - spec/spec_helper.rb
84
+ - spec/unless_spec.rb