{"id":13631684,"url":"https://github.com/ruby/rbs","last_synced_at":"2025-12-15T04:04:10.190Z","repository":{"id":36960313,"uuid":"174796313","full_name":"ruby/rbs","owner":"ruby","description":"Type Signature for Ruby","archived":false,"fork":false,"pushed_at":"2025-05-06T06:37:28.000Z","size":10228,"stargazers_count":2037,"open_issues_count":170,"forks_count":221,"subscribers_count":60,"default_branch":"master","last_synced_at":"2025-05-06T16:13:17.679Z","etag":null,"topics":["ruby","type-checking"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ruby.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"docs/CONTRIBUTING.md","funding":null,"license":"COPYING","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,"zenodo":null}},"created_at":"2019-03-10T08:22:27.000Z","updated_at":"2025-05-06T06:36:30.000Z","dependencies_parsed_at":"2024-03-26T02:30:00.058Z","dependency_job_id":"36ef4aee-a5b9-4afe-9e3f-9784f262cffa","html_url":"https://github.com/ruby/rbs","commit_stats":{"total_commits":2594,"total_committers":104,"mean_commits":"24.942307692307693","dds":0.6237471087124132,"last_synced_commit":"b9092c3e3bf39b3d91bbe4e2677a224e4b83717d"},"previous_names":[],"tags_count":135,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby%2Frbs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby%2Frbs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby%2Frbs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby%2Frbs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ruby","download_url":"https://codeload.github.com/ruby/rbs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253990455,"owners_count":21995773,"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":["ruby","type-checking"],"created_at":"2024-08-01T22:02:34.353Z","updated_at":"2025-12-15T04:04:10.179Z","avatar_url":"https://github.com/ruby.png","language":"Ruby","readme":"# RBS\n\nRBS is a language to describe the structure of Ruby programs.\nYou can write down the definition of a class or module: methods defined in the class, instance variables and their types, and inheritance/mix-in relations.\nIt also allows declaring constants and global variables.\n\nThe following is a small example of RBS for a chat app.\n\n\u003c!-- run-start:a.rbs:bundle exec rbs -I a.rbs validate --\u003e\n```rbs\nmodule ChatApp\n  VERSION: String\n\n  class User\n    attr_reader login: String\n    attr_reader email: String\n\n    def initialize: (login: String, email: String) -\u003e void\n  end\n\n  class Bot\n    attr_reader name: String\n    attr_reader email: String\n    attr_reader owner: User\n\n    def initialize: (name: String, owner: User) -\u003e void\n  end\n\n  class Message\n    attr_reader id: String\n    attr_reader string: String\n    attr_reader from: User | Bot                     # `|` means union types: `#from` can be `User` or `Bot`\n    attr_reader reply_to: Message?                   # `?` means optional type: `#reply_to` can be `nil`\n\n    def initialize: (from: User | Bot, string: String) -\u003e void\n\n    def reply: (from: User | Bot, string: String) -\u003e Message\n  end\n\n  class Channel\n    attr_reader name: String\n    attr_reader messages: Array[Message]\n    attr_reader users: Array[User]\n    attr_reader bots: Array[Bot]\n\n    def initialize: (name: String) -\u003e void\n\n    def each_member: () { (User | Bot) -\u003e void } -\u003e void  # `{` and `}` means block.\n                   | () -\u003e Enumerator[User | Bot, void]   # Method can be overloaded.\n  end\nend\n```\n\u003c!-- run-end --\u003e\n\n## The Target Version\n\n* The standard library signatures targets the latest release of Ruby. (`3.2` as of 2023.)\n* The library code targets non-EOL versions of Ruby. (`\u003e= 3.0` as of 2023.)\n\n## Installation\n\nInstall the `rbs` gem. `$ gem install rbs` from the command line, or add a line in your `Gemfile`.\n\n```rb\ngem \"rbs\"\n```\n\n## CLI\n\nThe gem ships with the `rbs` command line tool to demonstrate what it can do and help develop RBS.\n\n```console\n$ rbs version\n$ rbs list\n$ rbs ancestors ::Object\n$ rbs methods ::Object\n$ rbs method Object then\n```\n\nAn end user of `rbs` will probably find `rbs prototype` the most useful. This command generates boilerplate signature declarations for ruby files. For example, say you have written the below ruby script.\n\n```ruby\n# person.rb\nclass Person\n  attr_reader :name\n  attr_reader :contacts\n\n  def initialize(name:)\n    @name = name\n    @contacts = []\n  end\n\n  def speak\n    \"I'm #{@name} and I love Ruby!\"\n  end\nend\n```\n\nRunning prototype on the above will automatically generate\n\n```console\n$ rbs prototype rb person.rb\nclass Person\n  @name: untyped\n\n  @contacts: untyped\n\n  attr_reader name: untyped\n\n  attr_reader contacts: untyped\n\n  def initialize: (name: untyped) -\u003e void\n\n  def speak: () -\u003e ::String\nend\n```\n\nIt prints signatures for all methods, classes, instance variables, and constants.\nThis is only a starting point, and you should edit the output to match your signature more accurately.\n\n`rbs prototype` offers three options.\n\n- `rb` generates from just the available Ruby code\n- `rbi` generates from Sorbet RBI\n- `runtime` generates from runtime API\n\n## Library\n\nThere are two important concepts, _environment_ and _definition_.\n\nAn _environment_ is a dictionary that keeps track of all declarations. What is the declaration associated with `String` class? An _environment_ will give you the answer.\n\nA _definition_ gives you the detail of the class. What is the type of the return value of `gsub` method of the `String` class? The _definition_ for `String` class knows the list of methods it provides and their types.\n\nThe following is a small code to retrieve the definition of the `String#gsub` method.\n\n\u003c!-- run-start:a.rb:bundle exec ruby a.rb --\u003e\n```rb\nrequire \"rbs\"\n\nloader = RBS::EnvironmentLoader.new()\n\n# loader.add(path: Pathname(\"sig\"))   # Load .rbs files from `sig` directory\n# loader.add(library: \"logger\")       # Load logger library\n\nenvironment = RBS::Environment.from_loader(loader).resolve_type_names\n\n# ::String\nstring = RBS::TypeName.new(name: :String, namespace: RBS::Namespace.root)\n\n# Class declaration for ::String\ndecl = environment.class_decls[string]\n\n# Builder provides the translation from `declaration` to `definition`\nbuilder = RBS::DefinitionBuilder.new(env: environment)\n\n# Definition of instance of String\ninstance = builder.build_instance(string)\n\n# Print the types of `gsub` method:\nputs instance.methods[:gsub].method_types.join(\"\\n\")\n# Outputs =\u003e\n#  (::Regexp | ::string pattern, ::string replacement) -\u003e ::String\n#  (::Regexp | ::string pattern, ::Hash[::String, ::String] hash) -\u003e ::String\n#  (::Regexp | ::string pattern) { (::String match) -\u003e ::_ToS } -\u003e ::String\n#  (::Regexp | ::string pattern) -\u003e ::Enumerator[::String, self]\n\n# Definition of singleton of String\nsingleton = builder.build_singleton(string)\n# No `gsub` method for String singleton\nputs singleton.methods[:gsub]\n```\n\u003c!-- run-end --\u003e\n\n## Guides\n\n- [Architecture](docs/architecture.md)\n- [Core and standard library signature contribution guide](docs/CONTRIBUTING.md)\n- [Writing signatures guide](docs/sigs.md)\n- [Stdlib signatures guide](docs/stdlib.md)\n- [Syntax](docs/syntax.md)\n- [RBS by Example](docs/rbs_by_example.md)\n- [RBS collection](docs/collection.md)\n- [Using `Data` and `Struct`](docs/data_and_struct.md)\n- [Releasing a gem with RBS](docs/gem.md)\n\n## Community\n\nHere is a list of some places you can talk with active maintainers.\n\n- [Ruby Discord Server (invite link)](https://discord.gg/ad2acQFtkh) -- We have `rbs` channel in Ruby Discord server.\n- [ruby-jp Slack Workspace (in Japanese)](https://ruby-jp.github.io/) -- We have `types` channel in ruby-jp slack workspace.\n- [gem_rbs_collection](https://github.com/ruby/gem_rbs_collection) -- We have a repository of third-party RBS type definitions, for the case your dependency doesn't ship with RBS files.\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n### C Code Formatting\n\nThis project uses `clang-format` to enforce consistent formatting of C code with a `.clang-format` configuration in the root directory.\n\n#### Setup\n\nFirst, install clang-format:\n\n```bash\n# macOS\nbrew install clang-format\n\n# Ubuntu/Debian\nsudo apt-get install clang-format\n\n# Windows\nchoco install llvm\n```\n\n#### Usage\n\nFormat all C source files:\n\n```bash\nrake format:c\n```\n\nCheck formatting without making changes:\n\n```bash\nrake format:c_check\n```\n\n#### Editor Integration\n\nFor VS Code users, install the \"clangd\" extension which will automatically use the project's `.clang-format` file.\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/ruby/rbs.\n","funding_links":[],"categories":["Ruby","Ruby Type Annotations / Signatures"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruby%2Frbs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fruby%2Frbs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruby%2Frbs/lists"}