Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
Calls the block passed to the method
def some_method(&block)
yield
end
some_method { puts 'hello from Proc'}
# Напечатает hello from Proc
def some_method(agrument,&block)
yield (agrument)
end
some_method('ITS ARGUMENT') {|argument| puts "hello from Proc with #{argument}"}
# Напечатает hello from Proc with ITS ARGUMENT
Are you talking about the "yield" keyword? Read about generators .
On the fingers - By calling yield in the body of a method, we mean the following: transfer control to the block, and when it finishes, return control to this method .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question