attr_bool 0.2.2 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b0746e6bd74e2e6b5b07d6c910a13e18a97de02188f16b237ec810921e93aa97
4
- data.tar.gz: 6c071fb31a8ea5a63e8b875e7907259ae9b9694cc31d11ae9f6c503544e111f2
3
+ metadata.gz: c8c2838e4127813ba45ee36511d2ab27acbf336a7023dcfa88035b71164d9b01
4
+ data.tar.gz: 2d0af46054521a4fa83ae3d0aea20fd84bdb6da19b9a151087a81af34d2706f5
5
5
  SHA512:
6
- metadata.gz: a93798cf5ac76b8a181f9dff137255a93b59be01a92f02fb57723ba0ca9ffe1a3a6d470e03caaea067a20498c4338b2c1415c2fa015a25da9e04442763a74dee
7
- data.tar.gz: ce15f10ea56ea61fe14aaca334d521f84869386769f0ec97e50ec720c7ccf94f35f32d66860c1126c97c8319a7c03a2eb6e4fdd35ee9211e6dde7916a8f7b6e2
6
+ metadata.gz: 60d3d316e83c791256b8125742ef6e741452cf7a5de29b6162417629b1377f5358704b7fc7dfc1985fed20450e31d00a2797bddb81216110794691989080d2a6
7
+ data.tar.gz: 2ece3c6ecd679140f9f67c5087e653e960e74aa9651f3c98368cfb66a36a096ff2513c863f988e2f87d55e211c277f9682c591b95188909e4e4f858034b76423
data/.rdoc_options ADDED
@@ -0,0 +1,27 @@
1
+ ---
2
+ encoding: UTF-8
3
+ op_dir: doc
4
+ title: AttrBool
5
+ main_page: README.md
6
+
7
+ apply_default_exclude: true
8
+ embed_mixins: true
9
+ force_update: true
10
+ hyperlink_all: true
11
+ line_numbers: true
12
+ markup: markdown
13
+ show_hash: true
14
+ skip_tests: true
15
+
16
+ exclude:
17
+ - /.git/
18
+ - /.github/
19
+ - /.idea/
20
+ - /doc/
21
+ - /pkg/
22
+ - /spec/
23
+ - /stock/
24
+ - /test/
25
+ - Gemfile
26
+ - Gemfile.lock
27
+ - Rakefile
data/Gemfile CHANGED
@@ -1,7 +1,18 @@
1
1
  # encoding: UTF-8
2
2
  # frozen_string_literal: true
3
3
 
4
-
5
4
  source 'https://rubygems.org'
6
5
 
7
6
  gemspec
