• Stars
    star
    246
  • Rank 164,726 (Top 4 %)
  • Language
    Ruby
  • Created almost 6 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

❓ 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: true
=> [:first, :take, :shift, :grep, :min]

# It works on several core modules including String
"HELLO".what_returns? "hello"
=> [:downcase, :swapcase]

# You can also specify a block that you want the method to accept
[1,2,3,4].what_returns?({true => [2,4], false => [1,3]}) { |n| n % 2 == 0 }
=> [:group_by]

# Object#what_mutates? tells you which method changes the object to the desired state
[1,2,3].what_mutates? [2, 3]
=> [:shift]

# You can also match on the return value
[1,2,3].what_mutates? [2, 3], returns: 1
=> [:shift]

[1,2,3].what_mutates? [2, 3], returns: 2
=> []

# You can specify which args to pass to the method
[1,2,3].what_mutates? [3], args: [2]
=> [:shift]

# It also works on a bunch of core modules
"HELLO".what_mutates? "hello"
=> [:swapcase!, :downcase!]

# And you can give it a block as well
[1,2,3,4].what_mutates? [2,4] { |n| n % 2 == 0 }
=> [:select!, :keep_if]

# You can use a lambda as an expected
[1,2,3,4].what_returns? -> (something_that) { something_that.to_i == 4 }
=> [:count, :length, :size, :last, :max]

# It respects the ruby version
# ruby 2.4.3
{a: 1, b: 2}.what_returns?({})
=> []
# ruby 2.5.0
{a: 1, b: 2}.what_returns?({})
=> [:slice]

Note to Self

Snippet to use in bin/console for finding methods for blacklisting:

Suggest::SUGGEST_MODS.flat_map { |k| [k].product(k.instance_methods) }.select { |k, v| v == :rand }.map { |k, v| k.instance_method(v).owner }.uniq

More Repositories

1

spy_rb

🔍 Transparent Test Spies for Ruby
Ruby
28
star
2

ruby_for_experienced_developers

📖 Ruby Jump-start for Experienced Devs
28
star
3

awesome-web-architecture

a list of links to help you make various important architectural decisions
10
star
4

minitest-tagz

🏷️ yet another tags implementation for Minitest
Ruby
6
star
5

spotifuby

🎵 Ruby server for interacting with Spotify on OSX
Ruby
6
star
6

dead_gems

💀 lists your app's unused gems
Ruby
5
star
7

shutdown_app

a demo app for playing with OS signals in Elixir
Elixir
4
star
8

game_jam-locked

https://jbodah.itch.io/admin-play
Ruby
3
star
9

awesome-links

when you are just too awesome for subcategories
3
star
10

minion_rb

:trollface: a dsl for proxying http traffic
Ruby
3
star
11

ascii_toons

🎨 make your projects more awesomer with customizable ascii art
Ruby
3
star
12

bgg_tools

Ruby
3
star
13

jbodah.github.io

my blog 2.0
CSS
3
star
14

firefox-bgg

a Firefox extension for expanding BoardGameGeek links by name
JavaScript
2
star
15

mosaic

📷 a demo app for generating photo mosaics from image collections
Ruby
1
star
16

super_logger

a beefed up Ruby logger
Ruby
1
star
17

exercism-solutions

My solutions to the exercism exercises
Ruby
1
star
18

tty-prompt-vim

adds Vim-like bindings to TTY::Prompt
Ruby
1
star
19

hubot-spotifuby

hubot script for spotifuby
CoffeeScript
1
star
20

spotifuby-client

***DEAD*** a client library for talking with a Spotifuby server
Ruby
1
star
21

run_length_encoder

💿 run-length encode/decode stuff
Ruby
1
star
22

forky

✌️ a library for simple parallel tasks
Ruby
1
star
23

godot-base

my base project for godot projects
Shell
1
star
24

with_thread_pool

simple lib for wrapping your enumerators with thread pools
Ruby
1
star
25

ssh_tunnel

a simple gem for creating SSH tunnels
Ruby
1
star