booleans 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7c61a7f997b836a4c37f276700b566887f42243f5ce3328d61135b0efe1bb4db
4
+ data.tar.gz: dd31205816c376a2a2b5f75c1ae9b84417ea62fb8570306dfd0d7d70cf0bfc09
5
+ SHA512:
6
+ metadata.gz: 2174881be8926092026a7c69697d6987aecc536bfec11b7cd8013ed46e19aa0ec17596bcae18a1ea0211c1751bffaa278daf1e8d5eb525ae140647520333cfce
7
+ data.tar.gz: 1a8941ae0cc3c9c8e2a52b9dc68d1c842b07bf12616f6bd431db3fa8b1e315fe9a75c720808f9be0f7050659db7342e3d0361be701813c3ea2d08cb30ad34f55
data/.rubocop.yml ADDED
@@ -0,0 +1,14 @@
1
+ Style/StringLiterals:
2
+ Enabled: true
3
+ EnforcedStyle: double_quotes
4
+
5
+ Style/StringLiteralsInInterpolation:
6
+ Enabled: true
7
+ EnforcedStyle: double_quotes
8
+
9
+ Layout/LineLength:
10
+ Max: 120
11
+
12
+ AllCops:
13
+ SuggestExtensions: false
14
+ TargetRubyVersion: 3.0
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-10-20
4
+
5
+ - Initial release
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Mateusz Drewniak
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.md ADDED
@@ -0,0 +1,76 @@
1
+ # Booleans
2
+
3
+ This gem adds a new method called `Boolean`, analogous to builtins like `Integer` or `String`, which converts
4
+ a Ruby value to either `true` or `false` based on its truthiness.
5
+
6
+ It also has optional core extensions that add a `to_bool` method to all Ruby objects and allow you to check if a value is boolean with `val.is_a?(Boolean)`.
7
+
8
+ ## Installation
9
+
10
+ Install the gem and add to the application's Gemfile by executing:
11
+
12
+ $ bundle add booleans
13
+
14
+ If bundler is not being used to manage dependencies, install the gem by executing:
15
+
16
+ $ gem install booleans
17
+
18
+ ## Usage
19
+
20
+ Once you load the gem, you can use the `Boolean` method to convert objects to `true` or `false`.
21
+
22
+ ```rb
23
+ require 'booleans'
24
+
25
+ Boolean(5) #=> true
26
+ Boolean(0) #=> true
27
+ Boolean("foo") #=> true
28
+ Boolean("") #=> true
29
+ Boolean([]) #=> true
30
+ Boolean(nil) #=> false
31
+ Boolean(false) #=> false
32
+ ```
33
+
34
+ All values except `false` and `nil` get converted to `true`.
35
+
36
+ ### Core extensions
37
+
38
+ There is also an optional file you can load with core extensions.
39
+
40
+ This adds a new method `to_bool` to all Ruby objects.
41
+
42
+ ```rb
43
+ require 'booleans/core_extension'
44
+
45
+ 5.to_bool #=> true
46
+ 0.to_bool #=> true
47
+ "foo".to_bool #=> true
48
+ "".to_bool #=> true
49
+ [].to_bool #=> true
50
+ nil.to_bool #=> false
51
+ false.to_bool #=> false
52
+ ```
53
+
54
+ It also includes the `Boolean` module to `TrueClass` and `FalseClass`
55
+ which allows you to check if a value is a boolean like this.
56
+
57
+ ```rb
58
+ true.is_a?(Boolean) #=> true
59
+ false.is_a?(Boolean) #=> true
60
+ nil.is_a?(Boolean) #=> false
61
+ 5.is_a?(Boolean) #=> false
62
+ ```
63
+
64
+ ## Development
65
+
66
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
67
+
68
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
69
+
70
+ ## Contributing
71
+
72
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Verseth/ruby-booleans.
73
+
74
+ ## License
75
+
76
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/test_*.rb"]
10
+ end
11
+
12
+ require "rubocop/rake_task"
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: %i[test rubocop]
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../booleans"
4
+
5
+ module Boolean
6
+ # Contains additional methods that are added by
7
+ # the `booleans` gem to `Object`.
8
+ module CoreExtension
9
+ # Convert a Ruby value to `true` or `false`
10
+ # according to the truthiness of the value.
11
+ #
12
+ # Most Ruby objects get converted to `true` with the
13
+ # exception of: `nil` and `false`.
14
+ def to_bool
15
+ return true if self
16
+
17
+ false
18
+ end
19
+ end
20
+ end
21
+
22
+ Object.include(Boolean::CoreExtension)
23
+ TrueClass.include(Boolean)
24
+ FalseClass.include(Boolean)
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Booleans
4
+ # @return [String]
5
+ VERSION = "0.1.0"
6
+ end
data/lib/booleans.rb ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "booleans/version"
4
+
5
+ # Convert a Ruby value to `true` or `false`
6
+ # according to the truthiness of the value.
7
+ #
8
+ # Most Ruby objects get converted to `true` with the
9
+ # exception of: `nil` and `false`.
10
+ #
11
+ # @return [Boolean]
12
+ def Boolean(val) # rubocop:disable Naming/MethodName
13
+ return true if val
14
+
15
+ false
16
+ end
data/sig/booleans.rbs ADDED
@@ -0,0 +1,7 @@
1
+ module Booleans
2
+ VERSION: String
3
+
4
+ def to_bool: () -> bool
5
+ end
6
+
7
+ def Boolean: (boolish) -> bool
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: booleans
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mateusz Drewniak
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-10-20 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |
14
+ This gem adds a new method called `Boolean`, analogous to builtins like `Integer` or `String`, which converts
15
+ a Ruby value to either `true` or `false` based on its truthiness.
16
+
17
+ It also has optional core extensions that add a `to_bool` method to all Ruby objects and allow you to check if a value is boolean with `val.is_a?(Boolean)`.
18
+ email:
19
+ - matmg24@gmail.com
20
+ executables: []
21
+ extensions: []
22
+ extra_rdoc_files: []
23
+ files:
24
+ - ".rubocop.yml"
25
+ - CHANGELOG.md
26
+ - LICENSE.txt
27
+ - README.md
28
+ - Rakefile
29
+ - lib/booleans.rb
30
+ - lib/booleans/core_extension.rb
31
+ - lib/booleans/version.rb
32
+ - sig/booleans.rbs
33
+ homepage: https://github.com/Verseth/ruby-booleans
34
+ licenses:
35
+ - MIT
36
+ metadata:
37
+ homepage_uri: https://github.com/Verseth/ruby-booleans
38
+ source_code_uri: https://github.com/Verseth/ruby-booleans
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 3.0.0
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubygems_version: 3.4.21
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: Convert Ruby values to true or false in a convenient and reliable manner.
58
+ test_files: []