{"id":18158289,"url":"https://github.com/sam0x17/truthy","last_synced_at":"2025-04-07T03:20:00.777Z","repository":{"id":82773175,"uuid":"142800068","full_name":"sam0x17/truthy","owner":"sam0x17","description":"Adds intelligent to_b (to_boolen) to all objects in crystal ","archived":false,"fork":false,"pushed_at":"2019-02-02T15:07:33.000Z","size":14,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-13T08:14:47.754Z","etag":null,"topics":["boolean","crystal","crystal-language","crystal-shard","crystal-shards","shard","truthy"],"latest_commit_sha":null,"homepage":null,"language":"Crystal","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/sam0x17.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"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":"2018-07-29T22:32:55.000Z","updated_at":"2019-02-02T15:07:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"91337b3e-15c6-467f-9574-8d9ca6305ad2","html_url":"https://github.com/sam0x17/truthy","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sam0x17%2Ftruthy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sam0x17%2Ftruthy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sam0x17%2Ftruthy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sam0x17%2Ftruthy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sam0x17","download_url":"https://codeload.github.com/sam0x17/truthy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247584202,"owners_count":20962088,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["boolean","crystal","crystal-language","crystal-shard","crystal-shards","shard","truthy"],"created_at":"2024-11-02T07:06:11.746Z","updated_at":"2025-04-07T03:20:00.745Z","avatar_url":"https://github.com/sam0x17.png","language":"Crystal","funding_links":[],"categories":[],"sub_categories":[],"readme":"# truthy\n\nTruthy patches all objects in crystal with a `to_b` (to boolean) method that will intelligently return\na boolean based on the value of the object. This will differ from `!!(expr)` in a number of cases\nincluding the handling of `\"\"` and `'\\0'` as `false`, and proper handling of class instances and arrays (an empty array =\u003e false, an array with elements =\u003e true).\n\n`expr.to_b` will always return `true` or `false` no matter what you pass to it. `!!(expr)` is used\nas a fallback for any language features that are not explictly covered.\n\nAn alias is provided so that you can also use `*.truthy?` if you think this makes more sense than\n`to_b`. Both methods function in exactly the same way and are interchangable.\n\n## Installation\n\nAdd this to your application's `shard.yml`:\n\n```yaml\ndependencies:\n  truthy:\n    github: sam0x17/truthy\n```\n\n## Usage\n\n```crystal\nrequire \"truthy\"\n\n# Booleans\ntrue.to_b # =\u003e true\nfalse.to_b # =\u003e false\n\n# Objects\nnil.to_b # =\u003e false\nSomeClass.new.to_b # =\u003e true\n\n# Strings / Characters\n\"\".to_b # =\u003e false\n\"hey\".to_b # =\u003e true\n'\\0'.to_b # =\u003e false\n'c'.to_b # =\u003e true\n\"0\".to_b # =\u003e false\n\"1\".to_b # =\u003e true\n\"200\".to_b # =\u003e true\n\"1.0\".to_b # =\u003e true\n\"-1.0\".to_b # =\u003e false\n\"true\".to_b # =\u003e true\n\"false\".to_b # =\u003e false\n\"yes\".to_b # =\u003e true\n\"no\".to_b # =\u003e false\n\"nil\".to_b # =\u003e false\n\"null\".to_b # =\u003e false\n\"none\".to_b # =\u003e false\n\"True\".to_b # =\u003e true\n\"[]\".to_b # =\u003e false\n\"{}\".to_b # =\u003e false\n\n\n# Integers\n0.to_b # =\u003e false\n-1.to_b # =\u003e false\n1.to_b # =\u003e true\n10.to_b # =\u003e true\n0_i64.to_b # =\u003e false\n1_i8.to_b # =\u003e true\n-1_i16.to_b # =\u003e false\n0_u64.to_b # =\u003e false\n3_u16.to_b # =\u003e true\n\n# Floats\n0.0.to_b # =\u003e false\n1.0.to_b # =\u003e true\n0.001.to_b # =\u003e true\n-0.001.to_b # =\u003e false\n-1.0.to_b # =\u003e false\n23.342.to_b # =\u003e true\n\n# Arrays\n[1, 2, 3].to_b # =\u003e true\n([] of Int32).to_b # =\u003e false\n\n# truthy? alias\ntrue.truthy? # =\u003e true\nfalse.truthy? # =\u003e false\n0.truthy? # =\u003e false\n1.truthy? # =\u003e true\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsam0x17%2Ftruthy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsam0x17%2Ftruthy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsam0x17%2Ftruthy/lists"}