The only thing that will happen in a different way is the raising of an exception. For example, suppose there is a problem in calling the config_exists? method config_exists? . If an exception occurs in the first example, your @config var will be set to {} . In the second example, if the same thing happens, your program will crash.
As a side note, there is no need for a return key. Actually this example should look as follows. This suggests that I understand the intention.
def config @config ||= begin if config_exists? some_value else {} end rescue {} end end
and
def config @config ||= method end def method if config_exists? some_value else {} end end
Both examples are exactly the same, unless the exception raised by @config will still be set to = some_value in the first example.
In addition, it should be noted that nothing will happen if @config already matters. The operators ||= are the same as:
@config = some_value if @config.nil?
Set only this value if it is currently zero.
Hope this is helpful and that I understand your question correctly.
source share