Search code examples
rubyvoidreturn-type

Ruby alternative to void return type


My experience is in C-based languages (C, C++, Java, C#) where the return type of a function can be void, i.e no return. But in Ruby, it appears that every function returns something. I was wondering what to return in Ruby for a method that wouldn't return anything in Java or C++. My best guesses would be either nil or the object that contains the method (for chaining) or just ignore whatever happens to be at the end, but I can't seem to find any information on this.

What's an alternative to void in Ruby?


Solution

  • Put

    return nil
    

    in the last statement in method.

    Or simply

    nil