I am working with the “any?” method in a block. The snippet is looking for the string “CA” in the string (split) check:
region="CA"
check="AU,US,UK,CA,ZA"
if check.split(',').any? { |r| region[r] }
puts "This is true!"
end
I know how the “any?” command works what i don’t get is why region[r] resolves to true when the r value is “CA” – so we have region[“CA”] giving us true!
I can see that “CA”[“CA”] is true but why? There is a little knowledge I am missing here.
From String methods [] and slice,
http://www.ruby-doc.org/core-1.9.2/String.html#method-i-5B-5D