{"id":13879518,"url":"https://github.com/zverok/delegates","last_synced_at":"2025-06-12T07:09:47.289Z","repository":{"id":62556963,"uuid":"271065837","full_name":"zverok/delegates","owner":"zverok","description":"delegate :methods, to: :target, extracted from ActiveSupport","archived":false,"fork":false,"pushed_at":"2020-06-13T16:42:01.000Z","size":66,"stargazers_count":32,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-17T13:57:36.786Z","etag":null,"topics":["delegate","ruby"],"latest_commit_sha":null,"homepage":null,"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/zverok.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}},"created_at":"2020-06-09T17:22:19.000Z","updated_at":"2023-08-04T10:04:50.000Z","dependencies_parsed_at":"2022-11-03T06:15:23.438Z","dependency_job_id":null,"html_url":"https://github.com/zverok/delegates","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/zverok/delegates","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zverok%2Fdelegates","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zverok%2Fdelegates/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zverok%2Fdelegates/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zverok%2Fdelegates/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zverok","download_url":"https://codeload.github.com/zverok/delegates/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zverok%2Fdelegates/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259418217,"owners_count":22854187,"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":["delegate","ruby"],"created_at":"2024-08-06T08:02:23.624Z","updated_at":"2025-06-12T07:09:47.259Z","avatar_url":"https://github.com/zverok.png","language":"Ruby","readme":"# Delegates\n\n[![Gem Version](https://badge.fury.io/rb/delegates.svg)](http://badge.fury.io/rb/delegates)\n![build](https://github.com/zverok/delegates/workflows/CI/badge.svg)\n\nThis gem is just an extraction of the handy `delegate :method1, :method2, method3, to: :receiver` from ActiveSupport. It seems to be seriously superior to stdlib's [Forwardable](https://ruby-doc.org/stdlib-2.7.1/libdoc/forwardable/rdoc/Forwardable.html), and sometimes I want it in contexts when ActiveSupport and monkey-patching is undesireable.\n\nUsage:\n\n```\ngem install delegates\n```\n(or add `gem 'delegates'` to your `Gemfile`).\n\nThen:\n\n```ruby\nclass Employee \u003c Struct.new(:name, :department, :address)\n  # ...\n  extend Delegates\n  delegate :city, :street, to: :address\n  # ...\nend\n\nemployee = Employee.new(name, department, address)\n\nemployee.city # will call employee.address.city\n```\n\n`to:` can be anything evaluatable from inside the class: `:\u003cCONSTANT\u003e`, `:@\u003cinstance_variable\u003e`, `'chain.of.calls'` etc.; special names requiring `self` (like `class` method) handled gracefully with just `delegate ..., to: :class`. New methods are defined with `eval`-ing strings, so they are as fast as if manually written.\n\nSupported options examples (all that ActiveSupport's `Module#delegate` supports):\n\n```ruby\ndelegate :city, to: :address, prefix: true # defined method would be address_city\ndelegate :city, to: :address, prefix: :adrs # defined method would be adrs_city\n\ndelegate :city, to: :address, private: true # defined method would be private\n\ndelegate :city, to: :address, allow_nil: true\n```\nThe latter option will handle the `employee.city` call when `employee.address` is `nil` by returning `nil`; otherwise (by default) informative `DelegationError` is raised.\n\n## Credits\n\n99.99% of credits should go to Rails users and contributors, who found and and handled miriads of realistic edge cases. I just copied the code (and groomed it a bit for closer to my own style).\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzverok%2Fdelegates","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzverok%2Fdelegates","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzverok%2Fdelegates/lists"}