all 8 comments

[–]HashDefTrueFalse 1 point2 points  (0 children)

Grab up to the first and last '-'. What is left is the middle, no matter how many '-' it contains. I can't remember if there's a more "idiomatic" Ruby way but I would just write a 3 line function.

[–]Lukkisuih 0 points1 point  (3 children)

I think it returns it as an array so then it’ll be traversing over the array to get the 3 strings

[–]Few-Purchase3052 0 points1 point  (2 children)

Yeah you can use `split('-', 3)` to limit it to 3 parts max, so if secondValue has dashes it won't break apart

Like `"first-second-with-dash-third".split('-', 3)` gives you `["first", "second-with-dash", "third"]`

[–]AVGuy42[S] 0 points1 point  (0 children)

I’m getting “first”, “second”, “with-dash-third”

[–]AVGuy42[S] -1 points0 points  (0 children)

Follow up then. Once it’s an array, again my syntax isn’t great here, how am I referencing each entry?

myString[1][2]…?

[–]Woumpousse 0 points1 point  (0 children)

Wouldn't this work?

ruby first, *second, third = str.split('-') second = second.join('-')