1

i am trying to declare a dynamic array like below.

<% Product_in_Stock_array = [] %>

but it is not working giving syntax error.

2
  • 1
    What errors are you getting? Commented Aug 10, 2020 at 6:03
  • @SCM : What is a dynamic array? Your code simply produces a Ruby Array, constant which is the empty array. For experimenting with the syntax, don't do it in templates, but do it first inside irb. Constants are nor really constant in Ruby, but you get an error message if you try to reassign it. Commented Aug 10, 2020 at 8:24

1 Answer 1

2

You have to be a bit more specific.

The code you have is most likely an erb template file. This is actually a valid erb template

ERB.new('<% Product_in_Stock_array = [] %>').result

Your syntax error has to be somewhere else.

Additionally you most likely want to create a variable not a constant. In Ruby names starting with capital letter are constants (written in UpperCamelCase or UPPER_CASE most often), normal variables are written in camel_case.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.