├── .gitignore ├── Gemfile ├── CHANGELOG.md ├── lib └── boolean2.rb ├── .github └── workflows │ └── test.yml ├── boolean2.gemspec ├── README.md ├── Rakefile ├── MIT-LICENSE.txt └── spec └── boolean2_spec.rb /.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gemspec 4 | 5 | gem 'minitest' 6 | gem 'rake' 7 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## CHANGELOG 2 | 3 | ### 1.0.1 4 | 5 | - Relax Ruby version requirement to allow Ruby 3.0 6 | 7 | ### 1.0.0 8 | 9 | - Initial release 10 | 11 | -------------------------------------------------------------------------------- /lib/boolean2.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module Boolean2 4 | VERSION = '1.0.1' 5 | 6 | def self.new(object) 7 | object.to_boolean2 8 | end 9 | end 10 | 11 | class TrueClass 12 | include Boolean2 13 | end 14 | 15 | class FalseClass 16 | include Boolean2 17 | end 18 | 19 | class Object 20 | def to_boolean2 21 | !!self 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | test: 7 | name: Ruby ${{ matrix.ruby }} (${{ matrix.os }}) 8 | if: "!contains(github.event.head_commit.message, '[skip ci]')" 9 | strategy: 10 | matrix: 11 | ruby: 12 | - 3.0 13 | - 2.7 14 | - 2.6 15 | - 2.5 16 | - jruby-9.2.13.0 17 | - truffleruby-20.3.0 18 | os: 19 | - ubuntu-latest 20 | runs-on: ${{matrix.os}} 21 | steps: 22 | - uses: actions/checkout@v2 23 | - name: Set up Ruby 24 | uses: ruby/setup-ruby@v1 25 | with: 26 | ruby-version: ${{matrix.ruby}} 27 | bundler-cache: true 28 | - name: Run tests 29 | run: bundle exec rake 30 | -------------------------------------------------------------------------------- /boolean2.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | 3 | require File.dirname(__FILE__) + "/lib/boolean2" 4 | 5 | Gem::Specification.new do |gem| 6 | gem.name = "boolean2" 7 | gem.version = Boolean2::VERSION 8 | gem.summary = "A global Boolean2 constant that is an ancestor of true and false." 9 | gem.description = "A global Boolean2 constant that is an ancestor of true and false. Useful for coercion libraries." 10 | gem.authors = ["Jan Lelis"] 11 | gem.email = ["hi@ruby.consulting"] 12 | gem.homepage = "https://github.com/janlelis/boolean2" 13 | gem.license = "MIT" 14 | 15 | gem.files = Dir['{**/}{.*,*}'].select{ |path| File.file?(path) && path !~ /^pkg/ } 16 | gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } 17 | gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) 18 | gem.require_paths = ['lib'] 19 | 20 | gem.required_ruby_version = '>= 2.0' 21 | end 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Boolean2 [![[version]](https://badge.fury.io/rb/boolean2.svg)](https://badge.fury.io/rb/boolean2) [![[ci]](https://github.com/janlelis/boolean2/workflows/Test/badge.svg)](https://github.com/janlelis/boolean2/actions?query=workflow%3ATest) 2 | 3 | Next time before you want to define a global `Boolean` class, consider using this bare-bones approach instead. 4 | 5 | ## Setup 6 | 7 | Add to your `Gemfile`: 8 | 9 | ```ruby 10 | gem 'boolean2' 11 | ``` 12 | 13 | ## Usage 14 | 15 | ```ruby 16 | true.is_a? Boolean2 #=> true 17 | false.is_a? Boolean2 #=> true 18 | nil.is_a? Boolean2 #=> false 19 | Object.new.is_a? Boolean2 #=> false 20 | 21 | true.to_boolean2 #=> true 22 | false.to_boolean2 #=> false 23 | nil.to_boolean2 #=> false 24 | Object.new.to_boolean2 #=> true 25 | 26 | Boolean2.new(true) #=> true 27 | Boolean2.new(false) #=> false 28 | Boolean2.new(nil) #=> false 29 | Boolean2.new(Object.new) #=> true 30 | ``` 31 | 32 | ## J-_-L 33 | 34 | Copyright (C) 2015 Jan Lelis . Released under the MIT license. 35 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # # # 2 | # Load gemspec info 3 | gemspec_file = Dir['*.gemspec'].first 4 | gemspec = eval File.read(gemspec_file), binding, gemspec_file 5 | info = "#{gemspec.name} | #{gemspec.version} | " \ 6 | "#{gemspec.runtime_dependencies.size} dependencies | " \ 7 | "#{gemspec.files.size} files" 8 | 9 | 10 | # # # 11 | # Gem build and install task 12 | desc info 13 | task :gem do 14 | puts info + "\n\n" 15 | print " "; sh "gem build #{gemspec_file}" 16 | FileUtils.mkdir_p 'pkg' 17 | FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg' 18 | puts; sh %{gem install --no-document pkg/#{gemspec.name}-#{gemspec.version}.gem} 19 | end 20 | 21 | 22 | # # # 23 | # Start an IRB session with the gem loaded 24 | 25 | desc "#{gemspec.name} | IRB" 26 | task :irb do 27 | sh "irb -I ./lib -r #{gemspec.name.gsub '-','/'}" 28 | end 29 | 30 | 31 | # # # 32 | # Run the specs 33 | 34 | desc "#{gemspec.name} | SPECS" 35 | task :specs do 36 | ruby "spec/*" 37 | end 38 | 39 | 40 | # # # 41 | # Default 42 | 43 | task default: :specs 44 | -------------------------------------------------------------------------------- /MIT-LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Jan Lelis, https://janlelis.com 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /spec/boolean2_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative "../lib/boolean2" 2 | require "minitest/autorun" 3 | 4 | describe Boolean2 do 5 | describe "true" do 6 | it "is a Boolean2" do 7 | assert_equal true, true.is_a?(Boolean2) 8 | end 9 | 10 | it "returns itself for #to_boolean2" do 11 | assert_equal true, true.to_boolean2 12 | end 13 | 14 | it "returns true when given to Boolean2.new" do 15 | assert_equal true, Boolean2.new(true) 16 | end 17 | end 18 | 19 | describe "false" do 20 | it "is a Boolean2" do 21 | assert_equal true, false.is_a?(Boolean2) 22 | end 23 | 24 | it "returns itself for #to_boolean2" do 25 | assert_equal false, false.to_boolean2 26 | end 27 | 28 | it "returns false when given to Boolean2.new" do 29 | assert_equal false, Boolean2.new(false) 30 | end 31 | end 32 | 33 | describe "nil" do 34 | it "is not a Boolean2" do 35 | assert_equal false, nil.is_a?(Boolean2) 36 | end 37 | 38 | it "returns false for #to_boolean2" do 39 | assert_equal false, nil.to_boolean2 40 | end 41 | 42 | it "returns false when given to Boolean2.new" do 43 | assert_equal false, Boolean2.new(nil) 44 | end 45 | end 46 | 47 | describe "Object" do 48 | it "is not a Boolean2" do 49 | assert_equal false, Object.new.is_a?(Boolean2) 50 | end 51 | 52 | it "returns true for #to_boolean2" do 53 | assert_equal true, Object.new.to_boolean2 54 | end 55 | 56 | it "returns true when given to Boolean2.new" do 57 | assert_equal true, Boolean2.new(Object.new) 58 | end 59 | end 60 | end 61 | 62 | --------------------------------------------------------------------------------