class MarkdownRubyDocumentation::Method

Constants

InvalidMethodReference

Attributes

file_path[RW]
line_no[RW]
method_reference[R]
visibility[R]

Public Class Methods

===(value) click to toggle source
Calls superclass method
# File lib/markdown_ruby_documentation/method.rb, line 48
def self.===(value)
  if value.is_a?(String)
    value.include?(type_symbol) && !!/\A[:A-Za-z_0-9!?#{type_symbol}]+\z/.match(value)
  else
    super
  end
end
create(method_reference, null_method: false, context: Kernel, visibility: :public, file_path: nil) click to toggle source

@param [String] method_reference @example

".class_method_name" class method in the current scope.
"Constant.class_method_name" class method on a specific constant.
"SomeClass#instance_method_name" an instance method on a specific constant.
"#instance_method_name" an instance method in the current scope.
# File lib/markdown_ruby_documentation/method.rb, line 22
def self.create(method_reference, null_method: false, context: Kernel, visibility: :public, file_path: nil)
  return method_reference if method_reference.is_a?(Method)
  case method_reference
  when InstanceMethod
    InstanceMethod.new(method_reference, context: context, visibility: visibility, file_path: file_path)
  when ClassMethod
    ClassMethod.new(method_reference, context: context, visibility: visibility, file_path: file_path)
  else
    if null_method
      NullMethod.new(method_reference, context: context, visibility: visibility, file_path: file_path)
    else
      raise InvalidMethodReference, "method_reference is formatted incorrectly: '#{method_reference}'"
    end
  end
end
new(method_reference, context: Kernel, visibility: :public, file_path: nil, line_no: nil) click to toggle source
# File lib/markdown_ruby_documentation/method.rb, line 8
def initialize(method_reference, context: Kernel, visibility: :public, file_path: nil, line_no: nil)
  @method_reference = method_reference.to_s
  @context          = context
  @visibility       = visibility
  @file_path        = file_path
  @line_no          = line_no
end

Public Instance Methods

==(other_method) click to toggle source
# File lib/markdown_ruby_documentation/method.rb, line 38
def ==(other_method)
  self.class == other_method.class && other_method.method_reference == self.method_reference
end
Also aliased as: eql?
context() click to toggle source

@return [Class]

# File lib/markdown_ruby_documentation/method.rb, line 62
def context
  if method_reference.start_with?(type_symbol)
    @context
  else
    constant = method_reference.split(type_symbol).first
    begin
      constant.constantize
    rescue NameError
      @context.const_get(constant)
    end
  end
end
context_name() click to toggle source
# File lib/markdown_ruby_documentation/method.rb, line 75
def context_name
  if method_reference.start_with?(type_symbol)
    @context.name
  else
    method_reference.split(type_symbol).first
  end
end
eql?(other_method)
Alias for: ==
hash() click to toggle source
# File lib/markdown_ruby_documentation/method.rb, line 44
def hash
  @method_reference.hash
end
inspect() click to toggle source

@return [String]

# File lib/markdown_ruby_documentation/method.rb, line 94
def inspect
  "#<#{self.class.name} #{to_s}>"
end
name() click to toggle source

@return [Symbol]

# File lib/markdown_ruby_documentation/method.rb, line 84
def name
  method_reference.split(type_symbol).last.try!(:to_sym)
end
source_location() click to toggle source
# File lib/markdown_ruby_documentation/method.rb, line 103
def source_location
  if file_path && line_no
    [file_path, line_no]
  else
    context.public_send(type, name).source_location
  end
end
to_proc() click to toggle source

@return [Proc]

# File lib/markdown_ruby_documentation/method.rb, line 99
def to_proc
  context.public_send(type, name)
end
to_s() click to toggle source

@return [String]

# File lib/markdown_ruby_documentation/method.rb, line 89
def to_s
  method_reference
end
type() click to toggle source
# File lib/markdown_ruby_documentation/method.rb, line 111
def type
  raise NotImplementedError
end
type_symbol() click to toggle source

@return [String]

# File lib/markdown_ruby_documentation/method.rb, line 57
def type_symbol
  self.class.type_symbol
end