Module: Suggest::Mixin

Defined in:
lib/suggest.rb

Instance Method Summary collapse

Instance Method Details

#what_mutates?(expected, args: [], allow_not_public: false, **opts, &block) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/suggest.rb', line 73

def what_mutates?(expected, args: [], allow_not_public: false, **opts, &block)
  methods.map(&method(:method)).select(&SELECTOR).select do |m|
    arity = m.arity
    next unless arity < 0 || arity == args.count

    post = clone

    next if block && UNSAFE_WITH_BLOCK.include?([m.owner, m.name])
    result = post.__send__(allow_not_public ? :send : :public_send, m.name, *args, &block) rescue next

    next if opts.key?(:returns) && !Suggest.eq?(result, opts[:returns])

    Suggest.eq?(post, expected)
  end.map(&:name)
end

#what_returns?(expected, args: [], allow_mutation: false, allow_not_public: false, &block) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/suggest.rb', line 57

def what_returns?(expected, args: [], allow_mutation: false, allow_not_public: false, &block)
  methods.map(&method(:method)).select(&SELECTOR).select do |m|
    arity = m.arity
    next unless arity < 0 || arity == args.count

    post = clone

    next if block && UNSAFE_WITH_BLOCK.include?([m.owner, m.name])
    result = post.__send__(allow_not_public ? :send : :public_send, m.name, *args, &block) rescue next

    next unless allow_mutation || self == post

    Suggest.eq?(result, expected)
  end.map(&:name)
end