Class: RBI::Parser::SigBuilder
- Extended by:
- T::Sig
- Defined in:
- lib/rbi/parser.rb
Instance Attribute Summary collapse
-
#current ⇒ Object
readonly
Returns the value of attribute current.
Instance Method Summary collapse
-
#initialize(content, file:) ⇒ SigBuilder
constructor
A new instance of SigBuilder.
- #visit_assoc_node(node) ⇒ Object
- #visit_call_node(node) ⇒ Object
Constructor Details
#initialize(content, file:) ⇒ SigBuilder
Returns a new instance of SigBuilder.
798 799 800 801 802 |
# File 'lib/rbi/parser.rb', line 798 def initialize(content, file:) super @current = T.let(Sig.new, Sig) end |
Instance Attribute Details
#current ⇒ Object (readonly)
Returns the value of attribute current.
795 796 797 |
# File 'lib/rbi/parser.rb', line 795 def current @current end |
Instance Method Details
#visit_assoc_node(node) ⇒ Object
850 851 852 853 854 855 |
# File 'lib/rbi/parser.rb', line 850 def visit_assoc_node(node) @current.params << SigParam.new( node_string!(node.key).delete_suffix(":"), node_string!(node.value), ) end |
#visit_call_node(node) ⇒ Object
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 |
# File 'lib/rbi/parser.rb', line 805 def visit_call_node(node) case node. when "sig" args = node.arguments if args.is_a?(Prism::ArgumentsNode) args.arguments.each do |arg| @current.is_final = node_string(arg) == ":final" end end when "abstract" @current.is_abstract = true when "checked" args = node.arguments if args.is_a?(Prism::ArgumentsNode) arg = node_string(args.arguments.first) @current.checked = arg&.delete_prefix(":")&.to_sym end when "override" @current.is_override = true when "overridable" @current.is_overridable = true when "params" visit(node.arguments) when "returns" args = node.arguments if args.is_a?(Prism::ArgumentsNode) first = args.arguments.first @current.return_type = node_string!(first) if first end when "type_parameters" args = node.arguments if args.is_a?(Prism::ArgumentsNode) args.arguments.each do |arg| @current.type_params << node_string!(arg).delete_prefix(":") end end when "void" @current.return_type = nil end visit(node.receiver) visit(node.block) end |