{"id":22488474,"url":"https://github.com/alexherbo2/enum.rb","last_synced_at":"2025-03-27T19:46:52.574Z","repository":{"id":75997260,"uuid":"409365617","full_name":"alexherbo2/enum.rb","owner":"alexherbo2","description":"Enum for Ruby","archived":false,"fork":false,"pushed_at":"2021-09-26T08:54:11.000Z","size":1,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-01T22:28:46.689Z","etag":null,"topics":["enum","ruby"],"latest_commit_sha":null,"homepage":"https://www.ruby-lang.org","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexherbo2.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2021-09-22T21:48:33.000Z","updated_at":"2021-09-26T10:53:54.000Z","dependencies_parsed_at":null,"dependency_job_id":"727c1cbc-960e-42a5-896a-7da0541b04f0","html_url":"https://github.com/alexherbo2/enum.rb","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexherbo2%2Fenum.rb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexherbo2%2Fenum.rb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexherbo2%2Fenum.rb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexherbo2%2Fenum.rb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexherbo2","download_url":"https://codeload.github.com/alexherbo2/enum.rb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245916085,"owners_count":20693379,"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":["enum","ruby"],"created_at":"2024-12-06T17:17:46.296Z","updated_at":"2025-03-27T19:46:52.564Z","avatar_url":"https://github.com/alexherbo2.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Enum for Ruby\n\nA [Ruby] implementation of [enumerated type] for educational purposes.\n\n[Ruby]: https://www.ruby-lang.org\n[Enumerated type]: https://en.wikipedia.org/wiki/Enumerated_type\n\nHeavily based on [Crystal].\n\n[Crystal]: https://crystal-lang.org\n\n## Overview\n\nAn enum is a set of integer values, where each value has an associated name.\n\nFor example:\n\n``` ruby\nrequire 'enum'\n\nclass Color \u003c Enum\n  member :Red # 0\n  member :Green # 1\n  member :Blue # 2\nend\n```\n\nValues start with the value `0` and are incremented by one, but can be overwritten.\n\nTo get the underlying value you invoke `value` on it:\n\n``` ruby\nColor::Green.value # ⇒ 1\n```\n\n### Enums from integers\n\nAn enum can be created from an integer:\n\n``` ruby\nColor.new(1).to_s # ⇒ \"Green\"\n```\n\nValues that don’t correspond to enum’s constants are allowed:\nthe value will still be of type `Color`, but when printed you will get the underlying value:\n\n``` ruby\nColor.new(10).to_s # ⇒ \"10\"\n```\n\nThis method is mainly intended to convert integers from C to enums in [Ruby].\n\n### Question methods\n\n``` ruby\nColor::Red.red? # ⇒ true\nColor::Blue.red? # ⇒ false\n```\n\n## Usage\n\n``` ruby\ndef paint(color)\n  case color\n  when Color::Red\n    # ...\n  else\n    # Unusual, but still can happen.\n    raise \"Unknown color: #{color}\"\n  end\nend\n```\n\n## Reference\n\n- [Crystal reference]\n- [Crystal API]\n\n[Crystal reference]: https://crystal-lang.org/reference/syntax_and_semantics/enum.html\n[Crystal API]: https://crystal-lang.org/api/master/Enum.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexherbo2%2Fenum.rb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexherbo2%2Fenum.rb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexherbo2%2Fenum.rb/lists"}