Suppose we have n constants like:
FOO = 'foo' BAR = 'bar' ...
I need to check in the block if they exists and are non empty.
%w(FOO BAR FOOBAR).each {|i|
# this doesn't work
fail "#{i} is missing or empty" if (! defined?(i) || i.empty?)
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is the best way, in my opinion:
EDIT:
Things are a bit more complicated if you want to look up constants in a scope sensitive way (i.e not just top-level constants):