Class: Ivar::RaisePolicy
Overview
Policy that raises an exception for unknown instance variables
Instance Method Summary collapse
-
#handle_unknown_ivars(unknown_refs, _klass, allowed_ivars) ⇒ Object
Handle unknown instance variables by raising an exception.
Methods inherited from Policy
#find_closest_match, #format_warning
Instance Method Details
#handle_unknown_ivars(unknown_refs, _klass, allowed_ivars) ⇒ Object
Handle unknown instance variables by raising an exception
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ivar/policies.rb', line 80 def handle_unknown_ivars(unknown_refs, _klass, allowed_ivars) return if unknown_refs.empty? # Get the first unknown reference ref = unknown_refs.first ivar = ref[:name] suggestion = find_closest_match(ivar, allowed_ivars) suggestion_text = suggestion ? " Did you mean: #{suggestion}?" : "" # Raise an exception with location information = "#{ref[:path]}:#{ref[:line]}: unknown instance variable #{ivar}.#{suggestion_text}" raise NameError, end |