{"id":13879714,"url":"https://github.com/ruby/forwardable","last_synced_at":"2025-10-08T07:50:22.069Z","repository":{"id":33649625,"uuid":"138372513","full_name":"ruby/forwardable","owner":"ruby","description":"Provides delegation of specified methods to a designated object","archived":false,"fork":false,"pushed_at":"2024-08-19T22:05:30.000Z","size":197,"stargazers_count":42,"open_issues_count":3,"forks_count":17,"subscribers_count":30,"default_branch":"master","last_synced_at":"2025-03-28T09:04:37.673Z","etag":null,"topics":["ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ruby.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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-06-23T04:56:12.000Z","updated_at":"2024-12-24T04:45:44.000Z","dependencies_parsed_at":"2024-05-05T18:25:42.543Z","dependency_job_id":"4ee16d9c-1b8f-4d52-985b-50c3a80a593e","html_url":"https://github.com/ruby/forwardable","commit_stats":{"total_commits":115,"total_committers":26,"mean_commits":4.423076923076923,"dds":0.6608695652173913,"last_synced_commit":"3cedb338555504cb693df90aa92d34ae57525e62"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby%2Fforwardable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby%2Fforwardable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby%2Fforwardable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby%2Fforwardable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ruby","download_url":"https://codeload.github.com/ruby/forwardable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247156285,"owners_count":20893197,"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"],"created_at":"2024-08-06T08:02:30.050Z","updated_at":"2025-10-08T07:50:17.036Z","avatar_url":"https://github.com/ruby.png","language":"Ruby","readme":"# Forwardable\n\nThe Forwardable module provides delegation of specified methods to a designated object, using the methods `#def_delegator` and `#def_delegators`.\n\n## Installation\n\nAdd this line to your application's `Gemfile`:\n\n```ruby\ngem 'forwardable'\n```\n\nAnd then execute:\n\n```sh\n$ bundle\n```\n\nOr install it yourself as:\n\n```sh\n$ gem install forwardable\n```\n\n## Usage\n\nFor example, say you have a class `RecordCollection` which contains an array `@records`.  You could provide the lookup method `#record_number()`, which simply calls `#[]` on the `@records` array, like this:\n\n```ruby\n  require 'forwardable'\n\n  class RecordCollection\n    attr_accessor :records\n    extend Forwardable\n    def_delegator :@records, :[], :record_number\n  end\n```\n\nWe can use the lookup method like so:\n\n```ruby\n  r = RecordCollection.new\n  r.records = [4,5,6]\n  r.record_number(0)  # =\u003e 4\n```\n\nFurther, if you wish to provide the methods `#size`, `#\u003c\u003c`, and `#map`, all of which delegate to `@records`, this is how you can do it:\n\n```ruby\n  class RecordCollection # re-open RecordCollection class\n    def_delegators :@records, :size, :\u003c\u003c, :map\n  end\n\n  r = RecordCollection.new\n  r.records = [1,2,3]\n  r.record_number(0)   # =\u003e 1\n  r.size               # =\u003e 3\n  r \u003c\u003c 4               # =\u003e [1, 2, 3, 4]\n  r.map { |x| x * 2 }  # =\u003e [2, 4, 6, 8]\n```\n\nYou can even extend regular objects with Forwardable.\n\n```ruby\n  my_hash = Hash.new\n  my_hash.extend Forwardable              # prepare object for delegation\n  my_hash.def_delegator \"STDOUT\", \"puts\"  # add delegation for STDOUT.puts()\n  my_hash.puts \"Howdy!\"\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `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## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/ruby/forwardable.\n\n## License\n\nThe gem is available as open source under the terms of the [2-Clause BSD License](https://opensource.org/licenses/BSD-2-Clause).\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruby%2Fforwardable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fruby%2Fforwardable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruby%2Fforwardable/lists"}