DEV Community

chenge
chenge

Posted on

A Fun Way to Find a Ruby Method with suggest Gem

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

require 'suggest'

# Object#what_returns? tells you which method returns the value
[1,2,3].what_returns? 1
=> [:first, :min]
Enter fullscreen mode Exit fullscreen mode

Really fun.

Top comments (0)