File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -547,11 +547,16 @@ def clean_param(param)
547547 def erase_return_types ( source )
548548 result = source . dup
549549
550- # Remove return type: ): Type or ): Type<Foo> etc.
550+ # Remove return type after parentheses : ): Type or ): Type<Foo> etc.
551551 result . gsub! ( /\) \s *:\s *[^\n ]+?(?=\s *$)/m ) do |_match |
552552 ")"
553553 end
554554
555+ # Remove return type for methods without parentheses: def method_name: Type
556+ result . gsub! ( /^(\s *#{ TRuby ::VISIBILITY_PATTERN } def\s +#{ TRuby ::METHOD_NAME_PATTERN } )\s *:\s *[^\n ]+?(?=\s *$)/m ) do |_match |
557+ ::Regexp . last_match ( 1 )
558+ end
559+
555560 result
556561 end
557562 end
Original file line number Diff line number Diff line change @@ -157,6 +157,15 @@ def greet(name: String): String
157157 expect ( result ) . to include ( "def hello()" )
158158 end
159159
160+ it "handles functions without parentheses and with return type" do
161+ source = "def hello: String\n 'hello'\n end"
162+ eraser = TRuby ::TypeErasure . new ( source )
163+
164+ result = eraser . erase
165+ expect ( result ) . to include ( "def hello" )
166+ expect ( result ) . not_to include ( ": String" )
167+ end
168+
160169 it "handles nested structures" do
161170 source = "class Greeter" + "\n " \
162171 "def greet(name: String): String" + "\n " \
You can’t perform that action at this time.
0 commit comments