Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7004715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:14:04+00:00 2026-05-27T21:14:04+00:00

I am starting to learn ruby and am trying to figure out a way

  • 0

I am starting to learn ruby and am trying to figure out a way to if i have an array of 16 numbers, to print those numbers 4 at a time using only the each method. I can easily do this with a loop but i am lacking full understanding of the each method in Ruby so this gives me some trouble.

I have the following:

x=[*1..16]
index=0
x.each do |element|
  puts element[index]
  index=index+3
end

Now obviously this is completely wrong and i know that but i wanted to put something on here. A little advice would be great.

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:14:05+00:00Added an answer on May 27, 2026 at 9:14 pm

    A possible solution:

    a = (1..16)
    a.each_slice(4) { |s| p s[3] }
    

    EDIT: If you want print 4 elements on one line, then skip to the next line and print the next 4 elements, etc

    a = (1..16)
    a.each_slice(4) { |s| puts s.join(' ') }
    

    Or using each only

    a = (1..16)
    a.each { |i| print i.to_s + ' '; print "\n" if i % 4 == 0 }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just starting to learn Ruby on Rails. I'm using RoR 3. I have read
I'm starting to learn sockets, and I'm trying to figure out why you need
I'm starting to learn Python and I've come across generator functions, those that have
I'm just starting to learn Ruby and have a problem with encoding; require 'rubygems'
I am just starting to learn Ruby on Rails and have a newbie question
I'm starting right from the beginning with Ruby to learn the ropes but have
i'm starting to learn ruby on rails using this guide : getting_started , i
Just starting to learn scala.. I can't seem to figure out how to compile
Just starting to learn ASP.NET (C#) and I am using Visual Studio 2008. I
I am just starting to learn javascript, so I don't have the skills to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.