{"id":13395040,"url":"https://github.com/ruby/did_you_mean","last_synced_at":"2025-05-14T07:08:05.924Z","repository":{"id":13754633,"uuid":"16449263","full_name":"ruby/did_you_mean","owner":"ruby","description":"The gem that has been saving people from typos since 2014","archived":false,"fork":false,"pushed_at":"2025-01-10T04:19:16.000Z","size":2081,"stargazers_count":1871,"open_issues_count":6,"forks_count":113,"subscribers_count":57,"default_branch":"master","last_synced_at":"2025-04-10T23:37:28.964Z","etag":null,"topics":["hacktoberfest","ruby","spell-check","spellcheck","spelling","spelling-checker","spelling-correction","typo"],"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/ruby.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-02-02T05:09:58.000Z","updated_at":"2025-04-04T04:38:57.000Z","dependencies_parsed_at":"2024-03-19T02:37:20.947Z","dependency_job_id":"f8ea61ee-06a0-4fbc-a893-b24073b9700c","html_url":"https://github.com/ruby/did_you_mean","commit_stats":{"total_commits":728,"total_committers":43,"mean_commits":"16.930232558139537","dds":0.3612637362637363,"last_synced_commit":"94c7e8c169a1be43998d92e91b9c9f2dcd285555"},"previous_names":["yuki24/did_you_mean"],"tags_count":45,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby%2Fdid_you_mean","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby%2Fdid_you_mean/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby%2Fdid_you_mean/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby%2Fdid_you_mean/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ruby","download_url":"https://codeload.github.com/ruby/did_you_mean/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249517948,"owners_count":21284863,"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":["hacktoberfest","ruby","spell-check","spellcheck","spelling","spelling-checker","spelling-correction","typo"],"created_at":"2024-07-30T17:01:40.127Z","updated_at":"2025-04-22T13:24:18.001Z","avatar_url":"https://github.com/ruby.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# did_you_mean [![Gem Version](https://badge.fury.io/rb/did_you_mean.svg)](https://rubygems.org/gems/did_you_mean) [![Build status](https://github.com/ruby/did_you_mean/actions/workflows/ruby.yml/badge.svg)](https://github.com/ruby/did_you_mean/actions/workflows/ruby.yml)\n\n## Installation\n\nRuby 2.3 and later ships with this gem and it will automatically be `require`d when a Ruby process starts up. No special setup is required.\n\n## Examples\n\n### NameError\n\n#### Correcting a Misspelled Method Name\n\n```ruby\nmethosd\n# =\u003e NameError: undefined local variable or method `methosd' for main:Object\n#    Did you mean?  methods\n#                   method\n```\n\n#### Correcting a Misspelled Class Name\n\n```ruby\nOBject\n# =\u003e NameError: uninitialized constant OBject\n#    Did you mean?  Object\n```\n\n#### Suggesting an Instance Variable Name\n\n```ruby\n@full_name = \"Yuki Nishijima\"\nfirst_name, last_name = full_name.split(\" \")\n# =\u003e NameError: undefined local variable or method `full_name' for main:Object\n#    Did you mean?  @full_name\n```\n\n#### Correcting a Class Variable Name\n\n```ruby\n@@full_name = \"Yuki Nishijima\"\n@@full_anme\n# =\u003e NameError: uninitialized class variable @@full_anme in Object\n#    Did you mean?  @@full_name\n```\n\n### NoMethodError\n\n```ruby\nfull_name = \"Yuki Nishijima\"\nfull_name.starts_with?(\"Y\")\n# =\u003e NoMethodError: undefined method `starts_with?' for \"Yuki Nishijima\":String\n#    Did you mean?  start_with?\n```\n\n### KeyError\n\n```ruby\nhash = {foo: 1, bar: 2, baz: 3}\nhash.fetch(:fooo)\n# =\u003e KeyError: key not found: :fooo\n#    Did you mean?  :foo\n```\n\n### LoadError\n\n```ruby\nrequire 'net-http'\n# =\u003e LoadError (cannot load such file -- net-http)\n#    Did you mean?  net/http\n```\n\n### NoMatchingPatternKeyError\n\n```ruby\nhash = {foo: 1, bar: 2, baz: 3}\nhash =\u003e {fooo:}\n# =\u003e NoMatchingPatternKeyError: key not found: :fooo\n#    Did you mean?  :foo\n```\n\n## Using the `DidYouMean::SpellChecker`\n\nIf you need to programmatically find the closest matches to the user input, you could do so by re-using the `DidYouMean::SpellChecker` object.\n\n```ruby\nspell_checker = DidYouMean::SpellChecker.new(dictionary: ['email', 'fail', 'eval'])\n\nspell_checker.correct('meail') # =\u003e ['email']\nspell_checker.correct('afil')  # =\u003e ['fail']\n```\n\n## Disabling `did_you_mean`\n\nOccasionally, you may want to disable the `did_you_mean` gem for e.g. debugging issues in the error object itself. You\ncan disable it entirely by specifying `--disable-did_you_mean` option to the `ruby` command:\n\n```bash\n$ ruby --disable-did_you_mean -e \"1.zeor?\"\n-e:1:in `\u003cmain\u003e': undefined method `zeor?' for 1:Integer (NameError)\n```\n\nWhen you do not have direct access to the `ruby` command (e.g. `rails console`, `irb`), you could apply options using the\n`RUBYOPT` environment variable:\n\n```bash\n$ RUBYOPT='--disable-did_you_mean' irb\nirb:0\u003e 1.zeor?\n# =\u003e NoMethodError (undefined method `zeor?' for 1:Integer)\n```\n\n### Getting the original error message\n\nSometimes, you do not want to disable the gem entirely, but need to get the original error message without suggestions\n(e.g. testing). In this case, you could use the `#original_message` method on the error object:\n\n```ruby\nno_method_error = begin\n                    1.zeor?\n                  rescue NoMethodError =\u003e error\n                    error\n                  end\n\nno_method_error.message\n# =\u003e NoMethodError (undefined method `zeor?' for 1:Integer)\n#    Did you mean?  zero?\n\nno_method_error.original_message\n# =\u003e NoMethodError (undefined method `zeor?' for 1:Integer)\n```\n\n## Benchmarking\n\nPerformance is very important as the `did_you_mean` gem attempts to find the closest matches on the fly right after an exception\nis thrown. You could use the following rake tasks to get insights into how the gem performs:\n\n```bash\nbundle exec rake benchmark:ips:jaro\nbundle exec rake benchmark:ips:levenshtein\nbundle exec rake benchmark:memory\nbundle exec rake benchmark:memory:jaro\nbundle exec rake benchmark:memory:levenshtein\n```\n\n**Be sure to always use `bundle exec` otherwise it will activate the pre-installed version of the `did_you_mean`\n gem rather than using what's in the `lib/`.**\n\nYou could also use the [`benchmark-driver`](https://github.com/benchmark-driver/benchmark-driver) gem to know how each\nRuby performs differently.\n\n```bash\nbundle exec benchmark-driver benchmark/speed.yml --rbenv '2.6.0 --jit;2.6.0;2.5.3;truffleruby-1.0.0-rc10' --run-duration 30\n```\n\n## Contributing\n\n1. Fork it (https://github.com/ruby/did_you_mean/fork)\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Make sure all tests pass (`bundle exec rake`)\n5. Push to the branch (`git push origin my-new-feature`)\n6. Create new Pull Request\n\n## License\n\nCopyright (c) 2014-16 Yuki Nishijima. See MIT-LICENSE for further details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruby%2Fdid_you_mean","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fruby%2Fdid_you_mean","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruby%2Fdid_you_mean/lists"}