3

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?

1 Answer 1

6

Do as below using splat opearator(*) :

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

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

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

2 Comments

Here's a link to the documentation: Array to Arguments Conversion
@Stefan I have added it to my answer... Thanks for the suggestion for further improvement....

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.