Module: ImproveYourCode::AST::SexpExtensions::SendNode
- Defined in:
- lib/improve_your_code/ast/sexp_extensions/send.rb
Overview
Utility methods for :send nodes.
Constant Summary collapse
- ATTR_DEFN_METHODS =
%i[attr_writer attr_accessor].freeze
Instance Method Summary collapse
- #args ⇒ Object
-
#attr_with_writable_flag? ⇒ Boolean
Handles the case where we create an attribute writer via: attr :foo, true.
- #attribute_writer? ⇒ Boolean
- #module_creation_call? ⇒ Boolean
- #module_creation_receiver? ⇒ Boolean
- #name ⇒ Object
- #object_creation_call? ⇒ Boolean
- #participants ⇒ Object
- #receiver ⇒ Object
Instance Method Details
#args ⇒ Object
18 19 20 |
# File 'lib/improve_your_code/ast/sexp_extensions/send.rb', line 18 def args children[2..-1] end |
#attr_with_writable_flag? ⇒ Boolean
Handles the case where we create an attribute writer via: attr :foo, true
46 47 48 |
# File 'lib/improve_your_code/ast/sexp_extensions/send.rb', line 46 def attr_with_writable_flag? name == :attr && args.any? && args.last.type == :true end |
#attribute_writer? ⇒ Boolean
39 40 41 42 |
# File 'lib/improve_your_code/ast/sexp_extensions/send.rb', line 39 def attribute_writer? ATTR_DEFN_METHODS.include?(name) || attr_with_writable_flag? end |
#module_creation_call? ⇒ Boolean
26 27 28 |
# File 'lib/improve_your_code/ast/sexp_extensions/send.rb', line 26 def module_creation_call? object_creation_call? && module_creation_receiver? end |
#module_creation_receiver? ⇒ Boolean
30 31 32 33 |
# File 'lib/improve_your_code/ast/sexp_extensions/send.rb', line 30 def module_creation_receiver? receiver&.type == :const && %i[Class Struct].include?(receiver.simple_name) end |
#name ⇒ Object
14 15 16 |
# File 'lib/improve_your_code/ast/sexp_extensions/send.rb', line 14 def name children[1] end |
#object_creation_call? ⇒ Boolean
35 36 37 |
# File 'lib/improve_your_code/ast/sexp_extensions/send.rb', line 35 def object_creation_call? name == :new end |
#participants ⇒ Object
22 23 24 |
# File 'lib/improve_your_code/ast/sexp_extensions/send.rb', line 22 def participants ([receiver] + args).compact end |
#receiver ⇒ Object
10 11 12 |
# File 'lib/improve_your_code/ast/sexp_extensions/send.rb', line 10 def receiver children.first end |