Class: Protocol::MethodParser

Inherits:
Object
  • Object
show all
Defined in:
lib/protocol/method_parser/ruby_parser.rb

Overview

Parse protocol method definition to derive a Message specification.

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(modul, methodname, eigenclass = false) ⇒ MethodParser

Create a new MethodParser instance for method methodname of module modul. For eigenmethods set eigenclass to true, otherwise bad things will happen.



20
21
22
23
24
25
26
# File 'lib/protocol/method_parser/ruby_parser.rb', line 20

def initialize(modul, methodname, eigenclass = false)
  @method = Module === modul ?
    modul.instance_method(methodname) :
    modul.method(methodname)
  compute_args
  parse_method
end

Class Attribute Details

.__source_cache__Object

Returns the value of attribute source_cache.



7
8
9
# File 'lib/protocol/method_parser/ruby_parser.rb', line 7

def __source_cache__
  @__source_cache__
end

Instance Attribute Details

#arg_kindsObject (readonly)

Returns the kinds of the arguments of the parsed method.



37
38
39
# File 'lib/protocol/method_parser/ruby_parser.rb', line 37

def arg_kinds
  @arg_kinds
end

#argsObject (readonly)

Returns the names of the arguments of the parsed method.



29
30
31
# File 'lib/protocol/method_parser/ruby_parser.rb', line 29

def args
  @args
end

#arityObject (readonly)

Returns the arity of the parsed method.



45
46
47
# File 'lib/protocol/method_parser/ruby_parser.rb', line 45

def arity
  @arity
end

Class Method Details

.flush_source_cacheObject

Flushes the source cache.



10
11
12
13
# File 'lib/protocol/method_parser/ruby_parser.rb', line 10

def flush_source_cache
  __source_cache__.clear
  self
end

Instance Method Details

#arg(i) ⇒ Object

Returns the i-th argument (beginning with 0).



32
33
34
# File 'lib/protocol/method_parser/ruby_parser.rb', line 32

def arg(i)
  @args[i]
end

#arg_kind(i) ⇒ Object

Returns the i-th kind of an argument (beginning with 0).



40
41
42
# File 'lib/protocol/method_parser/ruby_parser.rb', line 40

def arg_kind(i)
  @arg_kinds[i]
end

#block_arg?Boolean

Return true if a block argument was detected.

Returns:

  • (Boolean)


54
55
56
# File 'lib/protocol/method_parser/ruby_parser.rb', line 54

def block_arg?
  @arg_kinds.last == :block
end

#complex?Boolean

Return true if this protocol method is a complex method, which ought to be called for checking conformance to the protocol.

Returns:

  • (Boolean)


49
50
51
# File 'lib/protocol/method_parser/ruby_parser.rb', line 49

def complex?
  @complex
end