Sha256: 8b6f441ea72a9e540937b87ec583966c155d1f436f929dc82d0ea5acd3e3635b
Contents?: true
Size: 713 Bytes
Versions: 3
Compression:
Stored size: 713 Bytes
Contents
# frozen_string_literal: true class NameError # Extract the name of the missing constant from the exception message. # # begin # HelloWorld # rescue NameError => e # e.missing_name # end # # => "HelloWorld" def missing_name if /undefined local variable or method/ !~ message $1 if /((::)?([A-Z]\w*)(::[A-Z]\w*)*)$/ =~ message end end # Was this exception raised because the given name was missing? # # begin # HelloWorld # rescue NameError => e # e.missing_name?("HelloWorld") # end # # => true def missing_name?(name) if name.is_a? Symbol self.name == name else missing_name == name.to_s end end end
Version data entries
3 entries across 3 versions & 2 rubygems