Class: FastRI::NameDescriptor
- Inherits:
-
Object
- Object
- FastRI::NameDescriptor
- Defined in:
- lib/fastri/name_descriptor.rb
Overview
Alternative NameDescriptor implementation which doesn’t require class/module names to be properly capitalized.
Rules:
-
#foo
: instance methodfoo
-
.foo
: methodfoo
(either singleton or instance) -
::foo
: singleton methodfoo
-
foo::bar#bar<tt>: instance method bar under <tt>foo::bar
-
foo::bar.bar<tt>: either singleton or instance method bar under <tt>foo::bar
-
<tt>foo::bar::Baz<tt>: module/class foo:bar::Baz
-
foo::bar::baz
: singleton methodbaz
fromfoo::bar
-
other: raise RiError
Instance Attribute Summary collapse
-
#class_names ⇒ Object
readonly
Returns the value of attribute class_names.
-
#is_class_method ⇒ Object
readonly
true and false have the obvious meaning.
-
#method_name ⇒ Object
readonly
Returns the value of attribute method_name.
Instance Method Summary collapse
-
#full_class_name ⇒ Object
Return the full class name (with ‘::’ between the components) or “” if there’s no class name.
-
#initialize(arg) ⇒ NameDescriptor
constructor
A new instance of NameDescriptor.
Constructor Details
permalink #initialize(arg) ⇒ NameDescriptor
Returns a new instance of NameDescriptor.
26 27 28 29 30 31 32 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 |
# File 'lib/fastri/name_descriptor.rb', line 26 def initialize(arg) @class_names = [] @method_name = nil @is_class_method = nil case arg when /((?:[^:]*::)*[^:]*)(#|::|\.)(.*)$/ ns, sep, meth_or_class = $~.captures # optimization attempt: try to guess the real capitalization, # so we get a direct hit @class_names = ns.split(/::/).map{|x| x[0,1] = x[0,1].upcase; x } if %w[# .].include? sep @method_name = meth_or_class @is_class_method = case sep when "#"; false when "."; nil end else if ("A".."Z").include? meth_or_class[0,1] # 1.9 compatibility @class_names << meth_or_class else @method_name = meth_or_class @is_class_method = true end end when /^[^#:.]+/ if ("A".."Z").include? arg[0,1] @class_names = [arg] else @method_name = arg.dup @is_class_method = nil end else raise RiError, "Cannot create NameDescriptor from #{arg}" end end |
Instance Attribute Details
permalink #class_names ⇒ Object (readonly)
Returns the value of attribute class_names.
20 21 22 |
# File 'lib/fastri/name_descriptor.rb', line 20 def class_names @class_names end |
permalink #is_class_method ⇒ Object (readonly)
true and false have the obvious meaning. nil means we don’t care
24 25 26 |
# File 'lib/fastri/name_descriptor.rb', line 24 def is_class_method @is_class_method end |
permalink #method_name ⇒ Object (readonly)
Returns the value of attribute method_name.
21 22 23 |
# File 'lib/fastri/name_descriptor.rb', line 21 def method_name @method_name end |
Instance Method Details
permalink #full_class_name ⇒ Object
Return the full class name (with ‘::’ between the components) or “” if there’s no class name
66 67 68 |
# File 'lib/fastri/name_descriptor.rb', line 66 def full_class_name @class_names.join("::") end |