### Home Classes Methods

### In Files

- lib/yard/code_objects/method_object.rb

### Parent

Base

### Methods

- ::new
- #aliases
- #attr_info
- #constructor?
- #copyable_attributes
- #is_alias?
- #is_attribute?
- #is_explicit?
- #module_function?
- #name
- #overridden_method
- #path
- #reader?
- #scope=
- #sep
- #writer?

### Files

- LICENSE.txt
- MIT.txt

### Class/Module Index

Quicksearch

- YARD
- YARD::CLI
- YARD::CLI::Command
- YARD::CLI::CommandParser
- YARD::CLI::Config
- YARD::CLI::Diff
- YARD::CLI::Display
- YARD::CLI::Gems
- YARD::CLI::Graph
- YARD::CLI::GraphOptions
- YARD::CLI::Help
- YARD::CLI::I18n
- YARD::CLI::List
- YARD::CLI::MarkupTypes
- YARD::CLI::Server
- YARD::CLI::Stats
- YARD::CLI::YRI
- YARD::CLI::Yardoc
- YARD::CLI::YardocOptions
- YARD::CLI::YardoptsCommand
- YARD::CodeObjects
- YARD::CodeObjects::Base
- YARD::CodeObjects::ClassObject
- YARD::CodeObjects::ClassVariableObject
- YARD::CodeObjects::CodeObjectList
- YARD::CodeObjects::ConstantObject
- YARD::CodeObjects::ExtendedMethodObject
- YARD::CodeObjects::ExtraFileObject
- YARD::CodeObjects::MacroObject
- YARD::CodeObjects::MethodObject
- YARD::CodeObjects::ModuleObject
- YARD::CodeObjects::NamespaceObject
- YARD::CodeObjects::Proxy
- YARD::CodeObjects::ProxyMethodError
- YARD::CodeObjects::RootObject
- YARD::Config
- YARD::Docstring
- YARD::DocstringParser
- YARD::Handlers
- YARD::Handlers::Base
- YARD::Handlers::C
- YARD::Handlers::C::AliasHandler
- YARD::Handlers::C::AttributeHandler
- YARD::Handlers::C::Base
- YARD::Handlers::C::ClassHandler
- YARD::Handlers::C::ConstantHandler
- YARD::Handlers::C::HandlerMethods
- YARD::Handlers::C::InitHandler
- YARD::Handlers::C::MethodHandler
- YARD::Handlers::C::MixinHandler
- YARD::Handlers::C::ModuleHandler
- YARD::Handlers::C::OverrideCommentHandler
- YARD::Handlers::C::PathHandler
- YARD::Handlers::C::StructHandler
- YARD::Handlers::C::SymbolHandler
- YARD::Handlers::HandlerAborted
- YARD::Handlers::NamespaceMissingError
- YARD::Handlers::Processor
- YARD::Handlers::Ruby
- YARD::Handlers::Ruby::AliasHandler
- YARD::Handlers::Ruby::AttributeHandler
- YARD::Handlers::Ruby::Base
- YARD::Handlers::Ruby::ClassConditionHandler
- YARD::Handlers::Ruby::ClassHandler
- YARD::Handlers::Ruby::ClassVariableHandler
- YARD::Handlers::Ruby::CommentHandler
- YARD::Handlers::Ruby::ConstantHandler
- YARD::Handlers::Ruby::DSLHandler
- YARD::Handlers::Ruby::DSLHandlerMethods
- YARD::Handlers::Ruby::ExceptionHandler
- YARD::Handlers::Ruby::ExtendHandler
- YARD::Handlers::Ruby::HandlesExtension
- YARD::Handlers::Ruby::Legacy
- YARD::Handlers::Ruby::Legacy::AliasHandler
- YARD::Handlers::Ruby::Legacy::AttributeHandler
- YARD::Handlers::Ruby::Legacy::Base
- YARD::Handlers::Ruby::Legacy::ClassConditionHandler
- YARD::Handlers::Ruby::Legacy::ClassHandler
- YARD::Handlers::Ruby::Legacy::ClassVariableHandler
- YARD::Handlers::Ruby::Legacy::CommentHandler
- YARD::Handlers::Ruby::Legacy::ConstantHandler
- YARD::Handlers::Ruby::Legacy::DSLHandler
- YARD::Handlers::Ruby::Legacy::ExceptionHandler
- YARD::Handlers::Ruby::Legacy::ExtendHandler
- YARD::Handlers::Ruby::Legacy::MethodHandler
- YARD::Handlers::Ruby::Legacy::MixinHandler
- YARD::Handlers::Ruby::Legacy::ModuleFunctionHandler
- YARD::Handlers::Ruby::Legacy::ModuleHandler
- YARD::Handlers::Ruby::Legacy::PrivateConstantHandler
- YARD::Handlers::Ruby::Legacy::VisibilityHandler
- YARD::Handlers::Ruby::Legacy::YieldHandler
- YARD::Handlers::Ruby::MethodCallWrapper
- YARD::Handlers::Ruby::MethodConditionHandler
- YARD::Handlers::Ruby::MethodHandler
- YARD::Handlers::Ruby::MixinHandler
- YARD::Handlers::Ruby::ModuleFunctionHandler
- YARD::Handlers::Ruby::ModuleHandler
- YARD::Handlers::Ruby::PrivateConstantHandler
- YARD::Handlers::Ruby::StructHandlerMethods
- YARD::Handlers::Ruby::TestNodeWrapper
- YARD::Handlers::Ruby::VisibilityHandler
- YARD::Handlers::Ruby::YieldHandler
- YARD::I18n
- YARD::I18n::Locale
- YARD::I18n::Message
- YARD::I18n::Messages
- YARD::I18n::PotGenerator
- YARD::I18n::Text
- YARD::Logger
- YARD::Options
- YARD::Parser
- YARD::Parser::Base
- YARD::Parser::C
- YARD::Parser::C::BodyStatement
- YARD::Parser::C::CParser
- YARD::Parser::C::Comment
- YARD::Parser::C::CommentParser
- YARD::Parser::C::Statement
- YARD::Parser::C::ToplevelStatement
- YARD::Parser::OrderedParser
- YARD::Parser::ParserSyntaxError
- YARD::Parser::Ruby
- YARD::Parser::Ruby::AstNode
- YARD::Parser::Ruby::ClassNode
- YARD::Parser::Ruby::CommentNode
- YARD::Parser::Ruby::ConditionalNode
- YARD::Parser::Ruby::KeywordNode
- YARD::Parser::Ruby::Legacy
- YARD::Parser::Ruby::Legacy::RubyLex
- YARD::Parser::Ruby::Legacy::RubyLex::BufferedReader
- YARD::Parser::Ruby::Legacy::RubyParser
- YARD::Parser::Ruby::Legacy::RubyToken
- YARD::Parser::Ruby::Legacy::RubyToken::TkBlockContents
- YARD::Parser::Ruby::Legacy::RubyToken::TkError
- YARD::Parser::Ruby::Legacy::RubyToken::TkId
- YARD::Parser::Ruby::Legacy::RubyToken::TkKW
- YARD::Parser::Ruby::Legacy::RubyToken::TkNode
- YARD::Parser::Ruby::Legacy::RubyToken::TkOPASGN
- YARD::Parser::Ruby::Legacy::RubyToken::TkOp
- YARD::Parser::Ruby::Legacy::RubyToken::TkStatementEnd
- YARD::Parser::Ruby::Legacy::RubyToken::TkUnknownChar
- YARD::Parser::Ruby::Legacy::RubyToken::TkVal
- YARD::Parser::Ruby::Legacy::RubyToken::TkWhitespace
- YARD::Parser::Ruby::Legacy::RubyToken::Token
- YARD::Parser::Ruby::Legacy::Statement
- YARD::Parser::Ruby::Legacy::StatementList
- YARD::Parser::Ruby::Legacy::TokenList
- YARD::Parser::Ruby::LiteralNode
- YARD::Parser::Ruby::LoopNode
- YARD::Parser::Ruby::MethodCallNode
- YARD::Parser::Ruby::MethodDefinitionNode
- YARD::Parser::Ruby::ModuleNode
- YARD::Parser::Ruby::ParameterNode
- YARD::Parser::Ruby::ReferenceNode
- YARD::Parser::Ruby::RipperParser
- YARD::Parser::Ruby::RubyParser
- YARD::Parser::SourceParser
- YARD::Parser::UndocumentableError
- YARD::Rake
- YARD::Rake::YardocTask
- YARD::Registry
- YARD::RegistryStore
- YARD::Serializers
- YARD::Serializers::Base
- YARD::Serializers::FileSystemSerializer
- YARD::Serializers::ProcessSerializer
- YARD::Serializers::StdoutSerializer
- YARD::Serializers::YardocSerializer
- YARD::Server
- YARD::Server::Adapter
- YARD::Server::Commands
- YARD::Server::Commands::Base
- YARD::Server::Commands::DisplayFileCommand
- YARD::Server::Commands::DisplayObjectCommand
- YARD::Server::Commands::FramesCommand
- YARD::Server::Commands::LibraryCommand
- YARD::Server::Commands::LibraryIndexCommand
- YARD::Server::Commands::LibraryOptions
- YARD::Server::Commands::ListCommand
- YARD::Server::Commands::SearchCommand
- YARD::Server::Commands::StaticFileCommand
- YARD::Server::DocServerHelper
- YARD::Server::DocServerSerializer
- YARD::Server::FinishRequest
- YARD::Server::LibraryNotPreparedError
- YARD::Server::LibraryVersion
- YARD::Server::NotFoundError
- YARD::Server::RackAdapter
- YARD::Server::RackMiddleware
- YARD::Server::Router
- YARD::Server::StaticCaching
- YARD::Server::WebrickAdapter
- YARD::Server::WebrickServlet
- YARD::StubProxy
- YARD::Tags
- YARD::Tags::AttributeDirective
- YARD::Tags::DefaultFactory
- YARD::Tags::DefaultTag
- YARD::Tags::Directive
- YARD::Tags::EndGroupDirective
- YARD::Tags::GroupDirective
- YARD::Tags::Library
- YARD::Tags::MacroDirective
- YARD::Tags::MethodDirective
- YARD::Tags::OptionTag
- YARD::Tags::OverloadTag
- YARD::Tags::ParseDirective
- YARD::Tags::RefTag
- YARD::Tags::RefTagList
- YARD::Tags::ScopeDirective
- YARD::Tags::Tag
- YARD::Tags::TagFormatError
- YARD::Tags::VisibilityDirective
- YARD::Templates
- YARD::Templates::Engine
- YARD::Templates::ErbCache
- YARD::Templates::Helpers
- YARD::Templates::Helpers::BaseHelper
- YARD::Templates::Helpers::FilterHelper
- YARD::Templates::Helpers::HtmlHelper
- YARD::Templates::Helpers::HtmlSyntaxHighlightHelper
- YARD::Templates::Helpers::Markup
- YARD::Templates::Helpers::Markup::RDocMarkdown
- YARD::Templates::Helpers::Markup::RDocMarkup
- YARD::Templates::Helpers::Markup::RDocMarkup::RDocMarkup
- YARD::Templates::Helpers::Markup::RDocMarkup::RDocMarkup::RDocMarkupToHtml
- YARD::Templates::Helpers::Markup::RDocMarkup::RDocMarkupToHtml
- YARD::Templates::Helpers::MarkupHelper
- YARD::Templates::Helpers::MethodHelper
- YARD::Templates::Helpers::ModuleHelper
- YARD::Templates::Helpers::TextHelper
- YARD::Templates::Helpers::UMLHelper
- YARD::Templates::Section
- YARD::Templates::Template
- YARD::Templates::Template::ClassMethods
- YARD::Templates::TemplateOptions
- YARD::Verifier
- Gem
- Gem::DocManager
- Gem::SourceIndex
- Gem::Specification
- Rack
- Rack::Request
- WEBrick
- WEBrick::HTTPRequest
- Array
- File
- Hash
- Insertion
- Module
- Object
- String
- SymbolHash

