Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruby return is implicit #131

Open
theoo opened this issue Feb 27, 2023 · 2 comments
Open

Ruby return is implicit #131

theoo opened this issue Feb 27, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@theoo
Copy link

theoo commented Feb 27, 2023

Using YARD for a ruby project, I realized that the "@return" will be documented only when an explicit return is provided in the commented function. Ruby has implicit return and I'm wondering if it wouldn't make sense to always add it in the generated snippet.

Something like:

# @return [TODO:nil]

But for this to work with ruby, it seems that Neogen should always "call" return_statement in the template instead of only when the function has an explicit return.

@danymat
Copy link
Owner

danymat commented May 22, 2023

Hello, so you are telling me that YARD should provide by default implicit returns ?
If so (I still need a source for this claim), I can make this work 😃

@danymat danymat added enhancement New feature or request under review Waiting for review by users or developer. question Further information is requested and removed under review Waiting for review by users or developer. labels May 22, 2023
@theoo
Copy link
Author

theoo commented May 22, 2023

I still need a source for this claim

Hi danymat,

sure thing. A quick ruby implicit return search yields the following sources:

The following code will print "Implicit return has its good sides".

#
# Example method to demonstrate implicit return
#
# @param whatever [String] text to append
#
# @return [String] text
#
def example(whatever)
  "Implicit return #{whatever}"
end

puts example("has its good sides")

Not that the following with return something as well. There is no such thing like "no returned value" with ruby.

#
# Another example method to demonstrate implicit return
#
# @return [NilClass] nil
#
def mute
 puts "The silence is gold."
 nil
end

puts mute.inspect

... will output:

The silence is gold.
nil

However explicit returns have their use, like in most language:

#
# Example method to demonstrate explicit return
#
# @param number [Integer] to test
#
# @return [String,Integer] "hit" if multiple of 10 otherwise the original _number_ value
#
def test(number)
  return "hit" if number % 10
  # do stuff
  number
end

puts test(1)
# 1
puts test(20)
# hit

I'm not sure that I wrote the best examples, but conventinal cases are illustrated that way. So in a nutshell, yes, ruby methods always return something.

@danymat danymat removed the question Further information is requested label May 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants