I came across this little piece of code from Ruby on Rails. Can some one please take time in explaining this - all_account_id = Rails.configuration.lsr_api_account_id[:prod] account_id.split(",").map(&:strip)
Especially the last piece .split(",").map(&:strip)
CodePudding user response:
the code is simply concatenating 2 different strings.
if the string looks like this "ab, cd, ef"
then the split method will return an array and the elements in that array will be from the string separated by
a comma. e.g.
"a, b, c".split(",")
will return ["a", " b", " c"]
You can see further examples from https://apidock.com/ruby/String/split
.map is like a loop, it'll be run on each element of the array that's returned by split, there's a method inside map, that's strip, as name suggest it removes extra spaces (if any) from the string
e.g. if split return something like [" a ", "b ", " c"]
then map(&:strip)
will remove extra spaces from each element.
Note: Remeber, map and split are 2 different things, you can explore them using below links https://apidock.com/ruby/Enumerable/map https://apidock.com/ruby/String/strip