On Thu, Oct 7, 2010 at 7:05 PM, Atul D.
If “3. End span” is selected by in the UI, following error is
Error: #<NoMethodError: undefined method `to_i’ for ["3. End span
Posted via http://www.ruby-forum.com/.
I assume you are using Google sketchup, and you are invoking this method
http://code.google.com/apis/sketchup/docs/ourdoc/ui.html#inputbox If so,
can see they say that it returns nil or an Array, so @input_tslab would
an Array. Then, you call (@input_tslab).to_i, first of all, you do not
parentheses, they don’t do anything. Second, that means you are invoking
to_i method on the array that @input_tslab has received from the
method. But to_i is not a method that Arrays have (
You need to figure out explicitly what will be returned (ie what does
Array actually contain? I know nothing about sketchup, so can only guess
that it is the text contents of the inputbox – if it even has a
And then you need to figure out what you want to do with it. In this
it looks like you want to associate it with a number. Figure out how to
from what is returned to the desired number. In your particular example,
looks like saying @input_tslav.first.to_i will work, but this might be a
shaky solution, I’d expect if you get more familiar with the API this
be easier for you.
Also, make sure to handle the situation where the user cancels the box,
nil is returned.