I really can’t understand how the below piece of code is working…
options.each { |p|
if p[0] == '-'[0]
break
end...
does it really check for this string? “-[0]”?? or am i missing something?
sorry for this dumb question, but my mind is blocked right now…
What
'-'[0]will give you in Ruby 1.8 or lower is 45, which is the ASCII value for the-character. So what this is doing is checking to see ifp[0]is equal to 45.In Ruby 1.9,
'-'[0]will give you'-', so it is recommended to useString#ordinstead if you want the ASCII value: