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

  • Home
  • SEARCH
  • 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 509313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:59:53+00:00 2026-05-13T06:59:53+00:00

Language: Ruby I have an array of Products. Each Product has an attribute called

  • 0

Language: Ruby

I have an array of Products. Each Product has an attribute called product_price_name.

[Product.product_price_name = “All Prices”, Product.product_price_name = “$1 to $100” ]

I want to sort this array so the first result is “All Prices” and then the next options will be price ranges such as $1- $100, $100- $200

  • 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-13T06:59:53+00:00Added an answer on May 13, 2026 at 6:59 am
    # some setup
    Product = Struct.new(:product_price_name)
    array = %w{$1-100 $200-1000 All_Prices $100-200}.collect{|each|Product.new(each)}
    
    # the actual code
    array = array.sort_by { |each| each.product_price_name }
    array.unshift array.pop
    array # => [#<struct Product product_price_name="All_Prices">, #<struct Product product_price_name="$1-100">, #<struct Product product_price_name="$100-200">, #<struct Product product_price_name="$200-1000">]
    

    Gosh, one should never submit code that had never run! Mea culpa.

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

Sidebar

Related Questions

I am working with Ruby scripting language. I have a snippet here. Just want
So all I simply want to do is make a Ruby program that reads
I have an array of two dimensional Arrays. I want to create a new
I have recently started learning Ruby, as my first programming language. I feel comfortable
In Ruby language, how can I get the number of lines in a string?
The language is Ruby, here is my irb session expr = /\Aselect from (\D+)(?:
as I am learning the Ruby language, I am getting closer to actual programming.
I'm porting some code from other language to Ruby, in my Class I need
As I am going through my journey by adopting the Ruby language, I spend
In this example from The Ruby Programming Language (p.270), I'm confused why the instance_eval

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.