No matching classes.

# YARD::CodeObjects::MethodObject

Represents a Ruby method in source

### Attributes

explicit[RW]

Whether the object is explicitly defined in source or whether it was inferred by a handler. For instance, attribute methods are generally inferred and therefore not explicitly defined in source.

@return [Boolean] whether the object is explicitly defined in source.

parameters[RW]

Returns the list of parameters parsed out of the method signature with their default values.

@return [Array<Array(String, String)>] a list of parameter names followed

    by their default values (or nil)

scope[R]

The scope of the method (`:class` or `:instance`)

@return [Symbol] the scope

### Public Class Methods

new(namespace, name, scope = :instance, &block) click to toggle source

Creates a new method object in `namespace` with `name` and an instance or class `scope`

If scope is `:module`, this object is instantiated as a public method in `:class` scope, but also creates a new (empty) method as a private `:instance` method on the same class or module.

@param [NamespaceObject] namespace the namespace @param [String, Symbol] name the method name @param [Symbol] scope `:instance`, `:class`, or `:module`

    # File lib/yard/code_objects/method_object.rb, line 33
    def initialize(namespace, name, scope = :instance, &block)
      @module_function = false
      @scope = nil

      # handle module function
      if scope == :module
        other = self.class.new(namespace, name, &block)
        other.visibility = :private
        scope = :class
        @module_function = true
      end

      @visibility = :public
      self.scope = scope
      self.parameters = []

      super
    end

