lib/zeitwerk/cref.rb in zeitwerk-2.6.18 vs lib/zeitwerk/cref.rb in zeitwerk-2.7.0

- old
+ new

@@ -24,51 +24,17 @@ @mod = mod @cname = cname @path = nil end - if Symbol.method_defined?(:name) - # Symbol#name was introduced in Ruby 3.0. It returns always the same - # frozen object, so we may save a few string allocations. - # - # @sig () -> String - def path - @path ||= Object.equal?(@mod) ? @cname.name : "#{real_mod_name(@mod)}::#{@cname.name}" - end - else - # @sig () -> String - def path - @path ||= Object.equal?(@mod) ? @cname.to_s : "#{real_mod_name(@mod)}::#{@cname}" - end + # @sig () -> String + def path + @path ||= Object.equal?(@mod) ? @cname.name : "#{real_mod_name(@mod)}::#{@cname.name}".freeze end - # The autoload? predicate takes into account the ancestor chain of the - # receiver, like const_defined? and other methods in the constants API do. - # - # For example, given - # - # class A - # autoload :X, "x.rb" - # end - # - # class B < A - # end - # - # B.autoload?(:X) returns "x.rb". - # - # We need a way to retrieve it ignoring ancestors. - # # @sig () -> String? - if method(:autoload?).arity == 1 - # @sig () -> String? - def autoload? - @mod.autoload?(@cname) if self.defined? - end - else - # @sig () -> String? - def autoload? - @mod.autoload?(@cname, false) - end + def autoload? + @mod.autoload?(@cname, false) end # @sig (String) -> bool def autoload(abspath) @mod.autoload(@cname, abspath)