Module: Suggest
- Defined in:
- lib/suggest.rb,
lib/suggest/version.rb
Defined Under Namespace
Modules: Mixin
Constant Summary collapse
- SUGGEST_MODS =
Set.new([ Array, BasicObject, Comparable, Complex, Enumerable, FalseClass, Float, Hash, Integer, Math, NilClass, Numeric, Range, Regexp, Regexp, Set, String, Struct, Symbol, Time, TrueClass, ])
- UNSAFE_WITH_BLOCK =
Set.new([ [Array, :cycle], [Enumerable, :cycle] ])
- INCONSISTENT =
Set.new([ [Array, :sample], [Array, :shuffle], [Array, :shuffle!] ])
- TOO_COMPLICATED =
Set.new([ [String, :freeze], [Set, :freeze], [Set, :taint], [Set, :untaint], [Numeric, :singleton_method_added], [Numeric, :clone], [Numeric, :dup], ])
- SELECTOR =
->(m) do SUGGEST_MODS.include?(m.owner) && !INCONSISTENT.include?([m.owner, m.name]) && !TOO_COMPLICATED.include?([m.owner, m.name]) end
- VERSION =
"0.5.1"
Class Method Summary collapse
- .eq?(result, expected) ⇒ Boolean
-
.suggestable!(mod, **corrections) ⇒ Object
unsafe_with_block: [], inconsistent: [], too_complicated: [].
- .suggestable_methods ⇒ Object
Class Method Details
.eq?(result, expected) ⇒ Boolean
94 95 96 |
# File 'lib/suggest.rb', line 94 def self.eq?(result, expected) result.is_a?(expected.class) && result == expected end |
.suggestable!(mod, **corrections) ⇒ Object
unsafe_with_block: [], inconsistent: [], too_complicated: []
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/suggest.rb', line 98 def self.suggestable!(mod, **corrections) # unsafe_with_block: [], inconsistent: [], too_complicated: [] raise ArgumentError.new("Must support smart comparison (implement «#{mod}#==»)") if mod.instance_method(:==).owner == BasicObject SUGGEST_MODS << mod %w[unsafe_with_block inconsistent too_complicated].each do |correction| c = Suggest.const_get(correction.upcase) [mod].product(corrections.fetch(correction, [])).each(&c.method(:<<)) end mod.include(Suggest::Mixin) unless mod.ancestors.include?(Suggest::Mixin) end |
.suggestable_methods ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'lib/suggest.rb', line 109 def self.suggestable_methods SUGGEST_MODS.each_with_object([]) do |mod, candidates| owned_methods = mod.instance_methods.select { |m| mod.instance_method(m).owner == mod } next if owned_methods.none? candidates += [mod].product(owned_methods) end.reject do |m| INCONSISTENT.include?(m) || TOO_COMPLICATED.include?(m) end end |