{"id":15288842,"url":"https://github.com/roberwil/truthy_gem","last_synced_at":"2026-02-22T16:33:44.552Z","repository":{"id":146094082,"uuid":"615535931","full_name":"roberwil/truthy_gem","owner":"roberwil","description":"Create a truth table and evaluate it with your inputs, Truthy figures out the formula; Perform your logical operations with ease.","archived":false,"fork":false,"pushed_at":"2023-03-31T03:51:31.000Z","size":50,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-11T22:22:03.395Z","etag":null,"topics":["ruby","ruby-gem","ruby-on-rails","rubygems"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/roberwil.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-17T23:39:47.000Z","updated_at":"2023-03-30T02:11:15.000Z","dependencies_parsed_at":"2023-06-25T19:50:04.745Z","dependency_job_id":null,"html_url":"https://github.com/roberwil/truthy_gem","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/roberwil/truthy_gem","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roberwil%2Ftruthy_gem","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roberwil%2Ftruthy_gem/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roberwil%2Ftruthy_gem/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roberwil%2Ftruthy_gem/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/roberwil","download_url":"https://codeload.github.com/roberwil/truthy_gem/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roberwil%2Ftruthy_gem/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29718432,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-22T15:10:41.462Z","status":"ssl_error","status_checked_at":"2026-02-22T15:10:04.636Z","response_time":110,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ruby","ruby-gem","ruby-on-rails","rubygems"],"created_at":"2024-09-30T15:53:22.172Z","updated_at":"2026-02-22T16:33:44.531Z","avatar_url":"https://github.com/roberwil.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Truthy\n\n###### **Find the gem [here](https://rubygems.org/gems/ada_truthy).**\n\nTL;DR;\n\nSame as [Truthy](https://github.com/roberwil/truthy), but for Ruby folks.\n\n## What is truthy anyway?\n\nWell, think of truth table you just invented, you put your 1s and 0s and **Truthy** figures out which formula works\nfor the table.\n\n| A   | B   | C   |\n|-----|-----|-----|\n| 0   | 0   | 1   |\n| 1   | 0   | 1   |\n| 1   | 1   | 0   |\n| 0   | 1   | 0   |\n\nIf you create the above table with **Truthy**, it will know what to do so that your table makes sense.\nAlso, **Truthy** has implementations for the following logical gates: `and`, `or`, `not`,\n`xor`, `nand`, `nor`, and `xnor`.\n\n## Where can I use it?\n\n- Access matrices are a good example;\n- Other examples are just day-to-day comparisons you do with booleans in your code.\n\nWhy stress your brain with bare booleans? Use Truthy!\n\nLet your imagination make good use of Truthy.\n\n## Usage\n\nTo install, add this line to your application's Gemfile:\n\n```ruby\ngem 'ada_truthy'\n```\n\n\nOr install it yourself as:\n\n    $ gem install ada_truthy\n\nEvery functionality is under `ada_truthy` namespace. Some methods throw an exception, the `TruthyException`.\n\n```ruby\nrequire 'ada_truthy'\n```\n\n### Truth Table\n\n**Note: For versions \u003e= 1.1.0, the examples bellow assume the following was defined**\n\n```ruby\nTruthTable = AdaTruthy::TruthTable\n```\n\nTo create a truth table, you do as follows:\n\n```ruby\nt = TruthTable.new 2\n```\n\n2 is the number of terms in the truth table. The **minimum** number of terms is **2** and the **maximum** is **6**.\nIf you violate any of the limits, `TruthyException` will be raised.\n\nTo add a new row, you do as follows:\n\n```ruby\nt = TruthTable.new 2\nt.add_row 1, 1, 0\n```\n\nFor a truth table of **n** terms, the rows take **n+1** terms, where **+1** is the result of the operation for such row.\n`TruthyException` will be raised if:\n\n- There are already enough rows for the defined truth table;\n- You try to add equal rows;\n- You try to add a row with **m** terms, where **m != n + 1**.\n\nAfter you have defined your truth table and added your rows, you can check boolean values against it as follows:\n\n```ruby\nt = TruthTable.new 2\nt.add_row 1, 1, 0\n\nt.check(2+2==4, 3+3==6) # \u003e false\nt.check(2+2==1, 3+3==6) # \u003e true\n```\nFor a truth table of **n** terms, you check **n** terms.\n\nBeware of the behaviour of Truthy, see the following example to understand.\n\n```ruby\nt = TruthTable.new 2\nt.add_row 1, 1, 0   # the other combinations will evaluate to true\nt.check true, false # \u003e true\n\nu = TruthTable.new 2\nu.add_row 1, 1, 0\nu.add_row 1, 0, 1\n\nu.check(true, true)  # \u003e false\nu.check(true, false) # \u003e true\n\n# the other combinations will evaluate to true\nu.check(false, false) # \u003e true\nu.check(false, true)  # \u003e true\n\n\nw = TruthTable.new 2\nw.add_row 1, 1, 0\nw.add_row 1, 0, 0\nw.add_row 0, 1, 1\n\nw.check(true, true)  # \u003e false\nw.check(true, false) # \u003e false\nw.check(false, true) # \u003e true\n\n# the other combinations will evaluate to false\nu.check(false, false) # \u003e false\n```\n\nThe tricks to master it are:\n- The first row you add is determinant, take **table t**, if the first row was equal to 1, the the rest would be false;\n- if there are more 0s than 1s explicitly (like **table w**), every combination that equals 0 and others not specified will evaluate to 0, which means, it could be simplified;\n- if there are more 1s than 0s explicitly, every combination that equals 1 and others not specified will evaluate to 1.\n\nAt last, if you wish to know the formula, just call `.to_s`\n\n```ruby\nt = TruthTable.new 2\nt.add_row(1, 1, 0)    # the other combinations will evaluate to true\nt.check(true, false)  # \u003e true\n\nt.to_s # \u003e (~A+~B)\n```\n\n### Logical Gates\n\n**Note: For versions \u003e= 1.1.0, the examples bellow assume the following was defined**\n\n```ruby\nLogicalGate = AdaTruthy::LogicalGate\n```\n\nThe logical gates are all found in the `LogicalGate` class, but there are also extension methods for booleans.\nAll operations support multiple terms and accept a minimum of 2 terms, except `.not()` which accepts only 1 term.\n\n`.and` is equivalent to `\u0026\u0026`. Operation is `true` if every term is `true`.\n\n```ruby\na = (2+2==4)\nb = (2+1==3)\nc = (2+1==5)\n\na.and(b)    # \u003e true\na.and(b, c) # \u003e false\n```\n\n`.or` is equivalent to `||`. Operation is `true` if any term is `true`.\n\n```ruby\na = (2+2==4)\nb = (2+1==3)\nc = (2+1==5)\n\na.or(b)               # \u003e true\na.or(b, c)            # \u003e true\nLogicalGate.or(c, c)  # \u003e false\n```\n\n`.not` inverts the value.\n\n```ruby\na = (2+2==4)\nb = (2+1==3)\nc = (2+1==5)\n\na.not()            # \u003e false\nLogicalGate.not(b) # \u003e false\nLogicalGate.not(c) # \u003e true\n```\n\n`.xor` is the exclusive OR, the operation is true if the terms are different. XOR is a binary operation,\nwhich means that if you test multiple terms, XOR will be applied for every two terms.\nExample: 3 terms (a, b and c), first, we do a XOR b, and then (a XOR b) XOR c.\n\n```ruby\na = (2+2==4)\nb = (2+1==3)\nc = (2+1==5)\n\na.xor(b) # \u003e false\na.xor(c) # \u003e true\n```\n\n`.nand` is the inverse of AND operation.\n\n```ruby\na = (2+2==4)\nb = (2+1==3)\nc = (2+1==5)\n\na.nand(b)    # \u003e false\na.nand(b, c) # \u003e true\n```\n\n`.nor` is the inverse of OR operation.\n\n```ruby\na = (2+2==4)\nb = (2+1==3)\nc = (2+1==5)\n\na.nor(b)             # \u003e false\na.nor(b, c)          # \u003e false\nLogicalGate.or(c, c) # \u003e true\n```\n\n`.xnor`is the inverse of XOR operation.\n\n```ruby\na = (2+2==4)\nb = (2+1==3)\nc = (2+1==5)\n\na.xnor(b) # \u003e true\na.xnor(c) # \u003e false\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test`\nto run the tests. You can also run `bin/console` for an interactive prompt that will allow\nyou to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a\nnew version, update the version number in `version.rb`, and then run `bundle exec rake release`,\nwhich will create a git tag for the version, push git commits and tags, and push the `.gem`\nfile to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/roberwil/truthy_gem.\nThis project is intended to be a safe, welcoming space for collaboration, and contributors are\nexpected to adhere to the [code of conduct](https://github.com/roberwil/truthy_gem/blob/main/CODE_OF_CONDUCT.md).\n\n\n## Code of Conduct\n\nEveryone interacting in the AdaNumbers project's codebases, issue trackers, chat rooms and\nmailing lists is expected to follow the [code of conduct](https://github.com/roberwil/truthy_gem/blob/main/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froberwil%2Ftruthy_gem","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Froberwil%2Ftruthy_gem","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froberwil%2Ftruthy_gem/lists"}