0

I'm using the dashing dashboard to display some data. Part of my code for one of the jobs uses the map! function in ruby:

vars = arr.map! { |element| element.gsub(/.{3}$/, '' )}

and when I try to run the dashboard using dashing start, I get the following error :

scheduler caught exception:
undefined method map! for #<Hash: 0x......>

If I run the code on its own as a ruby program, I get the correct result.

tyrell_c
  • 503
  • 3
  • 10
  • 24
  • It looks like you expect `arr` to be an Array, but when you receive that error `arr` is a Hash. Can you provide the code that defines `arr`? – Travis Hohl Oct 01 '14 at 20:19
  • arr = JSON.parse(response.body). when I print arr I see an array of strings. – tyrell_c Oct 02 '14 at 12:58

1 Answers1

0

The documentation for the JSON module indicates that the parse method will "...convert your string into a hash." See http://www.ruby-doc.org/stdlib-2.0.0/libdoc/json/rdoc/JSON.html#module-JSON-label-Parsing+JSON.

Try calling just map on your hash instead of calling map!:

vars = arr.map { |element| element.gsub(/.{3}$/, '' )}

The difference is that map will return a new array with the results of running your block once for every element in the Hash. Also, map is defined in the Enumerable module, which is included by Hash, but map! is not defined in Enumerable. See http://www.ruby-doc.org/core-2.0.0/Enumerable.html#method-i-map.

Travis Hohl
  • 2,176
  • 2
  • 14
  • 15