From 0ffdf42cf2171deb0bdd4c54f8281c1c1257ee86 Mon Sep 17 00:00:00 2001 From: elijah Date: Sat, 22 Jun 2013 15:52:48 -0700 Subject: improve `leap inspect` --- lib/core_ext/json.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'lib/core_ext') 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 -- cgit v1.2.3