[#2139] Best way to install ri documentation — Dave Thomas <dave@...>

Folks:

69 messages 2004/01/04
[#2140] Re: Best way to install ri documentation — Gavin Sinclair <gsinclair@...> 2004/01/04

On Monday, January 5, 2004, 2:29:57 AM, Dave wrote:

[#2141] Re: Best way to install ri documentation — matz@... (Yukihiro Matsumoto) 2004/01/04

Hi,

[#2145] Re: Best way to install ri documentation — Richard Kilmer <rich@...> 2004/01/05

Perhaps make it available for mirrors and save ruby-lang's bandwidth?

[#2147] Re: Best way to install ri documentation — Dave Thomas <dave@...> 2004/01/05

[#2148] Re: Best way to install ri documentation -- please check this — Dave Thomas <dave@...> 2004/01/05

So, I'm thinking about doing the following? Is this OK with everyone?

[#2149] Re: Best way to install ri documentation -- please check this — "J.Herre" <jlst@...> 2004/01/05

[#2152] Re: Best way to install ri documentation -- please check this — Dave Thomas <dave@...> 2004/01/05

[#2153] Re: Best way to install ri documentation -- please check this — nobu.nokada@... 2004/01/05

Hi,

[#2154] Re: Best way to install ri documentation -- please check this — Dave Thomas <dave@...> 2004/01/05

[#2219] Re: Best way to install ri documentation -- please check this — "James F. Hranicky" <jfh@...> 2004/01/12

On Tue, 6 Jan 2004 00:47:41 +0900

[#2194] File.readable_world? and File.writable_world? — Ian Macdonald <ian@...>

Hello,

27 messages 2004/01/09
[#2195] Re: [PATCH] File.readable_world? and File.writable_world? — Eivind Eklund <eivind@...> 2004/01/09

On Fri, Jan 09, 2004 at 06:02:07PM +0900, Ian Macdonald wrote:

[#2199] Re: [PATCH] File.readable_world? and File.writable_world? — Ian Macdonald <ian@...> 2004/01/09

On Fri 09 Jan 2004 at 23:10:02 +0900, Eivind Eklund wrote:

[#2200] Re: [PATCH] File.readable_world? and File.writable_world? — matz@... (Yukihiro Matsumoto) 2004/01/10

Hi,

[#2203] Re: [PATCH] File.readable_world? and File.writable_world? — Ian Macdonald <ian@...> 2004/01/11

On Sun 11 Jan 2004 at 00:47:33 +0900, Yukihiro Matsumoto wrote:

[#2206] Re: [PATCH] File.readable_world? and File.writable_world? — matz@... (Yukihiro Matsumoto) 2004/01/11

Hi,

[#2208] Re: [PATCH] File.readable_world? and File.writable_world? — Ian Macdonald <ian@...> 2004/01/11

On Sun 11 Jan 2004 at 21:40:22 +0900, Yukihiro Matsumoto wrote:

[#2209] Re: [PATCH] File.readable_world? and File.writable_world? — matz@... (Yukihiro Matsumoto) 2004/01/12

Hi,

[#2216] ruby aborts in data-handling applications — xsdg <xsdg@...>

I reported a similar bug about 2 or 3 months ago. The problem seemed to go

12 messages 2004/01/12

pp.rb patch to optionally sort hash keys

From: David Garamond <lists@...6.isreserved.com>
Date: 2004-01-25 12:18:57 UTC
List: ruby-core #2301
I see that Perl's Data::Dumper and YAML already have this feature, and I 
happen to need it in pp.

Patched against 1.8.0's pp.rb.

-- 
dave

Attachments (1)

pp.rb-sort_keys.patch (1.84 KB, text/x-diff)
--- /usr/lib/ruby/1.8/pp.rb	Mon May 12 09:49:13 2003
+++ pp2.rb	Sun Jan 25 19:03:16 2004
@@ -69,6 +69,12 @@
 --- PP.sharing_detection = boolean_value
     sets the sharing detection flag.
 
+--- PP.sort_keys
+    returns the sort keys flag as a boolean value.
+
+--- PP.sort_keys = boolean_value
+    sets the sort keys flag.
+
 == methods
 --- pp(obj)
     adds ((|obj|)) to the pretty printing buffer
@@ -154,6 +160,11 @@
     attr_accessor :sharing_detection
   end
 
+  @sort_keys = false
+  class << self
+    attr_accessor :sort_keys
+  end
+
   module PPMethods
     InspectKey = :__inspect_key__
 
@@ -219,17 +230,32 @@
 
     def pp_hash(obj)
       group(1, '{', '}') {
-        obj.each {|k, v|
-          comma_breakable unless first?
-          group {
-            pp k
-            text '=>'
-            group(1) {
-              breakable ''
-              pp v
+        if PP.sort_keys
+          obj.to_a.sort.each {|kv|
+            k, v = kv[0, 2]
+            comma_breakable unless first?
+            group {
+              pp k
+              text '=>'
+              group(1) {
+                breakable ''
+                pp v
+              }
             }
           }
-        }
+        else
+          obj.each {|k, v|
+            comma_breakable unless first?
+            group {
+              pp k
+              text '=>'
+              group(1) {
+                breakable ''
+                pp v
+              }
+            }
+          }
+        end
       }
     end
   end
@@ -592,4 +618,16 @@
       end
     end
   end
+
+  class PPSortKeysTest < Test::Unit::TestCase
+    def test_hash
+      begin
+        PP.sort_keys = true
+        assert_equal("{1=>2, 3=>4, 5=>6, 7=>8, 9=>10}\n", 
+                     PP.pp({1=>2, 3=>4, 5=>6, 7=>8, 9=>10}, ''))
+      ensure
+        PP.sort_keys = false
+      end
+    end
+  end
 end

In This Thread

Prev Next