{"id":16737642,"url":"https://github.com/shioyama/invisible","last_synced_at":"2025-03-17T01:31:51.518Z","repository":{"id":56877881,"uuid":"218176163","full_name":"shioyama/invisible","owner":"shioyama","description":"Override methods while maintaining their original visibility","archived":false,"fork":false,"pushed_at":"2020-04-12T07:17:45.000Z","size":44,"stargazers_count":35,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-15T02:39:28.266Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shioyama.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-29T01:11:29.000Z","updated_at":"2023-03-29T13:04:48.000Z","dependencies_parsed_at":"2022-08-20T23:10:15.681Z","dependency_job_id":null,"html_url":"https://github.com/shioyama/invisible","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shioyama%2Finvisible","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shioyama%2Finvisible/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shioyama%2Finvisible/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shioyama%2Finvisible/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shioyama","download_url":"https://codeload.github.com/shioyama/invisible/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243676697,"owners_count":20329431,"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-10-13T00:27:15.776Z","updated_at":"2025-03-17T01:31:51.170Z","avatar_url":"https://github.com/shioyama.png","language":"Ruby","readme":"# Invisible\n\n[![Gem Version](https://badge.fury.io/rb/invisible.svg)][gem]\n[![Build Status](https://travis-ci.com/shioyama/invisible.svg?branch=master)][travis]\n\n[gem]: https://rubygems.org/gems/invisible\n[travis]: https://travis-ci.com/shioyama/invisible\n\nPublic? Private? Protected? Who cares! I just wanna monkey patch that shit!\n\nNo fear: Invisible has your back! In a dozen lines of code, this little gem does away with the problem of maintaining original method visibility, so you can get on with your monkey-patching mayhem.\n\n## Usage\n\nSuppose you are defining a module which will override a bunch of methods from some class (or module). Simply `extend Invisible` and you can ignore checking whether those methods are public, protected or private -- Invisible will take care of that for you.\n\nSuppose this is the class we are overriding:\n\n```ruby\nclass Base\n  def public_method\n    'public'\n  end\n\n  protected\n\n  def protected_method\n    'protected'\n  end\n\n  private\n\n  def private_method\n    'private'\n  end\nend\n```\n\nWe don't want to care about whether the methods are private or whatever. So we define our module like so:\n\n```ruby\nmodule WithFoo\n  extend Invisible\n\n  def public_method\n    super + ' with foo'\n  end\n\n  def protected_method\n    super + ' with foo'\n  end\n\n  def private_method\n    super + ' with foo'\n  end\nend\n```\n\nNormally, without Invisible, we would have just made methods that were previously `private` or `protected` become `public`. But Invisible checks the original visibility and ensures that when the module is included, methods which were originally private or protected stay that way.\n\n```ruby\nclass MyClass \u003c Base\n  include WithFoo\nend\n\ninstance = MyClass.new\n\nMyClass.public_method_defined?(:public_method)       #=\u003e true\ninstance.public_method                               #=\u003e 'public with foo'\n\nMyClass.protected_method_defined?(:protected_method) #=\u003e true\ninstance.protected_method                            # raises NoMethodError\ninstance.send(:protected_method)                     #=\u003e 'protected with foo'\n\nMyClass.private_method_defined?(:private_method)     #=\u003e true\ninstance.private_method                              # raises NoMethodError\ninstance.send(:private_method)                       #=\u003e 'private with foo'\n```\n\nAlso works with `prepend`:\n\n```ruby\nBase.prepend WithFoo\n\ninstance = Base.new\n\nBase.private_method_defined?(:private_method)        # true\ninstance.private_method                              # raises NoMethodError\ninstance.send(:private_method)                       #=\u003e 'private with foo'\n```\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshioyama%2Finvisible","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshioyama%2Finvisible","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshioyama%2Finvisible/lists"}