Skip to content

Instantly share code, notes, and snippets.

@lukeredpath
Created June 20, 2017 12:22
Show Gist options
  • Save lukeredpath/2ab6f3bd0fea9450bdad7a36369f020d to your computer and use it in GitHub Desktop.
Save lukeredpath/2ab6f3bd0fea9450bdad7a36369f020d to your computer and use it in GitHub Desktop.
Ruby interpolate array value
class Array
def interpolate(value)
map { |el| [el, value] }.flatten
end
end
[1, 3, 5, 6].interpolate(9) #=> [1, 9, 3, 9, 5, 9, 6, 9]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment