I am using ruby 1.8.6 and I have been having some problem using certain
methods and stuff. It seems that my ruby wont recognize until loops and
also the .collect method dosnt work.
Is this normal? If I try to write use a until loop in my code I get
error and if I try to use .collect nothing happens (but no error).
I am using ruby 1.8.6 and I have been having some problem using certain
methods and stuff. It seems that my ruby wont recognize until loops and
also the .collect method dosnt work.
Is this normal? If I try to write use a until loop in my code I get
error and if I try to use .collect nothing happens (but no error).
Please provide a short example of the code you are trying and the
incorrect output you are receiving.
I am using ruby 1.8.6 and I have been having some problem using
certain
methods and stuff. It seems that my ruby wont recognize until loops
and
also the .collect method dosnt work.
Is this normal? If I try to write use a until loop in my code I get
error and if I try to use .collect nothing happens (but no error).
Is what normal? We can’t help you if we can’t see what you’re trying
to do. “doesn’t work” is not descriptive.
I apologize. I actually managed to get the until loops working after
some reinstalling. However, the .collect method still dosnt work and I
really want to use it. The code looks like this:
array = [1,2,5,7]
array.collect do |x|
x = x*2
end
puts array.inspect
After I have run this code it still says the array is [1,2,5,7].
Invokes _block_ once for each element of _self_. Creates a new
array containing the values returned by the block. See also
+Enumerable#collect+.
a = [ "a", "b", "c", "d" ]
a.collect {|x| x + "!" } #=> ["a!", "b!", "c!", "d!"]
a #=> ["a", "b", "c", "d"]
Invokes _block_ once for each element of _self_. Creates a new
array containing the values returned by the block. See also
+Enumerable#collect+.
a = [ "a", "b", "c", "d" ]
a.collect {|x| x + "!" } #=> ["a!", "b!", "c!", "d!"]
a #=> ["a", "b", "c", "d"]
I am using ruby 1.8.6 and I have been having some problem using certain
methods and stuff. It seems that my ruby wont recognize until loops and
also the .collect method dosnt work.
Is this normal? If I try to write use a until loop in my code I get
error and if I try to use .collect nothing happens (but no error).
Please show a code example, the output you’re getting and the exact
Ruby version you’re using.
The behavior of the code you posted is entirely consistent with
the described behavior and the example in the docs which Ryan posted
(in the example the contents of a are the same before and after calling
collect on it). So if collect does not work for you, show an example in
which it doesn’t work (as opposed to one where it behaves exactly as
expected).
To summarize the important part of the docs: collect returns a new
array,
it does not change the array it is called on in any way.