nil output

You can use to_s function to replace NIL to empty string. For example, you can put following code in your view. <%= obj.to_s %> If obj is NIL, it simply returns "" (empty string), and you can avoid runtime errors.

Cheers, Glenn

WKC CCC wrote:

How can I get this so that the ouput is displayed as: [["one","","three"], ["","five","six"]]

testarray.map{|q| q.to_s }

This might even work:

testarray.map(&:to_s)

testarray.inspect.gsub('nil', '""')

If you need each element of the original array to being on its own line, you'll have to roll your own. If you do that, then each element could be:   (element || "").inspect except that turns both nil and false to the "" string.

-Rob

Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com

Rob Biedenharn wrote:

testarray.inspect.gsub('nil', '""')

That idea is ... disturbing on many levels. To begin, what happens when one of the string elements is 'Manila'?

WKC CCC wrote:

In the case of 'manila' manila is still printed out or whatever string content the variable may hold

p 'manila'.gsub('nil', 'ni')

:wink:

Since it wasn't *my* problem, I tried not to go crazy looking for a solution.

-Rob

Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com