class Hocon::Impl::SimpleConfigObject::RenderComparator

Public Class Methods

all_digits?(s) click to toggle source
# File lib/hocon/impl/simple_config_object.rb, line 391
def self.all_digits?(s)
  s =~ /^\d+$/
end
sort(arr) click to toggle source

This is supposed to sort numbers before strings, and sort the numbers numerically. The point is to make objects which are really list-like (numeric indices) appear in order.

# File lib/hocon/impl/simple_config_object.rb, line 399
def self.sort(arr)
  arr.sort do |a, b|
    a_digits = all_digits?(a)
    b_digits = all_digits?(b)
    if a_digits && b_digits
      Integer(a) <=> Integer(b)
    elsif a_digits
      -1
    elsif b_digits
      1
    else
      a <=> b
    end
  end
end