Is there any function for get an array value from string in ruby except eval?

Is there any function for get an array value from string in ruby except eval?

I have a string. It will be "1" or "['1','2','3','4']". By using eval method i can get the result 1 or [1,2,3,4] but i need the result should be array [1] or [1,2,3,4].

I have a string. It will be "1" or "['1','2','3','4']". By using eval method i can get the result 1 or [1,2,3,4] but i need the result should be array [1] or [1,2,3,4].

params[:city_id] = eval(params[:city_id]) #params will be "1" or "['1','2','3']"

scope :city, -> (params) { params[:city_id].present? ? where(city_id: (params[:city_id].is_a?(String) ? eval(params[:city_id]) : params[:city_id])) : all }

Here i don't want eval.

scope :city, -> (params) { params[:city_id].present? ? where(city_id: params[:city_id]) : all }

params[:city_id] #should be array values e.g [1] or [1,2,3,4] instead of string


Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Ruby on Rails vs PHP

Understanding the pros and cons of Ruby on Rails versus PHP is important when deciding how to create your business-critical applications.