You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

deep_sort

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deep_sort

0.1.6
bundlerRubygems
Version published
Maintainers
1
Created
Source

deep_sort

Sort Array/Hash/Enumerable recursively.

Gem Version Build Status

Installation

Add this line to your application's Gemfile:

gem 'deep_sort'

And then execute:

$ bundle

Or install it yourself as:

$ gem install deep_sort

Methods

  • DeepSort.deep_sort(obj, options = {})
  • require 'deep_sort/extend'
    • Array#deep_sort(options = {})
    • Array#deep_sort!(options = {})
    • Hash#deep_sort(options = {})
    • Hash#deep_sort!(options = {})
    • Enumerable#deep_sort()

Usage

require 'deep_sort'
require 'pp'
require 'set'

hash = {"firstName"=>"John",
        "lastName"=>"Smith",
        "age"=>25,
        "address"=>
         {"streetAddress"=>"21 2nd Street",
          "city"=>"New York",
          "state"=>"NY",
          "postalCode"=>"10021"},
        "phoneNumber"=>
         [{"type"=>"home", "number"=>"212 555-1234"},
          {"type"=>"fax", "number"=>"646 555-4567"}],
        "gender"=>{"type"=>"male"},
        "number"=>[10, 5, 4, 9, 7],
        "tags"=>Set["staff", "engineer", {"joined_at"=>"2016", "emp_no"=>10}, "writer"]}

pp DeepSort.deep_sort(hash)
#=> {"address"=>
#     {"city"=>"New York",
#      "postalCode"=>"10021",
#      "state"=>"NY",
#      "streetAddress"=>"21 2nd Street"},
#    "age"=>25,
#    "firstName"=>"John",
#    "gender"=>{"type"=>"male"},
#    "lastName"=>"Smith",
#    "phoneNumber"=>
#     [{"number"=>"212 555-1234", "type"=>"home"},
#      {"number"=>"646 555-4567", "type"=>"fax"}],
#    "number" => [4, 5, 7, 9, 10],
#    "tags"=>Set["staff", "engineer", {"joined_at"=>"2016", "emp_no"=>10}, "writer"]}

sort_enum: true

pp DeepSort.deep_sort(sort_enum: true)
#=> {"address"=>
#     {"city"=>"New York",
#      "postalCode"=>"10021",
#      "state"=>"NY",
#      "streetAddress"=>"21 2nd Street"},
#    "age"=>25,
#    "firstName"=>"John",
#    "gender"=>{"type"=>"male"},
#    "lastName"=>"Smith",
#    "phoneNumber"=>
#     [{"number"=>"212 555-1234", "type"=>"home"},
#      {"number"=>"646 555-4567", "type"=>"fax"}],
#    "number" => [4, 5, 7, 9],
#    "tags"=>["engineer", "staff", "writer", {"emp_no"=>10, "joined_at"=>"2016"}]}

FAQs

Package last updated on 21 Aug 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts