Class: BitClust::MethodSignature
- Includes:
- NameUtils
- Defined in:
- lib/bitclust/methodsignature.rb
Overview
Represents detailed signature of a method in a class/module. Includes parameters, block specification and return type.
Constant Summary collapse
- METHOD_SIGNATURE_RE =
/\A --- \s* (?: (?:#{CLASS_PATH_RE} #{TYPEMARK_RE})? (#{METHOD_NAME_RE}) | (#{GVAR_RE}) ) \s* # method name ($1) or gvar name ($2) (?: \( (.*?) \) \s* )? # parameters (optional); $3=parameter_list (?: (\{ .* \}) \s* )? # block (optional); $4=block (?: -> \s* (\S.*) \s* )? # type declaration (optional); $5=return_type \z/x
Constants included from NameUtils
NameUtils::CHAR_TO_MARK, NameUtils::CHAR_TO_NAME, NameUtils::CLASS_NAME_RE, NameUtils::CLASS_PATH_RE, NameUtils::CONST_PATH_RE, NameUtils::CONST_RE, NameUtils::GVAR_RE, NameUtils::LIBNAME_RE, NameUtils::MARK_TO_CHAR, NameUtils::MARK_TO_NAME, NameUtils::METHOD_NAME_RE, NameUtils::METHOD_SPEC_RE, NameUtils::MID, NameUtils::NAME_TO_CHAR, NameUtils::NAME_TO_MARK, NameUtils::TYPEMARK_RE
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #friendly_string ⇒ Object
-
#initialize(name, params, block, type) ⇒ MethodSignature
constructor
A new instance of MethodSignature.
- #inspect ⇒ Object
- #to_s ⇒ Object
Methods included from NameUtils
build_method_id, classid2name, classname2id, classname?, decodeid, decodename_fs, decodename_url, encodeid, encodename_fs, encodename_rdocurl, encodename_url, functionname?, gvarname?, html_filename, libid2name, libname2id, libname?, method_spec?, methodid2classid, methodid2libid, methodid2mname, methodid2specparts, methodid2specstring, methodid2typechar, methodid2typemark, methodid2typename, methodname?, split_method_id, split_method_spec, typechar2mark, typechar2name, typechar?, typemark2char, typemark2name, typemark?, typename2char, typename2mark, typename?
Constructor Details
#initialize(name, params, block, type) ⇒ MethodSignature
39 40 41 42 43 44 |
# File 'lib/bitclust/methodsignature.rb', line 39 def initialize(name, params, block, type) @name = name @params = params @block = block @type = type end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
48 49 50 |
# File 'lib/bitclust/methodsignature.rb', line 48 def block @block end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
46 47 48 |
# File 'lib/bitclust/methodsignature.rb', line 46 def name @name end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
47 48 49 |
# File 'lib/bitclust/methodsignature.rb', line 47 def params @params end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
49 50 51 |
# File 'lib/bitclust/methodsignature.rb', line 49 def type @type end |
Class Method Details
.parse(line) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/bitclust/methodsignature.rb', line 32 def MethodSignature.parse(line) m = METHOD_SIGNATURE_RE.match(line) or raise ParseError, %Q(unknown signature format: "#{line.strip}") method, gvar, params, block, type = m.captures new(method || gvar, params && params.strip, block && block.strip, type && type.strip) end |
Instance Method Details
#friendly_string ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/bitclust/methodsignature.rb', line 58 def friendly_string case @name when /\A\$/ # gvar @name + (@type ? " -> #{@type}" : "") when "+@", "-@", "~", "!", "!@" # unary operator "#{@name.sub(/@/, '')} self" + (@type ? " -> #{@type}" : "") when "[]" # aref "self[#{@params}]" + (@type ? " -> #{@type}" : "") when "[]=" # aset params = @params.split(',') val = params.pop "self[#{params.join(',').strip}] = #{val.strip}" when "`" # `command` "`#{@params}`" + (@type ? " -> #{@type}" : "") when /\A\W/ # binary operator "self #{@name} #{@params}" + (@type ? " -> #{@type}" : "") else to_s() end end |
#inspect ⇒ Object
79 80 81 |
# File 'lib/bitclust/methodsignature.rb', line 79 def inspect "\#<#{self.class} name=#{@name.inspect} params=#{@params.inspect} block=#{@block.inspect} type=#{@type.inspect}>" end |
#to_s ⇒ Object
51 52 53 54 55 56 |
# File 'lib/bitclust/methodsignature.rb', line 51 def to_s @name + (@params ? "(#{@params})" : "") + (@block ? " #{@block}" : "") + (@type ? " -> #{@type}" : "") end |