Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I pass an array of strings to a ruby method that wants the strings but not in an array?

I have an array of strings (actually file names), something like

filenames = ['file1.jpg', 'file2.jpg', 'file3.jpg']

The method I am calling expects something like

images = Magick::ImageList.new("image1.png", "image2.png", "image3.png")

but if I call as below, I am actually passing an array.

images = Magick::ImageList.new(filenames)

How do I unwrap the contents of the array?

like image 906
Simmo Avatar asked Nov 28 '25 18:11

Simmo


1 Answers

Do as below using splat opearator(*) :

 images = Magick::ImageList.new(*filenames)

As @Stefan mentioned the documentation link for the same Array to Arguments Conversion

like image 100
Arup Rakshit Avatar answered Nov 30 '25 11:11

Arup Rakshit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!