b001e 0.0.0a → 0.0.1
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.
- data/README.rst +3 -5
- data/Rakefile.rb +7 -2
- data/b001e.gemspec +1 -1
- data/lib/b001e.rb +0 -3
- data/lib/b001e/extensions/core/false_class_extensions.rb +0 -3
- data/lib/b001e/extensions/core/nil_class_extensions.rb +0 -3
- data/lib/b001e/extensions/core/object_extensions.rb +0 -3
- data/lib/b001e/extensions/core/true_class_extensions.rb +0 -3
- data/lib/b001e/falsiness.rb +2 -5
- data/lib/b001e/truthiness.rb +3 -6
- data/spec/and_spec.rb +1 -2
- data/spec/b001e_suite.rb +0 -1
- data/spec/if_spec.rb +12 -13
- data/spec/unless_spec.rb +3 -4
- data/tasks/_default_task.rb +0 -3
- data/tasks/gem_task.rb +0 -3
- data/tasks/spec_task.rb +2 -2
- metadata +2 -2
data/README.rst
CHANGED
@@ -39,7 +39,7 @@ Operator / keyword style::
|
|
39
39
|
|
40
40
|
becomes::
|
41
41
|
|
42
|
-
c1.and { c2 }.ifelse ->
|
42
|
+
c1.and { c2 }.ifelse ->{ t }, ->{ c3.ifelse ->{ ei }, ->{ e } }
|
43
43
|
|
44
44
|
.. _Smalltalk: http://Smalltalk.Org/
|
45
45
|
|
@@ -81,21 +81,19 @@ Installation
|
|
81
81
|
|
82
82
|
::
|
83
83
|
|
84
|
-
gem install
|
84
|
+
gem install b001e
|
85
85
|
|
86
86
|
Usage
|
87
87
|
=====
|
88
88
|
|
89
89
|
::
|
90
90
|
|
91
|
-
begin require 'rubygems'; rescue LoadError
|
92
|
-
else begin gem 'JoergWMittag-b001e', '~> 0.0.3'; rescue Gem::LoadError; end end
|
93
91
|
require 'b001e'
|
94
92
|
|
95
93
|
true.and { nil.or { 42 } }.if { puts "It's true!" }
|
96
94
|
# Equivalent to: if true && (nil || 42) then puts "It's true!" end
|
97
95
|
|
98
|
-
false.ifelse ->
|
96
|
+
false.ifelse ->{ puts "You'll never see this." }, ->{ puts 'But this!' }
|
99
97
|
# Equivalent to: if false then puts "You'll never see this." else puts 'But this!' end
|
100
98
|
|
101
99
|
Acknowledgements
|
data/Rakefile.rb
CHANGED
@@ -6,7 +6,12 @@
|
|
6
6
|
|
7
7
|
require 'rake'
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
basedir = File.expand_path File.dirname(__FILE__)
|
10
|
+
taskdir = File.expand_path File.join(basedir, 'tasks')
|
11
|
+
specdir = File.expand_path File.join(basedir, 'spec')
|
12
|
+
libdir = File.expand_path File.join(basedir, 'lib')
|
13
|
+
|
14
|
+
$LOAD_PATH.unshift(specdir) unless $LOAD_PATH.include?(specdir)
|
15
|
+
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
11
16
|
|
12
17
|
FileList[File.join taskdir, '**', '*_task.rb'].each { |raketask| load raketask }
|
data/b001e.gemspec
CHANGED
@@ -34,7 +34,7 @@ speclist = filelist.grep /^spec/
|
|
34
34
|
$spec = Gem::Specification.new do |s|
|
35
35
|
s.name = 'b001e'
|
36
36
|
s.summary = 'Message-sending based re-implementation of the Boolean operators.'
|
37
|
-
s.version = Gem::Version.new '0.0.
|
37
|
+
s.version = Gem::Version.new '0.0.1'
|
38
38
|
s.author = 'Jörg W Mittag'
|
39
39
|
s.email = 'JoergWMittag+B001e@GoogleMail.Com'
|
40
40
|
s.homepage = 'http://JoergWMittag.GitHub.Com/b001e/'
|
data/lib/b001e.rb
CHANGED
@@ -3,9 +3,6 @@
|
|
3
3
|
#Copyright (c) 2009 Jörg W Mittag <JoergWMittag+B001e@GoogleMail.Com>
|
4
4
|
#This code is licensed under the terms of the MIT License (see LICENSE.txt)
|
5
5
|
|
6
|
-
libdir = File.expand_path(File.dirname __FILE__).gsub(/(.*lib).*?/, '\1')
|
7
|
-
$LOAD_PATH.unshift libdir unless $LOAD_PATH.include? libdir
|
8
|
-
|
9
6
|
require 'b001e/extensions/core/object_extensions'
|
10
7
|
require 'b001e/extensions/core/true_class_extensions'
|
11
8
|
require 'b001e/extensions/core/false_class_extensions'
|
@@ -3,9 +3,6 @@
|
|
3
3
|
#Copyright (c) 2009 Jörg W Mittag <JoergWMittag+B001e@GoogleMail.Com>
|
4
4
|
#This code is licensed under the terms of the MIT License (see LICENSE.txt)
|
5
5
|
|
6
|
-
libdir = File.expand_path(File.dirname __FILE__).gsub(/(.*lib).*?/, '\1')
|
7
|
-
$LOAD_PATH.unshift libdir unless $LOAD_PATH.include? libdir
|
8
|
-
|
9
6
|
require 'b001e/falsiness'
|
10
7
|
|
11
8
|
module B001e
|
@@ -3,9 +3,6 @@
|
|
3
3
|
#Copyright (c) 2009 Jörg W Mittag <JoergWMittag+B001e@GoogleMail.Com>
|
4
4
|
#This code is licensed under the terms of the MIT License (see LICENSE.txt)
|
5
5
|
|
6
|
-
libdir = File.expand_path(File.dirname __FILE__).gsub(/(.*lib).*?/, '\1')
|
7
|
-
$LOAD_PATH.unshift libdir unless $LOAD_PATH.include? libdir
|
8
|
-
|
9
6
|
require 'b001e/falsiness'
|
10
7
|
|
11
8
|
module B001e
|
@@ -3,9 +3,6 @@
|
|
3
3
|
#Copyright (c) 2009 Jörg W Mittag <JoergWMittag+B001e@GoogleMail.Com>
|
4
4
|
#This code is licensed under the terms of the MIT License (see LICENSE.txt)
|
5
5
|
|
6
|
-
libdir = File.expand_path(File.dirname __FILE__).gsub(/(.*lib).*?/, '\1')
|
7
|
-
$LOAD_PATH.unshift libdir unless $LOAD_PATH.include? libdir
|
8
|
-
|
9
6
|
require 'b001e/truthiness'
|
10
7
|
|
11
8
|
module B001e
|
@@ -3,9 +3,6 @@
|
|
3
3
|
#Copyright (c) 2009 Jörg W Mittag <JoergWMittag+B001e@GoogleMail.Com>
|
4
4
|
#This code is licensed under the terms of the MIT License (see LICENSE.txt)
|
5
5
|
|
6
|
-
libdir = File.expand_path(File.dirname __FILE__).gsub(/(.*lib).*?/, '\1')
|
7
|
-
$LOAD_PATH.unshift libdir unless $LOAD_PATH.include? libdir
|
8
|
-
|
9
6
|
require 'b001e/truthiness'
|
10
7
|
|
11
8
|
module B001e
|
data/lib/b001e/falsiness.rb
CHANGED
@@ -3,16 +3,13 @@
|
|
3
3
|
#Copyright (c) 2009 Jörg W Mittag <JoergWMittag+B001e@GoogleMail.Com>
|
4
4
|
#This code is licensed under the terms of the MIT License (see LICENSE.txt)
|
5
5
|
|
6
|
-
libdir = File.expand_path(File.dirname __FILE__).gsub(/(.*lib).*?/, '\1')
|
7
|
-
$LOAD_PATH.unshift libdir unless $LOAD_PATH.include? libdir
|
8
|
-
|
9
6
|
module B001e
|
10
7
|
module Falsiness
|
11
8
|
def if
|
12
9
|
end
|
13
10
|
|
14
|
-
def ifelse _ = nil, else_branch = ->
|
15
|
-
else_branch.
|
11
|
+
def ifelse _ = nil, else_branch = ->{}
|
12
|
+
else_branch.()
|
16
13
|
end
|
17
14
|
|
18
15
|
def unless
|
data/lib/b001e/truthiness.rb
CHANGED
@@ -3,23 +3,20 @@
|
|
3
3
|
#Copyright (c) 2009 Jörg W Mittag <JoergWMittag+B001e@GoogleMail.Com>
|
4
4
|
#This code is licensed under the terms of the MIT License (see LICENSE.txt)
|
5
5
|
|
6
|
-
libdir = File.expand_path(File.dirname __FILE__).gsub(/(.*lib).*?/, '\1')
|
7
|
-
$LOAD_PATH.unshift libdir unless $LOAD_PATH.include? libdir
|
8
|
-
|
9
6
|
module B001e
|
10
7
|
module Truthiness
|
11
8
|
def if
|
12
9
|
yield
|
13
10
|
end
|
14
11
|
|
15
|
-
def ifelse then_branch = ->
|
16
|
-
then_branch.
|
12
|
+
def ifelse then_branch = ->{}, _ = nil
|
13
|
+
then_branch.()
|
17
14
|
end
|
18
15
|
|
19
16
|
def unless
|
20
17
|
end
|
21
18
|
|
22
|
-
def unlesselse _ = nil, else_branch = ->
|
19
|
+
def unlesselse _ = nil, else_branch = ->{}
|
23
20
|
ifelse else_branch, _
|
24
21
|
end
|
25
22
|
|
data/spec/and_spec.rb
CHANGED
@@ -4,8 +4,7 @@
|
|
4
4
|
#Copyright (c) 2008 Engine Yard, Inc. All rights reserved.
|
5
5
|
#This code was directly ported from <https://GitHub.Com/RubySpec/RubySpec/tree/master/language/and_spec.rb>
|
6
6
|
|
7
|
-
require
|
8
|
-
|
7
|
+
require 'spec_helper'
|
9
8
|
require 'b001e'
|
10
9
|
|
11
10
|
describe "The 'and' operator" do
|
data/spec/b001e_suite.rb
CHANGED
data/spec/if_spec.rb
CHANGED
@@ -4,8 +4,7 @@
|
|
4
4
|
#Copyright (c) 2008 Engine Yard, Inc. All rights reserved.
|
5
5
|
#This code was directly ported from <https://GitHub.Com/RubySpec/RubySpec/tree/master/language/if_spec.rb>
|
6
6
|
|
7
|
-
require
|
8
|
-
|
7
|
+
require 'spec_helper'
|
9
8
|
require 'b001e'
|
10
9
|
|
11
10
|
describe 'The if expression' do
|
@@ -24,12 +23,12 @@ describe 'The if expression' do
|
|
24
23
|
end
|
25
24
|
|
26
25
|
it 'does not evaluate else-body if expression is true' do
|
27
|
-
true.ifelse ->
|
26
|
+
true.ifelse ->{ @result << 123 }, ->{ @result << 456 }
|
28
27
|
@result.must_equal [123]
|
29
28
|
end
|
30
29
|
|
31
30
|
it 'evaluates only else-body if expression is false' do
|
32
|
-
false.ifelse ->
|
31
|
+
false.ifelse ->{ @result << 123 }, ->{ @result << 456 }
|
33
32
|
@result.must_equal [456]
|
34
33
|
end
|
35
34
|
|
@@ -45,11 +44,11 @@ describe 'The if expression' do
|
|
45
44
|
end
|
46
45
|
|
47
46
|
it 'returns result of then-body evaluation if expression is true and else part is present' do
|
48
|
-
true.ifelse(->
|
47
|
+
true.ifelse(->{ 123 }, ->{ 456 }).must_equal 123
|
49
48
|
end
|
50
49
|
|
51
50
|
it 'returns result of else-body evaluation if expression is false' do
|
52
|
-
false.ifelse(->
|
51
|
+
false.ifelse(->{ 123 }, ->{ 456 }).must_equal 456
|
53
52
|
end
|
54
53
|
|
55
54
|
it 'returns nil if then-body is empty and expression is true' do
|
@@ -57,7 +56,7 @@ describe 'The if expression' do
|
|
57
56
|
end
|
58
57
|
|
59
58
|
it 'returns nil if then-body is empty, expression is true and else part is present' do
|
60
|
-
true.ifelse(->
|
59
|
+
true.ifelse(->{}, ->{ 456 }).must_be_nil
|
61
60
|
end
|
62
61
|
|
63
62
|
it 'returns nil if then-body is empty, expression is true and else part is empty' do
|
@@ -65,7 +64,7 @@ describe 'The if expression' do
|
|
65
64
|
end
|
66
65
|
|
67
66
|
it 'returns nil if else-body is empty and expression is false' do
|
68
|
-
false.ifelse(->
|
67
|
+
false.ifelse(->{ 123 }).must_be_nil
|
69
68
|
end
|
70
69
|
|
71
70
|
it 'returns nil if else-body is empty, expression is false and then-body is empty' do
|
@@ -73,22 +72,22 @@ describe 'The if expression' do
|
|
73
72
|
end
|
74
73
|
|
75
74
|
it 'considers an expression with nil result as false' do
|
76
|
-
nil.ifelse(->
|
75
|
+
nil.ifelse(->{ 123 }, ->{ 456 }).must_equal 456
|
77
76
|
end
|
78
77
|
|
79
78
|
it 'considers a non-nil and non-boolean object in expression result as true' do
|
80
|
-
MiniTest::Mock.new.ifelse(->
|
79
|
+
MiniTest::Mock.new.ifelse(->{ 123 }, ->{ 456 }).must_equal 123
|
81
80
|
end
|
82
81
|
|
83
82
|
it 'considers a zero integer in expression result as true' do
|
84
|
-
0.ifelse(->
|
83
|
+
0.ifelse(->{ 123 }, ->{ 456 }).must_equal 123
|
85
84
|
end
|
86
85
|
|
87
86
|
it 'evaluates subsequent elsif statements and execute body of first matching' do
|
88
|
-
false.ifelse(->
|
87
|
+
false.ifelse(->{ 123 }, ->{ false.ifelse ->{ 234 }, ->{ true.ifelse ->{ 345 }, ->{ true.if { 456 } } } }).must_equal 345
|
89
88
|
end
|
90
89
|
|
91
90
|
it 'evaluates else-body if no if/elsif statements match' do
|
92
|
-
false.ifelse(->
|
91
|
+
false.ifelse(->{ 123 }, ->{ false.ifelse ->{ 234 }, ->{ false.ifelse ->{ 345 }, ->{ 456 } } }).must_equal 456
|
93
92
|
end
|
94
93
|
end
|
data/spec/unless_spec.rb
CHANGED
@@ -4,13 +4,12 @@
|
|
4
4
|
#Copyright (c) 2008 Engine Yard, Inc. All rights reserved.
|
5
5
|
#This code was directly ported from <https://GitHub.Com/RubySpec/RubySpec/tree/master/language/unless_spec.rb>
|
6
6
|
|
7
|
-
require
|
8
|
-
|
7
|
+
require 'spec_helper'
|
9
8
|
require 'b001e'
|
10
9
|
|
11
10
|
describe 'The unless expression' do
|
12
11
|
it 'evaluates the unless body when the expression is false' do
|
13
|
-
false.unlesselse ->
|
12
|
+
false.unlesselse ->{ @result = true }, ->{ @result = false }
|
14
13
|
@result.must_equal true
|
15
14
|
end
|
16
15
|
|
@@ -22,7 +21,7 @@ describe 'The unless expression' do
|
|
22
21
|
end
|
23
22
|
|
24
23
|
it 'evaluates the else body when the expression is true' do
|
25
|
-
true.unlesselse(->
|
24
|
+
true.unlesselse(->{ :foo }, ->{ :bar }).must_equal :bar
|
26
25
|
end
|
27
26
|
|
28
27
|
it 'does not return a value when the expression is true' do
|
data/tasks/_default_task.rb
CHANGED
data/tasks/gem_task.rb
CHANGED
@@ -5,10 +5,7 @@ require 'rake'
|
|
5
5
|
require 'rake/gempackagetask'
|
6
6
|
|
7
7
|
taskdir = File.expand_path(File.dirname __FILE__).gsub(/(.*tasks).*?/, '\1')
|
8
|
-
$LOAD_PATH.unshift taskdir unless $LOAD_PATH.include? taskdir
|
9
|
-
|
10
8
|
basedir = File.expand_path File.join(taskdir, '..')
|
11
|
-
$LOAD_PATH.unshift basedir unless $LOAD_PATH.include? basedir
|
12
9
|
|
13
10
|
load Dir[File.expand_path File.join(basedir, '*.gemspec')].first
|
14
11
|
|
data/tasks/spec_task.rb
CHANGED
@@ -4,9 +4,9 @@
|
|
4
4
|
require 'rake'
|
5
5
|
|
6
6
|
taskdir = File.expand_path(File.dirname __FILE__).gsub(/(.*tasks).*?/, '\1')
|
7
|
-
|
7
|
+
specdir = File.expand_path(File.join(taskdir, '..', 'spec'))
|
8
8
|
|
9
9
|
desc 'Run the Specs'
|
10
10
|
task :spec do
|
11
|
-
FileList[File.join
|
11
|
+
FileList[File.join specdir, '**', '*_suite.rb'].each { |specsuite| require specsuite }
|
12
12
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: b001e
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "J\xC3\xB6rg W Mittag"
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-01-01 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|