Class: RubyLint::Definition::RubyMethod
- Inherits:
-
RubyObject
- Object
- RubyObject
- RubyLint::Definition::RubyMethod
- Defined in:
- lib/ruby-lint/definition/ruby_method.rb
Overview
The RubyMethod definition class is a definition class used for storing information about Ruby methods (both class and instance methods).
Constant Summary
Constants inherited from RubyObject
RubyLint::Definition::RubyObject::LOOKUP_PARENT, RubyLint::Definition::RubyObject::PATH_SEPARATOR, RubyLint::Definition::RubyObject::VALID_TYPES
Constants included from VariablePredicates
VariablePredicates::PREDICATE_METHODS, VariablePredicates::RUBY_CLASSES, VariablePredicates::VARIABLE_TYPES
Instance Attribute Summary collapse
-
#callers ⇒ Array<RubyLint::MethodCallInfo>
readonly
The methods that called this method.
-
#calls ⇒ Array<RubyLint::MethodCallInfo>
readonly
The method calls made in the body of this method.
-
#return_value ⇒ Mixed
readonly
The value that is returned by the method.
-
#visibility ⇒ Symbol
readonly
The method visibility such as
:public.
Attributes inherited from RubyObject
#column, #definitions, #file, #inherit_self, #instance_type, #line, #members_as_value, #name, #parents, #reference_amount, #type, #update_parents, #value
Instance Method Summary collapse
-
#after_initialize ⇒ Object
Called after a new instance of this class is created.
- #arguments ⇒ Array
- #block_argument ⇒ RubyLint::Definition::RubyObject
-
#create_argument(type, name) ⇒ RubyLint::Definition::RubyObject
private
Adds a new argument to the method as well as adding it as a local variable.
-
#define_argument(name) ⇒ Object
Defines a required argument for the method.
-
#define_block_argument(name) ⇒ Object
Defines a block argument for the method.
-
#define_keyword_argument(name) ⇒ Object
Defines a keyword argument for the method.
-
#define_optional_argument(name) ⇒ Object
Defines a optional argument for the method.
-
#define_rest_argument(name) ⇒ Object
Defines a rest argument for the method.
- #keyword_arguments ⇒ Array
- #optional_arguments ⇒ Array
- #rest_argument ⇒ RubyLint::Definition::RubyObject
-
#returns(value = nil, &block) ⇒ Object
Sets the return value of this method.
Methods inherited from RubyObject
#add, #add_child_definition, #add_child_method, #add_definition, #amount, #call, #call_method, #class?, #constant_proxy, #copy, create_unknown, #define_constant, #define_constructors, #define_global_variable, #define_instance_method, #define_method, #define_self, #defines?, #determine_parent, #has_definition?, #inherits, #initialize, #inspect, #instance, #instance!, #instance?, #list, #lookup, #lookup_constant_path, #lookup_parent?, #merge, #method_call_type, #method_defined?, #prepare_lookup, #shim, #top_scope, #update_parent_definitions, #used?
Methods included from VariablePredicates
#constant?, #constant_path?, #ruby_class, #variable?
Constructor Details
This class inherits a constructor from RubyLint::Definition::RubyObject
Instance Attribute Details
#callers ⇒ Array<RubyLint::MethodCallInfo> (readonly)
Returns The methods that called this method.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/ruby-lint/definition/ruby_method.rb', line 23 class RubyMethod < RubyObject attr_reader :calls, :callers, :return_value, :visibility ## # Called after a new instance of this class is created. # def after_initialize @calls = [] @callers = [] end ## # @return [Array] # def arguments return list(:arg) end ## # @return [RubyLint::Definition::RubyObject] # def block_argument return list(:blockarg).first end ## # @return [Array] # def keyword_arguments return list(:kwoptarg) end ## # @return [Array] # def optional_arguments return list(:optarg) end ## # @return [RubyLint::Definition::RubyObject] # def rest_argument return list(:restarg).first end ## # Sets the return value of this method. If a block is given it will be # used as the return value. The block is *not* evaluated until it's # called. # # @example # string.define_instance_method(:gsub) do |method| # method.returns('...') # end # # @param [Mixed] value # def returns(value = nil, &block) @return_value = block_given? ? block : value end ## # Defines a required argument for the method. # # @example # method.define_argument('number') # # @param [String] name The name of the argument. # def define_argument(name) create_argument(:arg, name) end ## # Defines a keyword argument for the method. # # @see RubyLint::Definition::RubyObject#define_argument # def define_keyword_argument(name) create_argument(:kwoptarg, name) end ## # Defines a optional argument for the method. # # @see RubyLint::Definition::RubyObject#define_argument # def define_optional_argument(name) create_argument(:optarg, name) end ## # Defines a rest argument for the method. # # @see RubyLint::Definition::RubyObject#define_argument # def define_rest_argument(name) create_argument(:restarg, name) end ## # Defines a block argument for the method. # # @see RubyLint::Definition::RubyObject#define_argument # def define_block_argument(name) create_argument(:blockarg, name) end private ## # Adds a new argument to the method as well as adding it as a local # variable. Note that although the argument's variable is saved under a # argument key (e.g. `:arg`) the actual definition type is set to # `:lvar`. # # @param [Symbol] type The type of argument. # @param [String] name The name of the argument. # # @return [RubyLint::Definition::RubyObject] # def create_argument(type, name) argument = RubyObject.new(:type => :lvar, :name => name) add(argument.type, argument.name, argument) add(type, argument.name, argument) return argument end end |
#calls ⇒ Array<RubyLint::MethodCallInfo> (readonly)
Returns The method calls made in the body of this method.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/ruby-lint/definition/ruby_method.rb', line 23 class RubyMethod < RubyObject attr_reader :calls, :callers, :return_value, :visibility ## # Called after a new instance of this class is created. # def after_initialize @calls = [] @callers = [] end ## # @return [Array] # def arguments return list(:arg) end ## # @return [RubyLint::Definition::RubyObject] # def block_argument return list(:blockarg).first end ## # @return [Array] # def keyword_arguments return list(:kwoptarg) end ## # @return [Array] # def optional_arguments return list(:optarg) end ## # @return [RubyLint::Definition::RubyObject] # def rest_argument return list(:restarg).first end ## # Sets the return value of this method. If a block is given it will be # used as the return value. The block is *not* evaluated until it's # called. # # @example # string.define_instance_method(:gsub) do |method| # method.returns('...') # end # # @param [Mixed] value # def returns(value = nil, &block) @return_value = block_given? ? block : value end ## # Defines a required argument for the method. # # @example # method.define_argument('number') # # @param [String] name The name of the argument. # def define_argument(name) create_argument(:arg, name) end ## # Defines a keyword argument for the method. # # @see RubyLint::Definition::RubyObject#define_argument # def define_keyword_argument(name) create_argument(:kwoptarg, name) end ## # Defines a optional argument for the method. # # @see RubyLint::Definition::RubyObject#define_argument # def define_optional_argument(name) create_argument(:optarg, name) end ## # Defines a rest argument for the method. # # @see RubyLint::Definition::RubyObject#define_argument # def define_rest_argument(name) create_argument(:restarg, name) end ## # Defines a block argument for the method. # # @see RubyLint::Definition::RubyObject#define_argument # def define_block_argument(name) create_argument(:blockarg, name) end private ## # Adds a new argument to the method as well as adding it as a local # variable. Note that although the argument's variable is saved under a # argument key (e.g. `:arg`) the actual definition type is set to # `:lvar`. # # @param [Symbol] type The type of argument. # @param [String] name The name of the argument. # # @return [RubyLint::Definition::RubyObject] # def create_argument(type, name) argument = RubyObject.new(:type => :lvar, :name => name) add(argument.type, argument.name, argument) add(type, argument.name, argument) return argument end end |
#return_value ⇒ Mixed (readonly)
Returns The value that is returned by the method.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/ruby-lint/definition/ruby_method.rb', line 23 class RubyMethod < RubyObject attr_reader :calls, :callers, :return_value, :visibility ## # Called after a new instance of this class is created. # def after_initialize @calls = [] @callers = [] end ## # @return [Array] # def arguments return list(:arg) end ## # @return [RubyLint::Definition::RubyObject] # def block_argument return list(:blockarg).first end ## # @return [Array] # def keyword_arguments return list(:kwoptarg) end ## # @return [Array] # def optional_arguments return list(:optarg) end ## # @return [RubyLint::Definition::RubyObject] # def rest_argument return list(:restarg).first end ## # Sets the return value of this method. If a block is given it will be # used as the return value. The block is *not* evaluated until it's # called. # # @example # string.define_instance_method(:gsub) do |method| # method.returns('...') # end # # @param [Mixed] value # def returns(value = nil, &block) @return_value = block_given? ? block : value end ## # Defines a required argument for the method. # # @example # method.define_argument('number') # # @param [String] name The name of the argument. # def define_argument(name) create_argument(:arg, name) end ## # Defines a keyword argument for the method. # # @see RubyLint::Definition::RubyObject#define_argument # def define_keyword_argument(name) create_argument(:kwoptarg, name) end ## # Defines a optional argument for the method. # # @see RubyLint::Definition::RubyObject#define_argument # def define_optional_argument(name) create_argument(:optarg, name) end ## # Defines a rest argument for the method. # # @see RubyLint::Definition::RubyObject#define_argument # def define_rest_argument(name) create_argument(:restarg, name) end ## # Defines a block argument for the method. # # @see RubyLint::Definition::RubyObject#define_argument # def define_block_argument(name) create_argument(:blockarg, name) end private ## # Adds a new argument to the method as well as adding it as a local # variable. Note that although the argument's variable is saved under a # argument key (e.g. `:arg`) the actual definition type is set to # `:lvar`. # # @param [Symbol] type The type of argument. # @param [String] name The name of the argument. # # @return [RubyLint::Definition::RubyObject] # def create_argument(type, name) argument = RubyObject.new(:type => :lvar, :name => name) add(argument.type, argument.name, argument) add(type, argument.name, argument) return argument end end |
#visibility ⇒ Symbol (readonly)
Returns The method visibility such as :public.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/ruby-lint/definition/ruby_method.rb', line 23 class RubyMethod < RubyObject attr_reader :calls, :callers, :return_value, :visibility ## # Called after a new instance of this class is created. # def after_initialize @calls = [] @callers = [] end ## # @return [Array] # def arguments return list(:arg) end ## # @return [RubyLint::Definition::RubyObject] # def block_argument return list(:blockarg).first end ## # @return [Array] # def keyword_arguments return list(:kwoptarg) end ## # @return [Array] # def optional_arguments return list(:optarg) end ## # @return [RubyLint::Definition::RubyObject] # def rest_argument return list(:restarg).first end ## # Sets the return value of this method. If a block is given it will be # used as the return value. The block is *not* evaluated until it's # called. # # @example # string.define_instance_method(:gsub) do |method| # method.returns('...') # end # # @param [Mixed] value # def returns(value = nil, &block) @return_value = block_given? ? block : value end ## # Defines a required argument for the method. # # @example # method.define_argument('number') # # @param [String] name The name of the argument. # def define_argument(name) create_argument(:arg, name) end ## # Defines a keyword argument for the method. # # @see RubyLint::Definition::RubyObject#define_argument # def define_keyword_argument(name) create_argument(:kwoptarg, name) end ## # Defines a optional argument for the method. # # @see RubyLint::Definition::RubyObject#define_argument # def define_optional_argument(name) create_argument(:optarg, name) end ## # Defines a rest argument for the method. # # @see RubyLint::Definition::RubyObject#define_argument # def define_rest_argument(name) create_argument(:restarg, name) end ## # Defines a block argument for the method. # # @see RubyLint::Definition::RubyObject#define_argument # def define_block_argument(name) create_argument(:blockarg, name) end private ## # Adds a new argument to the method as well as adding it as a local # variable. Note that although the argument's variable is saved under a # argument key (e.g. `:arg`) the actual definition type is set to # `:lvar`. # # @param [Symbol] type The type of argument. # @param [String] name The name of the argument. # # @return [RubyLint::Definition::RubyObject] # def create_argument(type, name) argument = RubyObject.new(:type => :lvar, :name => name) add(argument.type, argument.name, argument) add(type, argument.name, argument) return argument end end |
Instance Method Details
#after_initialize ⇒ Object
Called after a new instance of this class is created.
29 30 31 32 |
# File 'lib/ruby-lint/definition/ruby_method.rb', line 29 def after_initialize @calls = [] @callers = [] end |
#arguments ⇒ Array
37 38 39 |
# File 'lib/ruby-lint/definition/ruby_method.rb', line 37 def arguments return list(:arg) end |
#block_argument ⇒ RubyLint::Definition::RubyObject
44 45 46 |
# File 'lib/ruby-lint/definition/ruby_method.rb', line 44 def block_argument return list(:blockarg).first end |
#create_argument(type, name) ⇒ RubyLint::Definition::RubyObject (private)
Adds a new argument to the method as well as adding it as a local
variable. Note that although the argument's variable is saved under a
argument key (e.g. :arg) the actual definition type is set to
:lvar.
146 147 148 149 150 151 152 153 |
# File 'lib/ruby-lint/definition/ruby_method.rb', line 146 def create_argument(type, name) argument = RubyObject.new(:type => :lvar, :name => name) add(argument.type, argument.name, argument) add(type, argument.name, argument) return argument end |
#define_argument(name) ⇒ Object
Defines a required argument for the method.
93 94 95 |
# File 'lib/ruby-lint/definition/ruby_method.rb', line 93 def define_argument(name) create_argument(:arg, name) end |
#define_block_argument(name) ⇒ Object
Defines a block argument for the method.
129 130 131 |
# File 'lib/ruby-lint/definition/ruby_method.rb', line 129 def define_block_argument(name) create_argument(:blockarg, name) end |
#define_keyword_argument(name) ⇒ Object
Defines a keyword argument for the method.
102 103 104 |
# File 'lib/ruby-lint/definition/ruby_method.rb', line 102 def define_keyword_argument(name) create_argument(:kwoptarg, name) end |
#define_optional_argument(name) ⇒ Object
Defines a optional argument for the method.
111 112 113 |
# File 'lib/ruby-lint/definition/ruby_method.rb', line 111 def define_optional_argument(name) create_argument(:optarg, name) end |
#define_rest_argument(name) ⇒ Object
Defines a rest argument for the method.
120 121 122 |
# File 'lib/ruby-lint/definition/ruby_method.rb', line 120 def define_rest_argument(name) create_argument(:restarg, name) end |
#keyword_arguments ⇒ Array
51 52 53 |
# File 'lib/ruby-lint/definition/ruby_method.rb', line 51 def keyword_arguments return list(:kwoptarg) end |
#optional_arguments ⇒ Array
58 59 60 |
# File 'lib/ruby-lint/definition/ruby_method.rb', line 58 def optional_arguments return list(:optarg) end |
#rest_argument ⇒ RubyLint::Definition::RubyObject
65 66 67 |
# File 'lib/ruby-lint/definition/ruby_method.rb', line 65 def rest_argument return list(:restarg).first end |
#returns(value = nil, &block) ⇒ Object
Sets the return value of this method. If a block is given it will be used as the return value. The block is not evaluated until it's called.
81 82 83 |
# File 'lib/ruby-lint/definition/ruby_method.rb', line 81 def returns(value = nil, &block) @return_value = block_given? ? block : value end |