The method map is like each, but returns a new array with the return values of each iteration step. In comparison, each normally has no return value but can at most change the state of the system (e.g. you can insert results into a previously defined list).
You should also have been able to achieve join with each and + (if you don’t know how you could try it as an exercise) and lookup Array#join in ruby documentation.
(OFF-TOPIC, re: MSP_Greg) "Please try and not use the :: notation ..."
This notation is from the style used when I learned Ruby (from a book I think Matz himself was involved with.)
And I prefer it, and will continue to use it.
It makes it obvious that the call is to a class or module method, whereas “dot notation” I use by convention to call an instance method.
(P.S. - I’ve 40y in engineering, 35y programming in 8+ coding languages, and 10y with Ruby. I’ve examined various recommended Ruby coding style guides. And use a hybrid of my own. I’m old enough, experienced enough, and well able to decide what kind of notation I will use.)
Not an issue (for me) as I do not use it.
It enforces bbatsov’s coding style guide, which I believe is stuffed full of arbitrarily chosen rules (many involving spacing and other trivial things) that are not accompanied with reasoning. Therefore they are bbatsov’s personal preferences and are meaningless to me.
Who died and made bbatsov “king of Ruby code” anway ?
I operate with a very terse (unwritten) style guide with rule number (1) being “make it readable and it’ll be maintainable”. Rule (2) is “no arbitrary nit-picky rules are needed.”
Not everyone attempts to write “pretty code”.
Some of the code in the Ruby Standard Library is formated quite ugly.
So? They need to learn some how, and sometime.
If it causes them to ask (which they’ve done here in the forums before,) or to go look up the scope operator in a book, so much the better. It is a learning opportunity.
I won’t argue the :: vs . notation question because I agree that is a matter of individual style. But I agree 100% that the :: notation for name scope is a basic part of Ruby syntax, so any “What?” reaction indicates the reader has not bothered to learn the fundamentals yet!
You may also use :: to designate a receiver, but this is rarely used due to the potential for confusion with :: for namespaces.
To which I retort, that there is no confusion as I follow Ruby convention that method names are lower case with underscore word separation, and namespaces are CamelCase.
If some reader is so untalented that they are so easily confused, then they should find something else to do than programming. And if they don’t “like” my code, then they may ignore it and me.
(3) You should have begun a new topic thread to discuss this, as you are hijacking this “Array” topic.
(4) Perhaps you forget how you treated ME in the following post:
Observers – why subclass? - #5 by MSP_Greg I do not forget. (I requested moderation on it then, but received no satisfaction from Admin.) So since then, as long as this remains posted, I will not and do not care for your opinions, Greg!