{"action":"created","comment":{"url":"https://api.github.com/repos/yuki24/did_you_mean/pulls/comments/22758654","id":22758654,"diff_hunk":"@@ -14,8 +15,10 @@ def each(&block) words.each(&block); end\n     def similar_to(target_word)\n       target_word = target_word.to_s\n       threshold   = threshold(target_word)\n-\n-      select {|word| Levenshtein.distance(word.to_s, target_word) <= threshold }\n+      map { |word| [Levenshtein.distance(word.to_s, target_word), word] }\n+        .select { |distance, _| distance <= threshold }\n+        .sort { |a, b| a[0] <=> b[0] }\n+        .map { |_, word| word }","path":"lib/did_you_mean/word_collection.rb","position":14,"original_position":14,"commit_id":"e33e7ba113d8619f27d45fe3dc5bc577c7e0b85e","original_commit_id":"e33e7ba113d8619f27d45fe3dc5bc577c7e0b85e","user":{"login":"yuki24","id":386234,"avatar_url":"https://avatars.githubusercontent.com/u/386234?v=3","gravatar_id":"","url":"https://api.github.com/users/yuki24","html_url":"https://github.com/yuki24","followers_url":"https://api.github.com/users/yuki24/followers","following_url":"https://api.github.com/users/yuki24/following{/other_user}","gists_url":"https://api.github.com/users/yuki24/gists{/gist_id}","starred_url":"https://api.github.com/users/yuki24/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yuki24/subscriptions","organizations_url":"https://api.github.com/users/yuki24/orgs","repos_url":"https://api.github.com/users/yuki24/repos","events_url":"https://api.github.com/users/yuki24/events{/privacy}","received_events_url":"https://api.github.com/users/yuki24/received_events","type":"User","site_admin":false},"body":"I like what you wanted to do here, but creating an array for each word could be slower than several distance re-calculations after `#select`. And again, don't include multiple changes in one pull request.","created_at":"2015-01-10T12:44:06Z","updated_at":"2015-01-10T12:44:06Z","html_url":"https://github.com/yuki24/did_you_mean/pull/28#discussion_r22758654","pull_request_url":"https://api.github.com/repos/yuki24/did_you_mean/pulls/28","_links":{"self":{"href":"https://api.github.com/repos/yuki24/did_you_mean/pulls/comments/22758654"},"html":{"href":"https://github.com/yuki24/did_you_mean/pull/28#discussion_r22758654"},"pull_request":{"href":"https://api.github.com/repos/yuki24/did_you_mean/pulls/28"}}},"pull_request":{"url":"https://api.github.com/repos/yuki24/did_you_mean/pulls/28","id":27134455,"html_url":"https://github.com/yuki24/did_you_mean/pull/28","diff_url":"https://github.com/yuki24/did_you_mean/pull/28.diff","patch_url":"https://github.com/yuki24/did_you_mean/pull/28.patch","issue_url":"https://api.github.com/repos/yuki24/did_you_mean/issues/28","number":28,"state":"open","locked":false,"title":"NoMethodError fix for Similar ClassNames and MethodNames","user":{"login":"tleish","id":1099993,"avatar_url":"https://avatars.githubusercontent.com/u/1099993?v=3","gravatar_id":"","url":"https://api.github.com/users/tleish","html_url":"https://github.com/tleish","followers_url":"https://api.github.com/users/tleish/followers","following_url":"https://api.github.com/users/tleish/following{/other_user}","gists_url":"https://api.github.com/users/tleish/gists{/gist_id}","starred_url":"https://api.github.com/users/tleish/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tleish/subscriptions","organizations_url":"https://api.github.com/users/tleish/orgs","repos_url":"https://api.github.com/users/tleish/repos","events_url":"https://api.github.com/users/tleish/events{/privacy}","received_events_url":"https://api.github.com/users/tleish/received_events","type":"User","site_admin":false},"body":"(deleted previous pull requests to make it cleaner)\r\n\r\nThese code changes resolve #24 using the SimilarMethodFinder and SimilarClassFinder.\r\n\r\n* Checks to see if the receiver is a Class or Module\r\n* If Class or Module, then use SimilarClassFinder for classes other than current receiver\r\n* For each SimilarClass use SimilarMethodFinder\r\n* Return Results\r\n\r\nI also noticed that when in Rails using development mode and cache_class set to false if I have 2 classes (User and Users), and I attempt to access the active record model (e.g. Users.first), the suggestion \"Did you mean? User.first\" still didn't work unless I had already loaded the User class. I see users do this all the time with active record models, forgetting the plural vs singular form.\r\n\r\nTo solve this, I added a simple method (if Rails is loaded) that takes the receiver class and attempts to autoload a safe_contantize of the pluralized or singular version of the Class name (see autoload_class_name_inflector). This resolves the issue.\r\n\r\nAlso improved the order in which suggestions are recommended.","created_at":"2015-01-09T22:29:54Z","updated_at":"2015-01-10T12:44:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7652c766287723ae20cbc8021555f2399e6dccaa","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/yuki24/did_you_mean/pulls/28/commits","review_comments_url":"https://api.github.com/repos/yuki24/did_you_mean/pulls/28/comments","review_comment_url":"https://api.github.com/repos/yuki24/did_you_mean/pulls/comments/{number}","comments_url":"https://api.github.com/repos/yuki24/did_you_mean/issues/28/comments","statuses_url":"https://api.github.com/repos/yuki24/did_you_mean/statuses/e33e7ba113d8619f27d45fe3dc5bc577c7e0b85e","head":{"label":"tleish:master","ref":"master","sha":"e33e7ba113d8619f27d45fe3dc5bc577c7e0b85e","user":{"login":"tleish","id":1099993,"avatar_url":"https://avatars.githubusercontent.com/u/1099993?v=3","gravatar_id":"","url":"https://api.github.com/users/tleish","html_url":"https://github.com/tleish","followers_url":"https://api.github.com/users/tleish/followers","following_url":"https://api.github.com/users/tleish/following{/other_user}","gists_url":"https://api.github.com/users/tleish/gists{/gist_id}","starred_url":"https://api.github.com/users/tleish/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tleish/subscriptions","organizations_url":"https://api.github.com/users/tleish/orgs","repos_url":"https://api.github.com/users/tleish/repos","events_url":"https://api.github.com/users/tleish/events{/privacy}","received_events_url":"https://api.github.com/users/tleish/received_events","type":"User","site_admin":false},"repo":{"id":29036868,"name":"did_you_mean","full_name":"tleish/did_you_mean","owner":{"login":"tleish","id":1099993,"avatar_url":"https://avatars.githubusercontent.com/u/1099993?v=3","gravatar_id":"","url":"https://api.github.com/users/tleish","html_url":"https://github.com/tleish","followers_url":"https://api.github.com/users/tleish/followers","following_url":"https://api.github.com/users/tleish/following{/other_user}","gists_url":"https://api.github.com/users/tleish/gists{/gist_id}","starred_url":"https://api.github.com/users/tleish/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tleish/subscriptions","organizations_url":"https://api.github.com/users/tleish/orgs","repos_url":"https://api.github.com/users/tleish/repos","events_url":"https://api.github.com/users/tleish/events{/privacy}","received_events_url":"https://api.github.com/users/tleish/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tleish/did_you_mean","description":"\"Did you mean?\" experience in Ruby","fork":true,"url":"https://api.github.com/repos/tleish/did_you_mean","forks_url":"https://api.github.com/repos/tleish/did_you_mean/forks","keys_url":"https://api.github.com/repos/tleish/did_you_mean/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tleish/did_you_mean/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tleish/did_you_mean/teams","hooks_url":"https://api.github.com/repos/tleish/did_you_mean/hooks","issue_events_url":"https://api.github.com/repos/tleish/did_you_mean/issues/events{/number}","events_url":"https://api.github.com/repos/tleish/did_you_mean/events","assignees_url":"https://api.github.com/repos/tleish/did_you_mean/assignees{/user}","branches_url":"https://api.github.com/repos/tleish/did_you_mean/branches{/branch}","tags_url":"https://api.github.com/repos/tleish/did_you_mean/tags","blobs_url":"https://api.github.com/repos/tleish/did_you_mean/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tleish/did_you_mean/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tleish/did_you_mean/git/refs{/sha}","trees_url":"https://api.github.com/repos/tleish/did_you_mean/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tleish/did_you_mean/statuses/{sha}","languages_url":"https://api.github.com/repos/tleish/did_you_mean/languages","stargazers_url":"https://api.github.com/repos/tleish/did_you_mean/stargazers","contributors_url":"https://api.github.com/repos/tleish/did_you_mean/contributors","subscribers_url":"https://api.github.com/repos/tleish/did_you_mean/subscribers","subscription_url":"https://api.github.com/repos/tleish/did_you_mean/subscription","commits_url":"https://api.github.com/repos/tleish/did_you_mean/commits{/sha}","git_commits_url":"https://api.github.com/repos/tleish/did_you_mean/git/commits{/sha}","comments_url":"https://api.github.com/repos/tleish/did_you_mean/comments{/number}","issue_comment_url":"https://api.github.com/repos/tleish/did_you_mean/issues/comments/{number}","contents_url":"https://api.github.com/repos/tleish/did_you_mean/contents/{+path}","compare_url":"https://api.github.com/repos/tleish/did_you_mean/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tleish/did_you_mean/merges","archive_url":"https://api.github.com/repos/tleish/did_you_mean/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tleish/did_you_mean/downloads","issues_url":"https://api.github.com/repos/tleish/did_you_mean/issues{/number}","pulls_url":"https://api.github.com/repos/tleish/did_you_mean/pulls{/number}","milestones_url":"https://api.github.com/repos/tleish/did_you_mean/milestones{/number}","notifications_url":"https://api.github.com/repos/tleish/did_you_mean/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tleish/did_you_mean/labels{/name}","releases_url":"https://api.github.com/repos/tleish/did_you_mean/releases{/id}","created_at":"2015-01-09T21:47:41Z","updated_at":"2015-01-09T22:27:47Z","pushed_at":"2015-01-09T22:27:47Z","git_url":"git://github.com/tleish/did_you_mean.git","ssh_url":"git@github.com:tleish/did_you_mean.git","clone_url":"https://github.com/tleish/did_you_mean.git","svn_url":"https://github.com/tleish/did_you_mean","homepage":null,"size":2266,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"yuki24:master","ref":"master","sha":"db461f3339ed3fc42284cd85a69f9bc8d716ec3a","user":{"login":"yuki24","id":386234,"avatar_url":"https://avatars.githubusercontent.com/u/386234?v=3","gravatar_id":"","url":"https://api.github.com/users/yuki24","html_url":"https://github.com/yuki24","followers_url":"https://api.github.com/users/yuki24/followers","following_url":"https://api.github.com/users/yuki24/following{/other_user}","gists_url":"https://api.github.com/users/yuki24/gists{/gist_id}","starred_url":"https://api.github.com/users/yuki24/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yuki24/subscriptions","organizations_url":"https://api.github.com/users/yuki24/orgs","repos_url":"https://api.github.com/users/yuki24/repos","events_url":"https://api.github.com/users/yuki24/events{/privacy}","received_events_url":"https://api.github.com/users/yuki24/received_events","type":"User","site_admin":false},"repo":{"id":16449263,"name":"did_you_mean","full_name":"yuki24/did_you_mean","owner":{"login":"yuki24","id":386234,"avatar_url":"https://avatars.githubusercontent.com/u/386234?v=3","gravatar_id":"","url":"https://api.github.com/users/yuki24","html_url":"https://github.com/yuki24","followers_url":"https://api.github.com/users/yuki24/followers","following_url":"https://api.github.com/users/yuki24/following{/other_user}","gists_url":"https://api.github.com/users/yuki24/gists{/gist_id}","starred_url":"https://api.github.com/users/yuki24/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yuki24/subscriptions","organizations_url":"https://api.github.com/users/yuki24/orgs","repos_url":"https://api.github.com/users/yuki24/repos","events_url":"https://api.github.com/users/yuki24/events{/privacy}","received_events_url":"https://api.github.com/users/yuki24/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/yuki24/did_you_mean","description":"\"Did you mean?\" experience in Ruby","fork":false,"url":"https://api.github.com/repos/yuki24/did_you_mean","forks_url":"https://api.github.com/repos/yuki24/did_you_mean/forks","keys_url":"https://api.github.com/repos/yuki24/did_you_mean/keys{/key_id}","collaborators_url":"https://api.github.com/repos/yuki24/did_you_mean/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/yuki24/did_you_mean/teams","hooks_url":"https://api.github.com/repos/yuki24/did_you_mean/hooks","issue_events_url":"https://api.github.com/repos/yuki24/did_you_mean/issues/events{/number}","events_url":"https://api.github.com/repos/yuki24/did_you_mean/events","assignees_url":"https://api.github.com/repos/yuki24/did_you_mean/assignees{/user}","branches_url":"https://api.github.com/repos/yuki24/did_you_mean/branches{/branch}","tags_url":"https://api.github.com/repos/yuki24/did_you_mean/tags","blobs_url":"https://api.github.com/repos/yuki24/did_you_mean/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/yuki24/did_you_mean/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/yuki24/did_you_mean/git/refs{/sha}","trees_url":"https://api.github.com/repos/yuki24/did_you_mean/git/trees{/sha}","statuses_url":"https://api.github.com/repos/yuki24/did_you_mean/statuses/{sha}","languages_url":"https://api.github.com/repos/yuki24/did_you_mean/languages","stargazers_url":"https://api.github.com/repos/yuki24/did_you_mean/stargazers","contributors_url":"https://api.github.com/repos/yuki24/did_you_mean/contributors","subscribers_url":"https://api.github.com/repos/yuki24/did_you_mean/subscribers","subscription_url":"https://api.github.com/repos/yuki24/did_you_mean/subscription","commits_url":"https://api.github.com/repos/yuki24/did_you_mean/commits{/sha}","git_commits_url":"https://api.github.com/repos/yuki24/did_you_mean/git/commits{/sha}","comments_url":"https://api.github.com/repos/yuki24/did_you_mean/comments{/number}","issue_comment_url":"https://api.github.com/repos/yuki24/did_you_mean/issues/comments/{number}","contents_url":"https://api.github.com/repos/yuki24/did_you_mean/contents/{+path}","compare_url":"https://api.github.com/repos/yuki24/did_you_mean/compare/{base}...{head}","merges_url":"https://api.github.com/repos/yuki24/did_you_mean/merges","archive_url":"https://api.github.com/repos/yuki24/did_you_mean/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/yuki24/did_you_mean/downloads","issues_url":"https://api.github.com/repos/yuki24/did_you_mean/issues{/number}","pulls_url":"https://api.github.com/repos/yuki24/did_you_mean/pulls{/number}","milestones_url":"https://api.github.com/repos/yuki24/did_you_mean/milestones{/number}","notifications_url":"https://api.github.com/repos/yuki24/did_you_mean/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/yuki24/did_you_mean/labels{/name}","releases_url":"https://api.github.com/repos/yuki24/did_you_mean/releases{/id}","created_at":"2014-02-02T05:09:58Z","updated_at":"2015-01-10T01:47:43Z","pushed_at":"2015-01-09T13:46:49Z","git_url":"git://github.com/yuki24/did_you_mean.git","ssh_url":"git@github.com:yuki24/did_you_mean.git","clone_url":"https://github.com/yuki24/did_you_mean.git","svn_url":"https://github.com/yuki24/did_you_mean","homepage":null,"size":2266,"stargazers_count":1114,"watchers_count":1114,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":24,"mirror_url":null,"open_issues_count":2,"forks":24,"open_issues":2,"watchers":1114,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/yuki24/did_you_mean/pulls/28"},"html":{"href":"https://github.com/yuki24/did_you_mean/pull/28"},"issue":{"href":"https://api.github.com/repos/yuki24/did_you_mean/issues/28"},"comments":{"href":"https://api.github.com/repos/yuki24/did_you_mean/issues/28/comments"},"review_comments":{"href":"https://api.github.com/repos/yuki24/did_you_mean/pulls/28/comments"},"review_comment":{"href":"https://api.github.com/repos/yuki24/did_you_mean/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/yuki24/did_you_mean/pulls/28/commits"},"statuses":{"href":"https://api.github.com/repos/yuki24/did_you_mean/statuses/e33e7ba113d8619f27d45fe3dc5bc577c7e0b85e"}}}}