{"id":22119987,"url":"https://github.com/maxpleaner/inverse_methods","last_synced_at":"2025-10-30T10:34:50.058Z","repository":{"id":56877877,"uuid":"78098432","full_name":"MaxPleaner/inverse_methods","owner":"MaxPleaner","description":"pass_to and chain_to methods using debug_inspector","archived":false,"fork":false,"pushed_at":"2017-06-26T17:40:06.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-06T06:22:31.475Z","etag":null,"topics":["ruby","ruby-extension","ruby-gem"],"latest_commit_sha":null,"homepage":"","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/MaxPleaner.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":"2017-01-05T09:19:52.000Z","updated_at":"2017-06-26T17:05:56.000Z","dependencies_parsed_at":"2022-08-20T11:21:49.046Z","dependency_job_id":null,"html_url":"https://github.com/MaxPleaner/inverse_methods","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/MaxPleaner%2Finverse_methods","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaxPleaner%2Finverse_methods/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaxPleaner%2Finverse_methods/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaxPleaner%2Finverse_methods/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MaxPleaner","download_url":"https://codeload.github.com/MaxPleaner/inverse_methods/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245219770,"owners_count":20579647,"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","ruby-extension","ruby-gem"],"created_at":"2024-12-01T14:19:42.331Z","updated_at":"2025-10-30T10:34:49.947Z","avatar_url":"https://github.com/MaxPleaner.png","language":"Ruby","readme":"### Install\n\n`gem install inverse_methods`\n`require 'inverse_methods'`\n\n## Accessing methods\n\nThere is a single module `InverseMethods` which can be included where it's needed or patched on `Object` for global access.\n\nTo load it globally, use `Object.include InverseMethods`. Or use a more specific scope such as `MyClass.include InverseMethods` or `MyClass.extend InverseMethods`.\n\nIt can be used as a refinement: `using InverseMethods`.\n\n### Explanation\n\nTwo methods which can be added on Object:\n\nBoth use `debug_inspector` to do some stuff with Ruby that wouldn't otherwise be possible.\n\n`pass_to` is kind of like a reverse tap. It still works as a \"tap\" (it returns the caller) but takes arguments differently:\n\n    foo = []\n    1.pass_to %i{ foo.push foo.push }\n    # =\u003e 1\n    puts foo # =\u003e [1,1]\n\nThe caller is being passed as an argument (serialized using `Marshal.dump`), and the symbols in the list are methods which it is passed to. They are evaluated in the caller context, which is why the local variable `foo` can be referenced.\n\nThe method names passed to `pass_to` are not chained. This is why `[1,1]` was returned instead of `[1, [...]]` (the three dots being a recursive reference). The `foo.push 1` calls happen independently of one another.  \n\nThe above example, if modified like so, wouldn't work:\n\n    foo = []\n    1.pass_to [:foo.push, :foo.push]\n    puts foo\n\nThe reason is that `:foo.push` is a `SyntaxError`. It needs to be written as `:\"foo.push\"`, which the `%i{ array.of symbols }` shorthand would do automatically.\n\nThe second method is `chain_to`, which is perhaps the 'functional programming' alternative to `pass_to` (and `tap`, which it's based on). It works similarly:\n\n    foo = []\n    [1].chain_to %i{[2].concat [3].concat}\n    puts foo # =\u003e [3,2,1]\n\nOnly the first symbol (`:\"[2].concat\"`) gets the original argument, `[1]`, passed when evaluated. The next symbol `:\"[3].concat\"` gets the first evaluation's result (`[2, 1]`) passed.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxpleaner%2Finverse_methods","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaxpleaner%2Finverse_methods","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxpleaner%2Finverse_methods/lists"}