Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why does array "each" do not work anymore in Crystal 1.3.0? What should I use instead?

The code below does not print the elements of the array. Why is that?

array = [1, 2, 3]

array.each do |x|
  puts x
end

array.each { |x| puts x }

Crystal Play Output

It used to work in previous versions. I know Crystal is not Ruby, but the code above works in Ruby. What is the best practice to iterate through an array in Crystal? And why did the Crystal developers decide to make Crystal incompatible with Ruby in such a basic scenario?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Short answer: click "SHOW OUTPUT" below right-hand side box.

There is an apparent difference between the local version of Crystal Playground you get from running crystal play and the one running at play.crystal-lang.org. The code works, but the presentation of the results is different.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading