aboutsummaryrefslogtreecommitdiff
path: root/lib/core_ext
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2013-06-22 15:52:48 -0700
committerelijah <elijah@riseup.net>2013-06-22 15:52:48 -0700
commit0ffdf42cf2171deb0bdd4c54f8281c1c1257ee86 (patch)
treeb2a6ebe57fbca426104ae364a3a5381e731c4361 /lib/core_ext
parentcae55de7bf25d60f4f504c658b936bbbd94ff464 (diff)
downloadleap_cli-0ffdf42cf2171deb0bdd4c54f8281c1c1257ee86.tar.gz
leap_cli-0ffdf42cf2171deb0bdd4c54f8281c1c1257ee86.tar.bz2
improve `leap inspect`
Diffstat (limited to 'lib/core_ext')
-rw-r--r--lib/core_ext/json.rb13
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/core_ext/json.rb b/lib/core_ext/json.rb
index 3b08a04..1a82bd9 100644
--- a/lib/core_ext/json.rb
+++ b/lib/core_ext/json.rb
@@ -12,18 +12,21 @@ module JSON
#
def self.sorted_generate(obj)
# modify hash and array
- Hash.class_eval do
+ Array.class_eval do
alias_method :each_without_sort, :each
def each(&block)
- keys.sort {|a,b| a.to_s <=> b.to_s }.each do |key|
- yield key, self[key]
+ sorted = sort {|a,b| a.to_s <=> b.to_s }
+ for i in 0..(sorted.length-1) do
+ yield sorted[i]
end
end
end
- Array.class_eval do
+ Hash.class_eval do
alias_method :each_without_sort, :each
def each(&block)
- sort {|a,b| a.to_s <=> b.to_s }.each_without_sort &block
+ self.keys.each do |key|
+ yield key, self.fetch(key) # fetch is used so we don't trigger Config::Object auto-eval
+ end
end
end