Skip to content

Instantly share code, notes, and snippets.

Created January 6, 2020 11:28
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save strickvl/4c79593f3fae9fcb59b955b7f2e2724d to your computer and use it in GitHub Desktop.
blogpost on new method I learned

Joining Integers, Making Strings

While working through a Ruby problem on Codewars, I discovered a way to combine an array of integers in order to work on it as a string. As an example, see the following code snippet:

[3,2,1].join # --> returns "321"

This was surprising to me. In order to get the same result, I had taken the long route:

str = ""
[3,2,1].each { |digit| string << digit.to_s }

With Ruby, as often is the case, there’s a lot concealed underneath the .join method, but it’s a nice little shortcut for sure. One to remember…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment