Skip to content

Instantly share code, notes, and snippets.

@diskshima
Created January 19, 2019 04:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diskshima/d0b2a54735b2924a9168195f658b3d09 to your computer and use it in GitHub Desktop.
Save diskshima/d0b2a54735b2924a9168195f658b3d09 to your computer and use it in GitHub Desktop.
Ruby version of an Index error case (https://ericlippert.com/2019/01/18/indexer-error-cases/)
# A Ruby implementation to confirm when assignments happen.
# Inspired by https://ericlippert.com/2019/01/18/indexer-error-cases/
# Prints
# A
# B
# C
# catch
def a
puts 'A'
[]
end
def b
puts 'B'
'aaaaa'
end
def c
puts 'C'
123
end
begin
a()[b()] = c
rescue
puts 'catch'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment