if 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/if.rb +1 -1
  3. data/spec/if_spec.rb +24 -22
  4. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 48f4dc2f902936d9e33d8dbd8b5ac638de6cb812
4
- data.tar.gz: 537cdc652b31d2b68cbe2380d2416e4d4e36bdda
3
+ metadata.gz: 0638f3a18630bbc0ff3f75dedbdd2eaf0479e8c8
4
+ data.tar.gz: 5f28eea0d2d53de6df401a8f8389b2a19b9dedd9
5
5
  SHA512:
6
- metadata.gz: f9bfba1de91f2f086b3d6026f5751df343c317d74e3a15c6e288ff169945a6f64d1e373335cf6b7fae5fe5f086c538d5fa82bc89290fba483f005bcb03e47d18
7
- data.tar.gz: 6f9b97f3d2619ebc8a3eaa33e3c06f94574ae7c1a0a062f541f9a48ce03908c3e0c4bbe8794ad8d3d956898cd251f9b85efcefde6afa365e2949b0d8c566c09d
6
+ metadata.gz: e4b65ac816967ccdbacba2746f2e3b5b12dbd4a45b54df8e65e07a1f4191c75aeb275a0025fbf623ea7f9704ba356432a356d27371d39abcbc6e9dd5644809c4
7
+ data.tar.gz: 4c354d60a9c8e1637b2d3dcfa587cb03c04ce8b29f98baed61c675d6a82e291642e99b8d60fc618ade7238f2630ff12839960f58fd4b3b0c9e1bbdd1e65166a1
data/lib/if.rb CHANGED
@@ -16,7 +16,7 @@ end
16
16
 
17
17
  module Falsey
18
18
  def if(_if_true, options = {})
19
- if_false = options.fetch(:else, -> {})
19
+ if_false = options.fetch(:else, proc {})
20
20
 
21
21
  if_false.call
22
22
  end
@@ -5,19 +5,20 @@ RSpec.describe BasicObject do
5
5
 
6
6
  describe '#if' do
7
7
  it 'always evaluates the first block to if' do
8
- expect(object.if(-> { "I'm true!" })).to eq("I'm true!")
8
+ expect(object.if proc { "I'm true!" }).to eq("I'm true!")
9
9
  end
10
10
 
11
11
  it 'ignores any else blocks' do
12
- expect(object.if(-> { "I'm true!" },
13
- else: -> { "I'm false!" })).to eq("I'm true!")
12
+ expect(object.if proc { "I'm true!" },
13
+ :else => proc { "I'm false!" }).to eq("I'm true!")
14
14
  end
15
15
  end
16
16
 
17
17
  describe '#if_true' do
18
18
  it 'evaluates the given block' do
19
- expect { object.if_true { puts "I'm true!" } }
20
- .to output("I'm true!\n").to_stdout
19
+ expect {
20
+ object.if_true { puts "I'm true!" }
21
+ }.to output("I'm true!\n").to_stdout
21
22
  end
22
23
 
23
24
  it 'returns the object for chaining' do
@@ -33,9 +34,9 @@ RSpec.describe BasicObject do
33
34
 
34
35
  describe 'chaining #if_true and #if_false' do
35
36
  it 'evaluates based on the original object' do
36
- expect { object.if_true { puts "I'm true!"; false }
37
- .if_false { puts "I'm false!" } }
38
- .to output("I'm true!\n").to_stdout
37
+ expect {
38
+ object.if_true { puts "I'm true!"; false }.if_false { puts "I'm false!" }
39
+ }.to output("I'm true!\n").to_stdout
39
40
  end
40
41
  end
41
42
  end
@@ -43,12 +44,12 @@ end
43
44
  RSpec.describe NilClass do
44
45
  describe '#if' do
45
46
  it 'always returns the else block' do
46
- expect(nil.if(-> { "I'm true!" },
47
- else: -> { "I'm false!" })).to eq("I'm false!")
47
+ expect(nil.if proc { "I'm true!" },
48
+ :else => proc { "I'm false!" }).to eq("I'm false!")
48
49
  end
49
50
 
50
51
  it 'does nothing by default' do
51
- expect(nil.if(-> { "I'm true!" })).to be_nil
52
+ expect(nil.if proc { "I'm true!" }).to be_nil
52
53
  end
53
54
  end
54
55
 
@@ -60,8 +61,9 @@ RSpec.describe NilClass do
60
61
 
61
62
  describe '#if_false' do
62
63
  it 'evaluates the given block' do
63
- expect { nil.if_false { puts "I'm false!" } }
64
- .to output("I'm false!\n").to_stdout
64
+ expect {
65
+ nil.if_false { puts "I'm false!" }
66
+ }.to output("I'm false!\n").to_stdout
65
67
  end
66
68
 
67
69
  it 'returns nil' do
@@ -71,9 +73,9 @@ RSpec.describe NilClass do
71
73
 
72
74
  describe 'chaining #if_false and #if_true' do
73
75
  it 'evaluates based on the original object' do
74
- expect { nil.if_false { puts "I'm false!"; true }
75
- .if_true { puts "I'm true!" } }
76
- .to output("I'm false!\n").to_stdout
76
+ expect {
77
+ nil.if_false { puts "I'm false!"; true }.if_true { puts "I'm true!" }
78
+ }.to output("I'm false!\n").to_stdout
77
79
  end
78
80
  end
79
81
  end
@@ -81,12 +83,12 @@ end
81
83
  RSpec.describe FalseClass do
82
84
  describe '#if' do
83
85
  it 'always returns the else block' do
84
- expect(false.if(-> { "I'm true!" },
85
- else: -> { "I'm false!" })).to eq("I'm false!")
86
+ expect(false.if proc { "I'm true!" },
87
+ :else => proc { "I'm false!" }).to eq("I'm false!")
86
88
  end
87
89
 
88
90
  it 'does nothing by default' do
89
- expect(false.if(-> { "I'm true!" })).to be_nil
91
+ expect(false.if proc { "I'm true!" }).to be_nil
90
92
  end
91
93
  end
92
94
 
@@ -108,9 +110,9 @@ RSpec.describe FalseClass do
108
110
 
109
111
  describe 'chaining #if_false and #if_true' do
110
112
  it 'evaluates based on the original object' do
111
- expect { nil.if_false { puts "I'm false!"; true }
112
- .if_true { puts "I'm true!" } }
113
- .to output("I'm false!\n").to_stdout
113
+ expect {
114
+ nil.if_false { puts "I'm false!"; true }.if_true { puts "I'm true!" }
115
+ }.to output("I'm false!\n").to_stdout
114
116
  end
115
117
  end
116
118
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: if
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Mucur
@@ -35,7 +35,8 @@ files:
35
35
  - spec/if_spec.rb
36
36
  - spec/spec_helper.rb
37
37
  homepage: https://github.com/mudge/if
38
- licenses: []
38
+ licenses:
39
+ - MIT
39
40
  metadata: {}
40
41
  post_install_message:
41
42
  rdoc_options: []