Class: Protocol::MethodParser
- Defined in:
- lib/protocol/method_parser/ruby_parser.rb
Overview
Parse protocol method definition to derive a Message specification.
Class Attribute Summary collapse
-
.__source_cache__ ⇒ Object
Returns the value of attribute source_cache.
Instance Attribute Summary collapse
-
#arg_kinds ⇒ Object
readonly
Returns the kinds of the arguments of the parsed method.
-
#args ⇒ Object
readonly
Returns the names of the arguments of the parsed method.
-
#arity ⇒ Object
readonly
Returns the arity of the parsed method.
Class Method Summary collapse
-
.flush_source_cache ⇒ Object
Flushes the source cache.
Instance Method Summary collapse
-
#arg(i) ⇒ Object
Returns the i-th argument (beginning with 0).
-
#arg_kind(i) ⇒ Object
Returns the i-th kind of an argument (beginning with 0).
-
#block_arg? ⇒ Boolean
Return true if a block argument was detected.
-
#complex? ⇒ Boolean
Return true if this protocol method is a complex method, which ought to be called for checking conformance to the protocol.
-
#initialize(modul, methodname, eigenclass = false) ⇒ MethodParser
constructor
Create a new MethodParser instance for method
methodnameof modulemodul.
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_kinds ⇒ Object (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 |
#args ⇒ Object (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 |
#arity ⇒ Object (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_cache ⇒ Object
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.
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.
49 50 51 |
# File 'lib/protocol/method_parser/ruby_parser.rb', line 49 def complex? @complex end |