Class: RDocF95::RI::NameDescriptor

Inherits:
Object
  • Object
show all
Defined in:
lib/rdoc-f95/ri/util.rb

Overview

Break argument into its constituent class or module names, an optional method type, and a method name

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arg) ⇒ NameDescriptor

arg may be

  1. A class or module name (optionally qualified with other class or module names (Kernel, File::Stat etc)

  2. A method name

  3. A method name qualified by a optionally fully qualified class or module name

We're fairly casual about delimiters: folks can say Kernel::puts, Kernel.puts, or Kernel#puts for example. There's one exception: if you say IO::read, we look for a class method, but if you say IO.read, we look for an instance method


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/rdoc-f95/ri/util.rb', line 33

def initialize(arg)
  @class_names = []
  separator = nil

  tokens = arg.split(/(\.|::|#)/)

  # Skip leading '::', '#' or '.', but remember it might
  # be a method name qualifier
  separator = tokens.shift if tokens[0] =~ /^(\.|::|#)/

  # Skip leading '::', but remember we potentially have an inst

  # leading stuff must be class names

  while tokens[0] =~ /^[A-Z]/
    @class_names << tokens.shift
    unless tokens.empty?
      separator = tokens.shift
      break unless separator == "::"
    end
  end

  # Now must have a single token, the method name, or an empty array
  unless tokens.empty?
    @method_name = tokens.shift
    # We may now have a trailing !, ?, or = to roll into
    # the method name
    if !tokens.empty? && tokens[0] =~ /^[!?=]$/
      @method_name << tokens.shift
    end

    if @method_name =~ /::|\.|#/ or !tokens.empty?
      raise RiError.new("Bad argument: #{arg}") 
    end
    if separator && separator != '.'
      @is_class_method = separator == "::"
    end
  end
end

Instance Attribute Details

#class_namesObject (readonly)

Returns the value of attribute class_names


11
12
13
# File 'lib/rdoc-f95/ri/util.rb', line 11

def class_names
  @class_names
end

#is_class_methodObject (readonly)

true and false have the obvious meaning. nil means we don't care


17
18
19
# File 'lib/rdoc-f95/ri/util.rb', line 17

def is_class_method
  @is_class_method
end

#method_nameObject (readonly)

Returns the value of attribute method_name


12
13
14
# File 'lib/rdoc-f95/ri/util.rb', line 12

def method_name
  @method_name
end

Instance Method Details

#full_class_nameObject

Return the full class name (with '::' between the components) or “” if there's no class name


76
77
78
# File 'lib/rdoc-f95/ri/util.rb', line 76

def full_class_name
  @class_names.join("::")
end