Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Inconsistent reporting when accessing something that doesn't exist
irb(main):017:0> val = RBENV_VERSI0N
NameError: uninitialized constant RBENV_VERSI0N
from (irb):17
from /Users/gerardcaulfield/.rbenv/versions/2.1.2/bin/irb:11:in `<main>' # Fair enough
irb(main):018:0> val = rbenv_versi0n
NameError: undefined local variable or method `rbenv_versi0n' for main:Object
from (irb):18
from /Users/gerardcaulfield/.rbenv/versions/2.1.2/bin/irb:11:in `<main>' # Oh right
irb(main):019:0> val = Class.rbenv_versi0n
NoMethodError: undefined method `rbenv_versi0n' for Class:Class
from (irb):19
from /Users/gerardcaulfield/.rbenv/versions/2.1.2/bin/irb:11:in `<main>' # My bad
irb(main):020:0> val = ENV['RBENV_VERSI0N']
=> nil # Oh!? Wha???
irb(main):039:0> val = ENV['RBENV_VERSION'] ? ENV['RBENV_VERSI0N'] : raise('the key does not exist')
=> nil # Splitting the check from the access does not prevent this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment