Skip to content

Commit

Permalink
[ruby/prism] Implement singleton methods for ripper translation
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton authored and matzbot committed Mar 6, 2024
1 parent 3a7beff commit db53705
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
14 changes: 13 additions & 1 deletion lib/prism/translation/ripper.rb
Expand Up @@ -1044,6 +1044,13 @@ def visit_constant_path_target_node(node)
# def self.foo; end
# ^^^^^^^^^^^^^^^^^
def visit_def_node(node)
receiver = visit(node.receiver)
operator =
if !node.operator_loc.nil?
bounds(node.operator_loc)
visit_token(node.operator)
end

bounds(node.name_loc)
name = visit_token(node.name_loc.slice)

Expand All @@ -1070,7 +1077,12 @@ def visit_def_node(node)
on_bodystmt(body, nil, nil, nil)
end

on_def(name, parameters, bodystmt)
bounds(node.location)
if receiver.nil?
on_def(name, parameters, bodystmt)
else
on_defs(receiver, operator, name, parameters, bodystmt)
end
end

# defined? a
Expand Down
15 changes: 0 additions & 15 deletions test/prism/ripper_test.rb
Expand Up @@ -30,7 +30,6 @@ class RipperTest < TestCase
heredocs_nested.txt
heredocs_with_ignored_newlines.txt
if.txt
keyword_method_names.txt
lambda.txt
method_calls.txt
methods.txt
Expand Down Expand Up @@ -93,13 +92,6 @@ class RipperTest < TestCase
seattlerb/defn_kwarg_lvar.txt
seattlerb/defn_oneliner_eq2.txt
seattlerb/defn_oneliner_rescue.txt
seattlerb/defns_reserved.txt
seattlerb/defs_as_arg_with_do_block_inside.txt
seattlerb/defs_comments.txt
seattlerb/defs_endless_command.txt
seattlerb/defs_endless_command_rescue.txt
seattlerb/defs_kwarg.txt
seattlerb/defs_oneliner.txt
seattlerb/defs_oneliner_eq2.txt
seattlerb/defs_oneliner_rescue.txt
seattlerb/difficult2_.txt
Expand Down Expand Up @@ -241,7 +233,6 @@ class RipperTest < TestCase
unparser/corpus/literal/control.txt
unparser/corpus/literal/def.txt
unparser/corpus/literal/defined.txt
unparser/corpus/literal/defs.txt
unparser/corpus/literal/dstr.txt
unparser/corpus/literal/empty.txt
unparser/corpus/literal/for.txt
Expand Down Expand Up @@ -303,12 +294,7 @@ class RipperTest < TestCase
whitequark/dedenting_interpolating_heredoc_fake_line_continuation.txt
whitequark/dedenting_non_interpolating_heredoc_line_continuation.txt
whitequark/def.txt
whitequark/defs.txt
whitequark/empty_stmt.txt
whitequark/endless_method.txt
whitequark/endless_method_command_syntax.txt
whitequark/endless_method_with_rescue_mod.txt
whitequark/endless_method_without_args.txt
whitequark/forward_arg.txt
whitequark/forward_args_legacy.txt
whitequark/forwarded_argument_with_kwrestarg.txt
Expand All @@ -329,7 +315,6 @@ class RipperTest < TestCase
whitequark/masgn_attr.txt
whitequark/masgn_nested.txt
whitequark/masgn_splat.txt
whitequark/method_definition_in_while_cond.txt
whitequark/newline_in_hash_argument.txt
whitequark/next_block.txt
whitequark/numbered_args_after_27.txt
Expand Down

0 comments on commit db53705

Please sign in to comment.