Defining methods inside methods
-
I've seen in a couple scripts now where methods have been def'd inside of another method def. It is allowable syntax in Ruby, but is this intentional? What advantages does this offer?
def a puts "a" def b puts "b" end end -
I dont think I have released any plugins that do that. But I have used it a few times to avoid copying a bunch of code into each case of a elaborate if or case statement.
I have also used it when debugging to override the behavior of a function like puts
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement