Class: Loom::MethodSignature
- Inherits:
-
Object
- Object
- Loom::MethodSignature
- Defined in:
- lib/loom/method_signature.rb
Overview
Used to analyze the arguments of a method.
Defined Under Namespace
Modules: ParamType Classes: MatchSpec
Instance Attribute Summary collapse
-
#block_args ⇒ Object
readonly
Returns the value of attribute block_args.
-
#key_args ⇒ Object
readonly
Returns the value of attribute key_args.
-
#keyreq_args ⇒ Object
readonly
Returns the value of attribute keyreq_args.
-
#keyrest_args ⇒ Object
readonly
Returns the value of attribute keyrest_args.
-
#opt_args ⇒ Object
readonly
Returns the value of attribute opt_args.
-
#req_args ⇒ Object
readonly
Returns the value of attribute req_args.
-
#rest_args ⇒ Object
readonly
Returns the value of attribute rest_args.
Instance Method Summary collapse
- #find_by_type(type) ⇒ Object
-
#initialize(proc_or_method) ⇒ MethodSignature
constructor
A new instance of MethodSignature.
-
#method_missing(name, *args) ⇒ Object
Defines has_xyz_args? methods for each ParamType.
Constructor Details
#initialize(proc_or_method) ⇒ MethodSignature
Returns a new instance of MethodSignature.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/loom/method_signature.rb', line 17 def initialize(proc_or_method) @parameter_list = proc_or_method.parameters @req_args = find_by_type ParamType::REQ @opt_args = find_by_type ParamType::OPT @rest_args = find_by_type ParamType::REST @keyreq_args = find_by_type ParamType::KEYREQ @key_args = find_by_type ParamType::KEY @keyrest_args = find_by_type ParamType::KEYREST @block_args = find_by_type ParamType::BLOCK end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
Defines has_xyz_args? methods for each ParamType.
36 37 38 39 40 41 42 43 44 |
# File 'lib/loom/method_signature.rb', line 36 def method_missing(name, *args) match_data = name.to_s.match /^has_([^?]+)_args\?$/ if match_data method = "%s_args" % [match_data[1]] !self.send(method.to_sym).empty? else super name, *args end end |
Instance Attribute Details
#block_args ⇒ Object (readonly)
Returns the value of attribute block_args.
28 29 30 |
# File 'lib/loom/method_signature.rb', line 28 def block_args @block_args end |
#key_args ⇒ Object (readonly)
Returns the value of attribute key_args.
28 29 30 |
# File 'lib/loom/method_signature.rb', line 28 def key_args @key_args end |
#keyreq_args ⇒ Object (readonly)
Returns the value of attribute keyreq_args.
28 29 30 |
# File 'lib/loom/method_signature.rb', line 28 def keyreq_args @keyreq_args end |
#keyrest_args ⇒ Object (readonly)
Returns the value of attribute keyrest_args.
28 29 30 |
# File 'lib/loom/method_signature.rb', line 28 def keyrest_args @keyrest_args end |
#opt_args ⇒ Object (readonly)
Returns the value of attribute opt_args.
28 29 30 |
# File 'lib/loom/method_signature.rb', line 28 def opt_args @opt_args end |
#req_args ⇒ Object (readonly)
Returns the value of attribute req_args.
28 29 30 |
# File 'lib/loom/method_signature.rb', line 28 def req_args @req_args end |
#rest_args ⇒ Object (readonly)
Returns the value of attribute rest_args.
28 29 30 |
# File 'lib/loom/method_signature.rb', line 28 def rest_args @rest_args end |
Instance Method Details
#find_by_type(type) ⇒ Object
31 32 33 |
# File 'lib/loom/method_signature.rb', line 31 def find_by_type(type) @parameter_list.find_all { |tuple| tuple.first == type } end |