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 9116923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:47:19+00:00 2026-06-17T04:47:19+00:00

I am getting confused with the Array methods below. Can anyone help me understand

  • 0

I am getting confused with the Array methods below. Can anyone help me understand how differently they work from each other with the help of simple snippet?

  • array.sort and array.sort { | a,b | block }
  • array.to_a and array.to_ary
  • array.size and array.length
  • array.reverse and array.reverse_each {|item| block }
  • array.fill(start [, length] ) { |index| block } and
    array.fill(range) { |index| block }
  • 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-06-17T04:47:20+00:00Added an answer on June 17, 2026 at 4:47 am

    Please read the documentation for Array.

    sort:

    a=[3,1,2]
    a.sort              # => [1, 2, 3] 
    a.sort{|a,b| b<=>a} # => [3, 2, 1] 
    

    use the second one if you need some custom way to sort elements.

    to_a vs. to_ary:

    class Foo < Array;end
    b=Foo[1,2]
    b.to_ary.class # returns self
    b.to_a.class   # converts to array
    

    size and length are exactly the same.

    reverse_each is pretty much the same as reverse.each.

    If you want to fill only a part of the array, you can call Array.fill either with a range or start,length. Those are just different ways to achieve the same:

    (["a"]*10).fill("b",2..7)
    (["a"]*10).fill("b",2,6)
    

    both return ["a", "a", "b", "b", "b", "b", "b", "b", "a", "a"].

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting confused with my C++ class structure below: A.h: class A{ }; A.cpp
I'm getting confused. I was able to make openid login kinda work using LightOpenID
I am really getting confused on how pointers work. I am trying to write
I'm getting confused with the various functions in Laravel's Eloquent ORM and what they
I'm getting confused working with character string arrays. I'm trying to fill 2 arrays
I am getting confused with the scenario of 2 classes implementing the same interface
I'm getting confused by bank switching in PIC assembler... This works for putting a
I'm getting confused re the range of options for development & deploying some simple
I am getting confused between TCP being Connection oriented and UDP being connectionless so
I'm getting confused in the doco how I should be setting up Ninject. I'm

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.