N
N
NetSpy2014-01-08 18:05:10
ruby
NetSpy, 2014-01-08 18:05:10

How to terminate the execution of a method in Ruby?

def some_method
  if a == "1"
    puts "Нужно завершить метод"
    _код_завершения_
  else
    puts "Завершение не требуется. Можно продолжить выполнение"
  end
  ...some_code_here...
end

def another_method
  ...some_code_here...
end

How to make it so that when a == 1, the method completes execution and the interpreter moves on to the next methods?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
_
_ _, 2014-01-08
@NetSpy

Are you talking about return?

N
NetSpy, 2014-01-08
@NetSpy

Thought we could put ...some_code_here... in the else block.
Perhaps there are more beautiful options?

N
NetSpy, 2014-01-08
@NetSpy

Yes thank you!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question