7
+
8
+ group(:development,:test) do
9
+ gem 'benchmark','~> 0.4 ' # For benchmarks in Rakefile.
10
+ gem 'bundler' ,'~> 2.6 '
11
+ gem 'rake' ,'~> 13.3 '
12
+ gem 'rdoc' ,'~> 6.14' # Doc.
13
+ gem 'simplecov','~> 0.22' # Test coverage.
14
+ end
15
+
16
+ group(:test) do
17
+ gem 'minitest','~> 5.25'
18
+ end
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020-2021 Jonathan Bradley Whited
3
+ Copyright (c) 2020-2025 Bradley Whited
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md ADDED
@@ -0,0 +1,307 @@
1
+ # AttrBool
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/attr_bool.svg)](https://badge.fury.io/rb/attr_bool)
4
+ [![Tests Status](https://github.com/esotericpig/attr_bool/actions/workflows/ruby.yml/badge.svg)](https://github.com/esotericpig/attr_bool/actions/workflows/ruby.yml)
5
+ [![Source Code](https://img.shields.io/badge/source-github-%23211F1F.svg)](https://github.com/esotericpig/attr_bool)
6
+ [![Changelog](https://img.shields.io/badge/changelog-md-%23A0522D.svg)](CHANGELOG.md)
7
+ [![License](https://img.shields.io/github/license/esotericpig/attr_bool.svg)](LICENSE.txt)
8
+
9
+ Easily create `attr` (attribute) methods that end with question marks (`?`) for booleans/predicates.
10
+
11
+ ```ruby
12
+ require 'attr_bool'
13
+
14
+ class TheTodd
15
+ extend AttrBool::Ext
16
+ #using AttrBool::Ref # Can use refinements instead.
17
+
18
+ attr_accessor? :headband
19
+ attr_reader? :banana_hammock
20
+ attr_writer? :high_five
21
+
22
+ # Can do DSL chaining.
23
+ protected attr_accessor? :carla_kiss, :elliot_kiss
24
+
25
+ # Can force bool values (i.e., only `true` or `false`).
26
+ attr_bool :bounce_pecs # Accessor.
27
+ attr_bool? :cat_fight # Reader.
28
+ attr_bool! :hot_tub # Writer.
29
+ end
30
+
31
+ todd = TheTodd.new
32
+
33
+ puts todd.headband?
34
+ puts todd.banana_hammock?
35
+ puts todd.bounce_pecs?
36
+ puts todd.cat_fight?
37
+ ```
38
+
39
+ Features:
40
+ - Can use multiple symbols and/or strings.
41
+ - Can force bool values.
42
+ - Can define custom logic with a block/proc.
43
+ - Can do DSL chaining, just like the core `attr` methods that return an array of the new method names.
44
+ - Can use refinements (`using AttrBool::Ref`) instead of `extend`.
45
+ - Fails fast if an instance variable name is invalid (if you don't use a block/proc).
46
+
47
+ Anti-features:
48
+ - No default values.
49
+ - Initialize your instance variables in `def initialize` like normal.
50
+ - Using default values has performance/memory issues and other drawbacks, so better to just match the core `attr` methods.
51
+ - Uses inner `AttrBool::Ext` & `AttrBool::Ref` instead of `AttrBool`.
52
+ - Some gems use the `extend AttrBool` (top module) pattern, but this includes `VERSION` in all of your classes/modules.
53
+ - Doesn't monkey-patch the core class/module by default.
54
+ - If desired for apps/scripts, you still can with `require 'attr_bool/core_ext'`, but not recommended for libraries.
55
+
56
+ ## // Contents
57
+
58
+ - [Similar Projects](#-similar-projects)
59
+ - [Setup](#-setup)
60
+ - [Usage](#-usage)
61
+ - [RuboCop](#-rubocop)
62
+ - [YARDoc](#-yardoc)
63
+ - [Hacking](#-hacking)
64
+ - [Benchmarks](#-benchmarks)
65
+ - [License](#-license)
66
+
67
+ ## [//](#-contents) Similar Projects
68
+
69
+ Create a [discussion](https://github.com/esotericpig/attr_bool/discussions) or an [issue](https://github.com/esotericpig/attr_bool/issues) to let me know to add your project.
70
+
71
+ | Gem Name | Code | Example |
72
+ |--------------------------------------------------------------------------|---------------------------------------------------------------|-----------------------------------------------------------|
73
+ | [attr_asker](https://rubygems.org/gems/attr_asker) | [GitHub](https://github.com/kitlangton/attr_asker) | `attr_asker :winning` |
74
+ | [attr_boolean](https://rubygems.org/gems/attr_boolean) | [GitHub](https://github.com/talentnest/attr_boolean) | `attr_boolean :winning, default: true` |
75
+ | [attr_setting](https://rubygems.org/gems/attr_setting) | [GitHub](https://github.com/merhard/attr_setting) | `attr_setting :winning, true` |
76
+ | [attribool](https://rubygems.org/gems/attribool) | [GitHub](https://github.com/evanthegrayt/attribool) | `bool_reader :winning` |
77
+ | [attribute_boolean](https://rubygems.org/gems/attribute_boolean) | [GitHub](https://github.com/alexmchale/attribute_boolean) | `attr_boolean :winning` |
78
+ | [attribute_predicates](https://rubygems.org/gems/attribute_predicates) | [GitHub](https://github.com/pluginaweek/attribute_predicates) | `attr :winning, true` |
79
+ | [boolean_accessor](https://rubygems.org/gems/boolean_accessor) | [GitHub](https://github.com/hiroki23/boolean_accessor) | `battr_accessor :winning` |
80
+ | [named_accessors](https://rubygems.org/gems/named_accessors) | [GitHub](https://github.com/zlw/named_accessors) | `named_reader :winning, as: :winning?` |
81
+ | [predicateable](https://rubygems.org/gems/predicateable) | [GitHub](https://github.com/nsgc/predicateable) | `predicate :wins, [:losing, :winning]` |
82
+ | [predicates](https://rubygems.org/gems/predicates) | [GitHub](https://github.com/Erol/predicates) | `predicate :winning?` |
83
+ | [property-accessor](https://rubygems.org/gems/property-accessor) | [GitHub](https://github.com/estepnv/property-accessor) | `property(:winning) { get(:winning?); default { true } }` |
84
+ | [question_mark_methods](https://rubygems.org/gems/question_mark_methods) | [GitHub](https://github.com/poiyzy/questionmarkmethods) | `add_question_mark_methods winning?: :winning` |
85
+ | [wannabe_bool](https://rubygems.org/gems/wannabe_bool) | [GitHub](https://github.com/prodis/wannabe_bool) | `attr_wannabe_bool :winning` |
86
+ | [wardrobe](https://rubygems.org/gems/wardrobe) | [GitHub](https://github.com/agensdev/wardrobe) | `attribute :winning, Wardrobe::Boolean, default: true` |
87
+
88
+ Searches:
89
+
90
+ | Site | Searches |
91
+ |------------------|--------------------------------------------------------------------------------------------------------------------------|
92
+ | The Ruby Toolbox | [1](https://www.ruby-toolbox.com/search?q=attr+bool), [2](https://www.ruby-toolbox.com/search?q=predicate) |
93
+ | RubyGems.org | [1](https://rubygems.org/search?query=attr+OR+attribute), [2](https://rubygems.org/search?query=predicates+OR+predicate) |
94
+
95
+ ## [//](#-contents) Setup
96
+
97
+ Pick your poison...
98
+
99
+ With the *RubyGems* package manager:
100
+
101
+ ```bash
102
+ gem install attr_bool
103
+ ```
104
+
105
+ Or in your *Gemspec*:
106
+
107
+ ```ruby
108
+ spec.add_dependency 'attr_bool', '~> X.X'
109
+ ```
110
+
111
+ Or in your *Gemfile*:
112
+
113
+ ```ruby
114
+ # Pick your poison...
115
+ gem 'attr_bool', '~> X.X'
116
+ gem 'attr_bool', git: 'https://github.com/esotericpig/attr_bool.git'
117
+ ```
118
+
119
+ Or from source:
120
+
121
+ ```bash
122
+ git clone --depth 1 'https://github.com/esotericpig/attr_bool.git'
123
+ cd attr_bool
124
+ bundle install
125
+ bundle exec rake install:local
126
+ ```
127
+
128
+ ## [//](#-contents) Usage
129
+
130
+ You can either add `extend AttrBool::Ext` in your class/module, add `using AttrBool::Ref` in your class/module, or include `require 'attr_bool/core_ext'`.
131
+
132
+ ```ruby
133
+ require 'attr_bool'
134
+
135
+ class TheTodd
136
+ extend AttrBool::Ext
137
+ #using AttrBool::Ref # Can use refinements instead.
138
+
139
+ # Can use multiple symbols and/or strings.
140
+ attr_accessor? :flexing, 'bounce_pecs'
141
+
142
+ # Can do DSL chaining.
143
+ protected attr_accessor? :high_five, 'fist_bump'
144
+
145
+ # Can do custom logic.
146
+ attr_accessor? :headband, 'banana_hammock',
147
+ reader: -> { @wearing == :flaming },
148
+ writer: ->(value) { @wearing = value }
149
+
150
+ attr_reader?(:cat_fights) { @cat_fights % 69 }
151
+ attr_writer?(:hot_surgeries) { |count| @hot_surgeries += count }
152
+
153
+ # Can force bool values (i.e., only `true` or `false`).
154
+ attr_bool :carla_kiss # Accessor.
155
+ attr_bool? :elliot_kiss # Reader.
156
+ attr_bool! :thumbs_up # Writer.
157
+ end
158
+ ```
159
+
160
+ If you don't want to have to add `extend AttrBool::Ext` to every inner class/module (within the same file), then you can simply refine the outer module or the file:
161
+
162
+ ```ruby
163
+ require 'attr_bool'
164
+
165
+ #using AttrBool::Ref # Can refine the entire file instead (doesn't affect other files).
166
+
167
+ module TheToddMod
168
+ using AttrBool::Ref
169
+
170
+ class TheTodd
171
+ attr_bool :banana_hammock
172
+ end
173
+
174
+ class TheToddBod
175
+ attr_bool :bounce_pecs
176
+ end
177
+ end
178
+ ```
179
+
180
+ If you only have an app/script (**not** a library), then you can simply include `require 'attr_bool/core_ext'` to monkey-patch the core class & module:
181
+
182
+ ```ruby
183
+ require 'attr_bool/core_ext'
184
+
185
+ class TheTodd
186
+ attr_bool :banana_hammock
187
+ end
188
+ ```
189
+
190
+ ### [///](#-contents) RuboCop
191
+
192
+ RuboCop might complain about `Layout/EmptyLinesAroundAttributeAccessor`:
193
+
194
+ ```ruby
195
+ class TheTodd
196
+ attr_accessor? :banana_hammock
197
+ attr_accessor :headband
198
+ attr_accessor? :bounce_pecs
199
+ end
200
+ ```
201
+
202
+ You can either disable this Cop or adjust it accordingly:
203
+
204
+ ```yaml
205
+ Layout/EmptyLinesAroundAttributeAccessor:
206
+ #Enabled: false
207
+ AllowedMethods:
208
+ - attr_accessor?
209
+ - attr_reader?
210
+ - attr_writer?
211
+ - attr_bool
212
+ - attr_bool?
213
+ - attr_bool!
214
+ ```
215
+
216
+ ### [///](#-contents) YARDoc
217
+
218
+ Here are some examples of how to document the methods in YARDoc:
219
+
220
+ ```ruby
221
+ attr_accessor? :winning # @!attribute [rw] winning=(value),winning?
222
+ attr_reader? :running # @!attribute [r] running?
223
+
224
+ # @!attribute [r] can_swim?
225
+ # @return [true,false] can you swim in it?
226
+ # @!attribute [r] can_wink?
227
+ # @return [true,false] can you wink at pretty people?
228
+ attr_reader? :can_swim,:can_wink
229
+
230
+ # @!attribute [rw] princess=(value),princess?
231
+ # @param value [true,false] this is Ms. Consuela or not!
232
+ # @return [true,false] is this Ms. Consuela?
233
+ # @!attribute [rw] crap_bag=(value),crap_bag?
234
+ # @param value [true,false] this is Mr. Crap Bag or not!
235
+ # @return [true,false] is this Mr. Crap Bag?
236
+ attr_accessor? :princess,:crap_bag
237
+
238
+ # @overload in_fashion?
239
+ # @return [true,false] whether it's fashionable right now
240
+ # @overload in_fashion=(value)
241
+ # Make it in or out of fashion!
242
+ attr_accessor? :in_fashion
243
+
244
+ # @!group My Attrs
245
+ # @!attribute [r] in_season?
246
+ attr_reader? :in_season
247
+ # @!attribute [r] can_wash?
248
+ attr_reader? :can_wash
249
+ # @!endgroup
250
+ ```
251
+
252
+ Further reading:
253
+
254
+ - [Documenting Attributes](https://www.rubydoc.info/gems/yard/file/docs/GettingStarted.md#documenting-attributes)
255
+ - [Documenting Custom DSL Methods](https://www.rubydoc.info/gems/yard/file/docs/GettingStarted.md#documenting-custom-dsl-methods)
256
+ - [Tags#Attribute](https://www.rubydoc.info/gems/yard/file/docs/Tags.md#attribute)
257
+ - [Macros](https://www.rubydoc.info/gems/yard/file/docs/GettingStarted.md#macros)
258
+ - [Tags#Macro](https://www.rubydoc.info/gems/yard/file/docs/Tags.md#macro)
259
+ - [Writing Handlers](https://yardoc.org/guides/extending-yard/writing-handlers.html)
260
+ - [YARD::Handlers::Ruby::AttributeHandler](https://github.com/lsegal/yard/blob/main/lib/yard/handlers/ruby/attribute_handler.rb)
261
+
262
+ ## [//](#-contents) Hacking
263
+
264
+ ```bash
265
+ git clone 'https://github.com/esotericpig/attr_bool.git'
266
+ cd attr_bool
267
+ bundle install
268
+ bundle exec rake -T
269
+ ```
270
+
271
+ Run tests:
272
+
273
+ ```bash
274
+ bundle exec rake test
275
+ ```
276
+
277
+ Generate doc:
278
+
279
+ ```bash
280
+ bundle exec rake doc
281
+ ```
282
+
283
+ Install locally:
284
+
285
+ ```bash
286
+ bundle exec rake install:local
287
+ ```
288
+
289
+ ### [///](#-contents) Benchmarks
290
+
291
+ Benchmarks are kind of meaningless, but after playing around with some, I found the following to be true on my system:
292
+ - `define_method()` is faster than `class/module_eval()`.
293
+ - `? true : false` (ternary operator) is faster than `!!` (surprisingly).
294
+
295
+ Therefore, AttrBool uses the "faster" ones found.
296
+
297
+ To run these on your system:
298
+
299
+ ```bash
300
+ bundle exec rake bench
301
+ ```
302
+
303
+ ## [//](#-contents) License
304
+
305
+ AttrBool (https://github.com/esotericpig/attr_bool)
306
+ Copyright (c) 2020-2025 Bradley Whited
307
+ [MIT License](LICENSE.txt)
data/Rakefile CHANGED
@@ -1,140 +1,144 @@
1
1
  # encoding: UTF-8
2
2
  # frozen_string_literal: true
3
3
 
4
-
5
4
  require 'bundler/gem_tasks'
6
5
 
6
+ require 'attr_bool/version'
7
7
  require 'benchmark'
8
8
  require 'rake/clean'
9
9
  require 'rake/testtask'
10
- require 'yard'
11
-
12
- require 'attr_bool/version'
10
+ require 'rdoc/task'
13
11
 
14
- CLEAN.exclude('{.git,stock}/**/*')
12
+ CLEAN.exclude('{.git,.github,.idea,stock}/**/*')
15
13
  CLOBBER.include('doc/')
16
14
 
17
- task default: [:test]
18
-
19
- desc 'Generate doc'
20
- task :doc,%i[] => %i[yard] do |task|
21
- # pass
22
- end
15
+ task default: %i[test]
23
16
 
24
- desc 'Generate doc for tests too'
25
- task :doc_test do |task|
26
- ENV['doctest'] = 'y'
17
+ desc 'Run all tests'
18
+ task test: %i[test:base test:core_ext]
27
19
 
28
- doc_task = Rake::Task[:doc]
20
+ TEST_DIR = 'test/**'
21
+ CORE_EXT_TEST = 'core_ext_test.rb'
29
22
 
30
- doc_task.reenable
31
- doc_task.invoke
23
+ namespace :test do
24
+ {
25
+ base: FileList["#{TEST_DIR}/*_test.rb"].exclude("**/#{CORE_EXT_TEST}"),
26
+ core_ext: FileList["#{TEST_DIR}/#{CORE_EXT_TEST}"],
27
+ }.each do |name,test_files|
28
+ Rake::TestTask.new(name) do |t|
29
+ t.libs = ['lib','test']
30
+ t.test_files = test_files
31
+ t.warning = true
32
+ t.verbose = false
33
+ end
34
+ end
32
35
  end
33
36
 
34
- Rake::TestTask.new do |task|
35
- task.deps << :doc_test
36
- task.libs = ['lib','test']
37
- task.pattern = File.join('test','**','*_test.rb')
38
- task.description += ": '#{task.pattern}'"
39
- task.verbose = false
40
- task.warning = true
37
+ RDoc::Task.new(:doc) do |t|
38
+ t.rdoc_dir = 'doc'
39
+ t.title = "AttrBool v#{AttrBool::VERSION}"
41
40
  end
42
41
 
43
- YARD::Rake::YardocTask.new do |task|
44
- task.files = [File.join('lib','**','*.{rb}')]
45
-
46
- #task.options += ['--template-path',File.join('yard','templates')]
47
- task.options += ['--title',"AttrBool v#{AttrBool::VERSION} doc"]
48
-
49
- task.before = proc do
50
- task.files << File.join('test','**','*.{rb}') if ENV['doctest'].to_s.casecmp?('y')
51
- end
42
+ # Benchmarks are kind of meaningless, but after playing around with some,
43
+ # I found the following to be true on my system:
44
+ # - define_method() is faster than class/module_eval().
45
+ # - `? true : false` (ternary operator) is faster than `!!` (surprisingly).
46
+ desc 'Benchmark code related to AttrBool'
47
+ task :bench do
48
+ bench_def_methods
49
+ bench_force_bools
50
+ puts
52
51
  end
53
52
 
54
- desc 'Benchmark define_method vs module_eval and ?: vs bangbang'
55
- task :benchmark do |task|
56
- # rubocop:disable all
53
+ def bench_def_methods
54
+ # rubocop:disable Style/DocumentDynamicEvalDefinition,Style/EvalWithLocation
57
55
 
58
- N0 = 100_000
59
- N1 = 20_000_000
56
+ n = 200_000
60
57
 
61
- module ModuleExt
62
- def do_class_eval(name)
63
- 0.upto(N0) do |i|
64
- n = "#{name}#{i}"
65
-
66
- class_eval("def #{n}?(); @#{n}; end")
58
+ puts
59
+ Benchmark.bmbm do |bm|
60
+ bm.report('class_eval ') do
61
+ Class.new do
62
+ n.times do |i|
63
+ name = "bool_#{i}"
64
+ class_eval("def #{name}?; @#{name}; end")
65
+ end
67
66
  end
68
67
  end
69
68
 
70
- def do_define_method(name)
71
- 0.upto(N0) do |i|
72
- n = "#{name}#{i}"
73
-
74
- define_method(:"#{n}?") do
75
- instance_variable_get(:"@#{n}")
69
+ bm.report('define_method') do
70
+ Class.new do
71
+ n.times do |i|
72
+ name = "bool_#{i}"
73
+ define_method(:"#{name}?") { instance_variable_get(:"@#{name}") }
76
74
  end
77
75
  end
78
76
  end
79
77
 
80
- def do_module_eval(name)
81
- 0.upto(N0) do |i|
82
- n = "#{name}#{i}"
83
-
84
- module_eval("def #{n}?(); @#{n}; end")
78
+ bm.report('module_eval ') do
79
+ Class.new do
80
+ n.times do |i|
81
+ name = "bool_#{i}"
82
+ module_eval("def #{name}?; @#{name}; end")
83
+ end
85
84
  end
86
85
  end
87
86
  end
88
87
 
89
- Module.prepend ModuleExt
88
+ # rubocop:enable all
89
+ end
90
+
91
+ def bench_force_bools
92
+ # rubocop:disable Style/DoubleNegation
93
+
94
+ n = 5_000_000
95
+ values = ['str',1,0,1.0,0.0,nil,true,false]
90
96
 
91
97
  puts
92
98
  Benchmark.bmbm do |bm|
93
- bm.report('class_eval ') do
94
- class ClassEvalTest
95
- do_class_eval :ce
96
- end
97
- end
98
-
99
- bm.report('define_method') do
100
- class DefineMethodTest
101
- do_define_method :dm
99
+ bm.report('?:') do
100
+ n.times do
101
+ x = nil
102
+ values.each do |value|
103
+ x = value ? true : false
104
+ end
105
+ x
102
106
  end
103
107
  end
104
108
 
105
- bm.report('module_eval ') do
106
- class ModuleEvalTest
107
- do_module_eval :me
109
+ bm.report('!!') do
110
+ n.times do
111
+ x = nil
112
+ values.each do |value|
113
+ x = !!value
114
+ end
115
+ x
108
116
  end
109
117
  end
110
118
  end
111
119
 
112
- str = 'str' # Warning workaround
113
-
114
120
  puts
115
121
  Benchmark.bmbm do |bm|
116
- bm.report('?:') do
117
- 0.upto(N1) do |i|
118
- x = str ? true : false
119
- x = nil ? true : false
120
- x = true ? true : false
121
- x = false ? true : false
122
- x = x ? true : false
122
+ bm.report('!!') do
123
+ n.times do
124
+ x = nil
125
+ values.each do |value|
126
+ x = !!value
127
+ end
128
+ x
123
129
  end
124
130
  end
125
131
 
126
- bm.report('!!') do
127
- 0.upto(N1) do |i|
128
- y = !!str
129
- y = !!nil
130
- y = !!true
131
- y = !!false
132
- y = !!y
132
+ bm.report('?:') do
133
+ n.times do
134
+ x = nil
135
+ values.each do |value|
136
+ x = value ? true : false
137
+ end
138
+ x
133
139
  end
134
140
  end
135
141
  end
136
142
 
137
- puts
138
-
139
143
  # rubocop:enable all
140
144
  end