lib/yard/code_objects/method_object.rb in yard-0.9.5 vs lib/yard/code_objects/method_object.rb in yard-0.9.6

- old
+ new

@@ -1,5 +1,6 @@ +# frozen_string_literal: true module YARD::CodeObjects register_separator CSEP, :method register_separator ISEP, :method # Represents a Ruby method in source @@ -67,13 +68,11 @@ end YARD::Registry.delete(self) @path = nil @scope = v.to_sym - if @scope == :module - @scope = :class - end + @scope = :class if @scope == :module YARD::Registry.register(self) if reregister end # @return whether or not the method is the #initialize constructor method def constructor? @@ -97,31 +96,38 @@ end # @return [Boolean] whether the method is a writer attribute # @since 0.5.3 def writer? - !!((info = attr_info) && info[:write] == self) + info = attr_info + info && info[:write] == self ? true : false end # @return [Boolean] whether the method is a reader attribute # @since 0.5.3 def reader? - !!((info = attr_info) && info[:read] == self) + info = attr_info + info && info[:read] == self ? true : false end # Tests if the object is defined as an attribute in the namespace # @return [Boolean] whether the object is an attribute def is_attribute? - return false unless info = attr_info - info[name.to_s =~ /=$/ ? :write : :read] ? true : false + info = attr_info + if info + read_or_write = name.to_s =~ /=$/ ? :write : :read + info[read_or_write] ? true : false + else + false + end end # Tests if the object is defined as an alias of another method # @return [Boolean] whether the object is an alias def is_alias? return false unless namespace.is_a?(NamespaceObject) - namespace.aliases.has_key? self + namespace.aliases.key? self end # Tests boolean {#explicit} value. # # @return [Boolean] whether the method is explicitly defined in source @@ -151,14 +157,10 @@ # Override path handling for instance methods in the root namespace # (they should still have a separator as a prefix). # @return [String] the path of a method def path - @path ||= if !namespace || namespace.path == "" - sep + super - else - super - end + @path ||= !namespace || namespace.path == "" ? sep + super : super end # Returns the name of the object. # # @example The name of an instance method (with prefix)