Skip to content

Instantly share code, notes, and snippets.

@jbranchaud
Created February 4, 2021 18:15
Show Gist options
  • Save jbranchaud/3f7d77a94a234b4107b30d5b22122244 to your computer and use it in GitHub Desktop.
Save jbranchaud/3f7d77a94a234b4107b30d5b22122244 to your computer and use it in GitHub Desktop.
Returning out of a Ruby begin block
class Thing
def initialize(value)
@value = value
end
def call(other_value)
@other_value = other_value
puts final_value
end
private
def final_value
@final_value ||=
begin
return if @other_value.nil? || @other_value == ""
if @value == @other_value
"SAME"
else
"DIFFERENT"
end
end
puts "Final Value set to #{@final_value}"
@final_value
end
end
puts "-- first --"
Thing.new("value").call("value")
puts "-- second --"
Thing.new("value").call("other value")
puts "-- third --"
Thing.new("value").call(nil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment