Class: Literal::Method
- Inherits:
-
Object
- Object
- Literal::Method
- Defined in:
- lib/literal/method.rb
Overview
@api private
Instance Attribute Summary collapse
-
#keyrest ⇒ Object
(also: #keyrest?)
readonly
Returns the value of attribute keyrest.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#number_of_optional_keyword_parameters ⇒ Object
readonly
Returns the value of attribute number_of_optional_keyword_parameters.
-
#number_of_optional_positional_parameters ⇒ Object
readonly
Returns the value of attribute number_of_optional_positional_parameters.
-
#number_of_required_keyword_parameters ⇒ Object
readonly
Returns the value of attribute number_of_required_keyword_parameters.
-
#number_of_required_positional_parameters ⇒ Object
readonly
Returns the value of attribute number_of_required_positional_parameters.
-
#object_class ⇒ Object
readonly
Returns the value of attribute object_class.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
-
#rest ⇒ Object
(also: #rest?)
readonly
Returns the value of attribute rest.
-
#visibility ⇒ Object
readonly
Returns the value of attribute visibility.
Instance Method Summary collapse
- #<(other) ⇒ Object
- #==(other) ⇒ Object
-
#initialize(name, object_class) ⇒ Method
constructor
A new instance of Method.
- #keyword_parameters_match?(other) ⇒ Boolean private
- #number_of_keyword_parameters ⇒ Object
- #number_of_positional_parameters ⇒ Object
- #positional_parameters_match?(other) ⇒ Boolean private
- #visibility_match?(other) ⇒ Boolean private
Constructor Details
#initialize(name, object_class) ⇒ Method
Returns a new instance of Method.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/literal/method.rb', line 5 def initialize(name, object_class) @name = name @object_class = object_class @method = @object_class.instance_method(@name) @parameters = @method.parameters.map(&:first) @rest = @parameters.include?(:rest) @keyrest = @parameters.include?(:keyrest) @number_of_required_positional_parameters = @parameters.count(:req) @number_of_optional_positional_parameters = @parameters.count(:opt) @number_of_required_keyword_parameters = @parameters.count(:keyreq) @number_of_optional_keyword_parameters = @parameters.count(:key) @visibility = if @object_class.public_instance_methods.include?(name) :public elsif @object_class.protected_instance_methods.include?(name) :protected else :private end end |
Instance Attribute Details
#keyrest ⇒ Object (readonly) Also known as: keyrest?
Returns the value of attribute keyrest.
30 31 32 |
# File 'lib/literal/method.rb', line 30 def keyrest @keyrest end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
30 31 32 |
# File 'lib/literal/method.rb', line 30 def method @method end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
30 31 32 |
# File 'lib/literal/method.rb', line 30 def name @name end |
#number_of_optional_keyword_parameters ⇒ Object (readonly)
Returns the value of attribute number_of_optional_keyword_parameters.
30 31 32 |
# File 'lib/literal/method.rb', line 30 def number_of_optional_keyword_parameters @number_of_optional_keyword_parameters end |
#number_of_optional_positional_parameters ⇒ Object (readonly)
Returns the value of attribute number_of_optional_positional_parameters.
30 31 32 |
# File 'lib/literal/method.rb', line 30 def number_of_optional_positional_parameters @number_of_optional_positional_parameters end |
#number_of_required_keyword_parameters ⇒ Object (readonly)
Returns the value of attribute number_of_required_keyword_parameters.
30 31 32 |
# File 'lib/literal/method.rb', line 30 def number_of_required_keyword_parameters @number_of_required_keyword_parameters end |
#number_of_required_positional_parameters ⇒ Object (readonly)
Returns the value of attribute number_of_required_positional_parameters.
30 31 32 |
# File 'lib/literal/method.rb', line 30 def number_of_required_positional_parameters @number_of_required_positional_parameters end |
#object_class ⇒ Object (readonly)
Returns the value of attribute object_class.
30 31 32 |
# File 'lib/literal/method.rb', line 30 def object_class @object_class end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
30 31 32 |
# File 'lib/literal/method.rb', line 30 def parameters @parameters end |
#rest ⇒ Object (readonly) Also known as: rest?
Returns the value of attribute rest.
30 31 32 |
# File 'lib/literal/method.rb', line 30 def rest @rest end |
#visibility ⇒ Object (readonly)
Returns the value of attribute visibility.
30 31 32 |
# File 'lib/literal/method.rb', line 30 def visibility @visibility end |
Instance Method Details
#<(other) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/literal/method.rb', line 49 def <(other) self != other && positional_parameters_match?(other) && keyword_parameters_match?(other) && visibility_match?(other) end |
#==(other) ⇒ Object
45 46 47 |
# File 'lib/literal/method.rb', line 45 def ==(other) @method == other.method end |
#keyword_parameters_match?(other) ⇒ Boolean (private)
74 75 76 77 78 79 80 |
# File 'lib/literal/method.rb', line 74 def keyword_parameters_match?(other) number_of_required_keyword_parameters <= other.number_of_required_keyword_parameters && ( keyrest? || (!other.keyrest? && ( number_of_keyword_parameters >= other.number_of_keyword_parameters )) ) end |
#number_of_keyword_parameters ⇒ Object
60 61 62 |
# File 'lib/literal/method.rb', line 60 def number_of_keyword_parameters @number_of_required_keyword_parameters + @number_of_optional_keyword_parameters end |
#number_of_positional_parameters ⇒ Object
56 57 58 |
# File 'lib/literal/method.rb', line 56 def number_of_positional_parameters @number_of_required_positional_parameters + @number_of_optional_positional_parameters end |
#positional_parameters_match?(other) ⇒ Boolean (private)
66 67 68 69 70 71 72 |
# File 'lib/literal/method.rb', line 66 def positional_parameters_match?(other) number_of_required_positional_parameters <= other.number_of_required_positional_parameters && ( rest? || (!other.rest? && ( number_of_positional_parameters >= other.number_of_positional_parameters )) ) end |
#visibility_match?(other) ⇒ Boolean (private)
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/literal/method.rb', line 82 def visibility_match?(other) case other.visibility when :public visibility == :public when :protected visibility == :public || visibility == :protected else true end end |