0

unable to store data contain in abc. it's showing an error

instance variable @ar of CategoryController must be (Array(Array(Array(Int64 | String) | Array(String))) | Nil), not Array(Array(Int64 | String) | Array(String)))

code sample:

 abc = [["", "Select"], [6_i64, "some"]]

 puts abc.class # => Array(Array(Int64 | String) | Array(String))

 @ar = [] of Array(Array(Int64 | String) | Array(String))

 @ar = abc # showing error
Johannes Müller
  • 5,581
  • 1
  • 11
  • 25
  • I'm pretty sure the error message is already in line for where you assign `@ar` the first time because the literal value has the same type as `abc`. However, the error message clearly states that the (expected) type of the instance variable and the actual type you try to assign, don't match. The assigned value is the item type of the array and can be *added* to the array `@ar`, but not assigned to a variable holding such an array type. – Johannes Müller May 03 '19 at 12:20

1 Answers1

0

The code is working here, going to need more context to find out the error. And also, comments should be done with # Comment here.

A guess would be that @ar in CategoryController is defined incorrectly.

Samual
  • 188
  • 1
  • 7
  • Exactly I tried the same using different pattern but it won't work with instance array variable. – tester test May 03 '19 at 13:18
  • To try and solve this, show the `CategoryController` class code – Samual May 03 '19 at 17:42
  • `code CategoryController < ApplicationController getter category = Category.new def new abc = [["", "Select"], [6_i64, "parent"]] puts "-------------------------------->" puts abc puts abc.class @ar = [] of Array(Array(Int64 | String) | Array(String)) @ar = abc render "new.slang" end end ` – tester test May 04 '19 at 04:52