### Public Instance Methods

aliases() click to toggle source

Returns all alias names of the object @return [Array<Symbol>] the alias names

    # File lib/yard/code_objects/method_object.rb, line 140
    def aliases
      list = []
      return list unless namespace.is_a?(NamespaceObject)
      namespace.aliases.each do |o, aname|
        list << o if aname == name && o.scope == scope
      end
      list
    end

attr_info() click to toggle source

Returns the read/writer info for the attribute if it is one @return [SymbolHash] if there is information about the attribute @return [nil] if the method is not an attribute @since 0.5.3

    # File lib/yard/code_objects/method_object.rb, line 91
    def attr_info
      return nil unless namespace.is_a?(NamespaceObject)
      namespace.attributes[scope][name.to_s.gsub(/=$/, '')]
    end

constructor?() click to toggle source

@return whether or not the method is the initialize constructor method

    # File lib/yard/code_objects/method_object.rb, line 76
    def constructor?
      name == :initialize && scope == :instance && namespace.is_a?(ClassObject)
    end

is_alias?() click to toggle source

Tests if the object is defined as an alias of another method @return [Boolean] whether the object is an alias

    # File lib/yard/code_objects/method_object.rb, line 117
    def is_alias?
      return false unless namespace.is_a?(NamespaceObject)
      namespace.aliases.has_key? self
    end

