Suggest.rb - tells you which method does the thing you want to do

Phil Nash - Jan 21 '19 - - Dev Community

I came across this project the other day and thought it was an interesting way to augment learning and using Ruby.

Suggest gives objects two extra methods; what_returns? and what_mutates?. Both methods take a result that you are interested in and return the methods you could call on the object to get that result.

For example:

require 'suggest'

[1,2,3].what_returns? 1
=> [:first, :min]
Enter fullscreen mode Exit fullscreen mode

I can see this being useful when you're tooling about in irb and you're sure that there is a method that does the thing you want but you can't remember it. It could save a trip to search the docs and could even suggest better methods than the one you were thinking of.

Check it out on GitHub:

GitHub logo jbodah / suggest_rb

❓ tells you which method does the thing you want to do

Suggest

tells you which method does the thing you want to do

Disclaimer

I don't recommend you ship this in your Gemfile. Keep it in your system's gems (e.g. gem install) and load it as needed (e.g. irb -rsuggest, RUBY_OPT=-rsuggest irb, etc)

Installation

gem install suggest_rb

Usage

require 'suggest'
# Object#what_returns? tells you which method returns the value
[1,2,3].what_returns? 1
=> [:first, :min]

# You can also specify the args you want that method to take
[1,2,3].what_returns? [1], args: [1]
=> [:first, :take, :grep, :min]

# By default, it only returns methods that don't mutate the object
[1,2,3].what_returns? [1], args: [1], allow_mutation
Enter fullscreen mode Exit fullscreen mode
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .