{"id":20123247,"url":"https://github.com/citizen428/methodfinder","last_synced_at":"2025-05-16T19:00:20.483Z","repository":{"id":1385584,"uuid":"1349995","full_name":"citizen428/methodfinder","owner":"citizen428","description":"A Smalltalk like Method Finder for Ruby. This is a mirror of the main repository on Sourcehut.","archived":false,"fork":false,"pushed_at":"2024-10-22T08:51:17.000Z","size":116,"stargazers_count":269,"open_issues_count":0,"forks_count":8,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-05-09T18:12:05.919Z","etag":null,"topics":["introspection","ruby"],"latest_commit_sha":null,"homepage":"https://sr.ht/~citizen428/methodfinder/","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/citizen428.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":"2011-02-10T09:24:18.000Z","updated_at":"2025-01-02T05:03:06.000Z","dependencies_parsed_at":"2024-11-13T19:44:14.065Z","dependency_job_id":"4c436ab9-030d-46dc-a160-a566bf5c14d0","html_url":"https://github.com/citizen428/methodfinder","commit_stats":{"total_commits":135,"total_committers":8,"mean_commits":16.875,"dds":0.3481481481481481,"last_synced_commit":"b6d2e92cf00c7cc4f82db59a3c803f2c941b0ce5"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/citizen428%2Fmethodfinder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/citizen428%2Fmethodfinder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/citizen428%2Fmethodfinder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/citizen428%2Fmethodfinder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/citizen428","download_url":"https://codeload.github.com/citizen428/methodfinder/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254592367,"owners_count":22097010,"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":["introspection","ruby"],"created_at":"2024-11-13T19:44:03.503Z","updated_at":"2025-05-16T19:00:20.385Z","avatar_url":"https://github.com/citizen428.png","language":"Ruby","readme":"# MethodFinder\n\n[![builds.sr.ht status](https://builds.sr.ht/~citizen428/methodfinder.svg)](https://builds.sr.ht/~citizen428/methodfinder?)\n[![Gem Version](https://img.shields.io/gem/v/methodfinder.svg)](https://rubygems.org/gems/methodfinder)\n\n\u003c!-- toc --\u003e\n\n- [NAME](#name)\n- [INSTALLATION](#installation)\n- [SYNOPSIS](#synopsis)\n- [DESCRIPTION](#description)\n  - [Warning](#warning)\n- [API](#api)\n  - [MethodFinder.find](#methodfinderfind)\n  - [Object#find_method](#objectfind_method)\n    - [Ignorelists](#ignorelists)\n  - [MethodFinder.find_classes_and_modules](#methodfinderfind_classes_and_modules)\n  - [MethodFinder.find_in_class_or_module](#methodfinderfind_in_class_or_module)\n- [TROUBLESHOOTING](#troubleshooting)\n- [DEVELOPMENT](#development)\n- [CONTRIBUTING](#contributing)\n- [SEE ALSO](#see-also)\n  - [Gems](#gems)\n  - [Misc](#misc)\n- [VERSION](#version)\n- [AUTHOR](#author)\n- [LICENSE](#license)\n\n\u003c!-- tocstop --\u003e\n\n## NAME\n\nMethodFinder - a Smalltalk-like Method Finder for Ruby\n\n## INSTALLATION\n\n    $ gem install methodfinder\n\n## SYNOPSIS\n\n```ruby\nWelcome to IRB. # or Pry\n\n\u003e\u003e 'Hello, world!'.find_method('HELLO, WORLD!')\n#=\u003e [\"String#upcase\", \"String#upcase!\"]\n\n\u003e\u003e %w[a b c].find_method('c')\n#=\u003e [\"Array#last\", \"Array#max\", \"Array#pop\"]\n\n\u003e\u003e %w[a b c].find_method { |it| it.unknown(2); it == %w[c] }\n#=\u003e [\"Array#shift\"]\n```\n\n## DESCRIPTION\n\nA Smalltalk-like Method Finder for Ruby for use in your `~/.irbrc` or\n`~/.pryrc`.\n\nThis project was originally inspired by Smalltalk's Method\nFinder, but additional features have been added over time.\n\n### Warning\n\nCommon sense not included!\n\nWhile this gem should generally be safe to use, it's still better to be safe\nthan sorry, so use this with caution and maybe not on production data.\n\nThis was initially written for the students of the core Ruby course on\n[RubyLearning](http://web.archive.org/web/20151218180403/http://rubylearning.org/classes/),\nso it's generally not tested in a Rails console, just plain IRB/Pry.\n\n## API\n\n### MethodFinder.find\n\nProvided with a receiver, the desired result and possibly some arguments,\n`MethodFinder.find` will list all methods that produce the given result when\ncalled on the receiver with the provided arguments.\n\n```ruby\nMethodFinder.find(10, 1, 3)\n#=\u003e [\"Fixnum#%\", \"Fixnum#\u003c=\u003e\", \"Fixnum#\u003e\u003e\", \"Fixnum#[]\", \"Integer#gcd\", \"Fixnum#modulo\", \"Numeric#remainder\"]\nMethodFinder.find(\"abc\", \"ABC\")\n#=\u003e [\"String#swapcase\", \"String#swapcase!\", \"String#upcase\", \"String#upcase!\"]\nMethodFinder.find(10, 100, 2)\n#=\u003e [\"Fixnum#**\"]\nMethodFinder.find(['a', 'b', 'c'], ['A', 'B', 'C']) { |x| x.upcase }\n#=\u003e [\"Array#collect\", \"Array#collect!\", \"Enumerable#collect_concat\", \"Enumerable#flat_map\", \"Array#map\", \"Array#map!\"]\n```\n\n### Object#find_method\n\nThis gem also adds `Object#find_method`, which besides offering an alternative\ninterface to pretty much the same functionality as `MethodFinder.find`, also\nallows you to test for state other than the return value of the method.\n\n```ruby\n%w[a b c].find_method { |a| a.unknown(1) ; a == %w[a c] }\n#=\u003e [\"Array#delete_at\", \"Array#slice!\"]\n10.find_method { |n| n.unknown(3) == 1 }\n#=\u003e [\"Fixnum#%\", \"Fixnum#\u003c=\u003e\", \"Fixnum#\u003e\u003e\", \"Fixnum#[]\", \"Integer#gcd\", \"Fixnum#modulo\", \"Numeric#remainder\"]\n```\n\nInside `find_method`'s block, the receiver is available as block argument and\nthe special method `unknown` is used as a placeholder for the desired method.\n\nYou can also call `find_method` without passing a block. This is the same as\ncalling `MethodFinder.find`.\n\n```ruby\n10.find_method(1, 3)\n#=\u003e [\"Fixnum#%\", \"Fixnum#\u003c=\u003e\", \"Fixnum#\u003e\u003e\", \"Fixnum#[]\", \"Integer#gcd\", \"Fixnum#modulo\", \"Numeric#remainder\"]\n```\n\n#### Ignorelists\n\nYou can exclude methods from being tried by editing the hashes\n`MethodFinder::INSTANCE_METHOD_IGNORELIST` and\n`MethodFinder::CLASS_METHOD_IGNORELIST`. Both use the class/module as key and\nan array of method names as values (note that class, module and method names\nhave to be symbols).\n\nFor example, to ignore the instance method `shutdown` of `Object`, you would do\n\n```ruby\nMethodFinder::INSTANCE_METHOD_IGNORELIST[:Object] \u003c\u003c :shutdown\n```\n\nThis might come in handy when using `MethodFinder` together with other gems as\nsuch as `interactive_editor`.\n\n### MethodFinder.find_classes_and_modules\n\nA simple method to return all currently defined modules and classes.\n\n```ruby\nMethodFinder.find_classes_and_modules\n#=\u003e [ArgumentError, Array, BasicObject, Bignum ... ZeroDivisionError]\n```\n\n### MethodFinder.find_in_class_or_module\n\nSearches for a given name within a class. The first parameter can either be a\nclass object, a symbol or a string whereas the optional second parameter can\nbe a string or a regular expression:\n\n```ruby\nMethodFinder.find_in_class_or_module('Array', 'shuff')\n#=\u003e [:shuffle, :shuffle!]\nMethodFinder.find_in_class_or_module(Float, /^to/)\n#=\u003e [:to_f, :to_i, :to_int, :to_r, :to_s]\n```\n\nIf the second parameter is omitted, all methods of the class or module will be\nreturned.\n\n```ruby\nMethodFinder.find_in_class_or_module(Math)\n#=\u003e [:acos, :acosh, :asin ... :tanh]\n```\n\n## TROUBLESHOOTING\n\nIf the `METHOD_FINDER_DEBUG` environment variable is set, the name of each\ncandidate method is printed to `STDERR` before it is invoked. This can be useful\nto identify (and consequently ignore) misbehaving methods.\n\nIt can be set on the command line e.g.:\n\n```\n$ METHOD_FINDER_DEBUG=1 irb\n```\n\nOr you can toggle it inside IRB/Pry:\n\n```ruby\n\u003e\u003e MethodFinder.toggle_debug!\n```\n\n## DEVELOPMENT\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run\n`rake test` to run the tests. You can also run `bin/console` for an interactive\nprompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To\nrelease a new version, update the version number in `version.rb`, and then run\n`bundle exec rake release`, which will create a git tag for the version, push\ngit commits and tags, and push the `.gem` file to\n[rubygems.org](https://rubygems.org).\n\n## CONTRIBUTING\n\nDevelopment happens primarily on [Sourcehut](https://sr.ht/~citizen428/methodfinder/) where you can\n[file bugs](https://sr.ht/~citizen428/methodfinder/trackers), [discuss on the mailing list](https://sr.ht/~citizen428/methodfinder/lists) or [send patches](https://git.sr.ht/~citizen428/methodfinder/send-email).\n\nIf you really have to you can also contribute via https://github.com/citizen428/methodfinder, but I really prefer Sourcehut.\n\n## SEE ALSO\n\n### Gems\n\n- [irbtools](https://github.com/janlelis/irbtools) - improvements for Ruby's IRB console (includes methodfinder)\n\n### Misc\n\n- [Other Implementations](https://man.sr.ht/~citizen428/MethodFinder/) - a list of related projects in Ruby and other languages\n\n## VERSION\n\n2.2.4\n\n## AUTHOR\n\n- [Michael Kohl](https://citizen428.net/)\n\n## LICENSE\n\nThe gem is available as open source under the terms of the [MIT\nLicense](https://opensource.org/licenses/MIT).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcitizen428%2Fmethodfinder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcitizen428%2Fmethodfinder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcitizen428%2Fmethodfinder/lists"}