is_attribute?() click to toggle source

Tests if the object is defined as an attribute in the namespace @return [Boolean] whether the object is an attribute

    # File lib/yard/code_objects/method_object.rb, line 110
    def is_attribute?
      return false unless info = attr_info
      info[name.to_s =~ /=$/ ? :write : :read] ? true : false
    end

is_explicit?() click to toggle source

Tests boolean {explicit} value.

@return [Boolean] whether the method is explicitly defined in source

    # File lib/yard/code_objects/method_object.rb, line 125
    def is_explicit?
      explicit ? true : false
    end

module_function?() click to toggle source

@return [Boolean] whether or not this method was created as a module

    function

@since 0.8.0

    # File lib/yard/code_objects/method_object.rb, line 83
    def module_function?
      @module_function
    end

name(prefix = false) click to toggle source

Returns the name of the object.

@example The name of an instance method (with prefix)

    an_instance_method.name(true) # => "#mymethod"

@example The name of a class method (with prefix)

    a_class_method.name(true) # => "mymethod"

@param [Boolean] prefix whether or not to show the prefix @return [String] returns {sep} + `name` for an instance method if

    prefix is true

@return [Symbol] the name without {sep} if prefix is set to false

    # File lib/yard/code_objects/method_object.rb, line 170
    def name(prefix = false)
      prefix ? (sep == ISEP ? "#{sep}#{super}" : super.to_s) : super
    end

overridden_method() click to toggle source

@return [MethodObject] the object that this method overrides @return [nil] if it does not override a method @since 0.6.0

    # File lib/yard/code_objects/method_object.rb, line 132
    def overridden_method
      return nil if namespace.is_a?(Proxy)
      meths = namespace.meths(:all => true)
      meths.find {|m| m.path != path && m.name == name && m.scope == scope }
    end

path() click to toggle source

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

    # File lib/yard/code_objects/method_object.rb, line 152
    def path
      @path ||= if !namespace || namespace.path == ""
        sep + super
      else
        super
      end
    end

reader?() click to toggle source

@return [Boolean] whether the method is a reader attribute @since 0.5.3

    # File lib/yard/code_objects/method_object.rb, line 104
    def reader?
      !!((info = attr_info) && info[:read] == self)
    end

scope=(v) click to toggle source

Changes the scope of an object from :instance or :class @param [Symbol] v the new scope

    # File lib/yard/code_objects/method_object.rb, line 54
    def scope=(v)
      reregister = @scope ? true : false

      # handle module function
      if v == :module
        other = self.class.new(namespace, name)
        other.visibility = :private
        @visibility = :public
        @module_function = true
        @path = nil
      end

      YARD::Registry.delete(self)
      @path = nil
      @scope = v.to_sym
      if @scope == :module
        @scope = :class
      end
      YARD::Registry.register(self) if reregister
    end

sep() click to toggle source

Override separator to differentiate between class and instance methods. @return [String] "#" for an instance method, "." for class

    # File lib/yard/code_objects/method_object.rb, line 177
    def sep
      if scope == :class
        namespace && namespace != YARD::Registry.root ? CSEP : NSEP
      else
        ISEP
      end
    end

writer?() click to toggle source

@return [Boolean] whether the method is a writer attribute @since 0.5.3

    # File lib/yard/code_objects/method_object.rb, line 98
    def writer?
      !!((info = attr_info) && info[:write] == self)
    end

### Protected Instance Methods

copyable_attributes() click to toggle source

    # File lib/yard/code_objects/method_object.rb, line 187
    def copyable_attributes
      super - %(scope module_function)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.