~ubuntu-branches/ubuntu/intrepid/ruby1.9/intrepid-updates

« back to all changes in this revision

Viewing changes to lib/pp.rb

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-09-04 16:01:17 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20070904160117-i15zckg2nhxe9fyw
Tags: 1.9.0+20070830-2ubuntu1
* Sync from Debian; remaining changes:
  - Add -g to CFLAGS.
* Fixes build failure on ia64.
* Fixes build failure with gcc-4.2 on lpia.
* Robustify check for target_os, fixing build failure on lpia.
* Set Ubuntu maintainer address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
247
247
 
248
248
    def pp_hash(obj)
249
249
      group(1, '{', '}') {
250
 
        seplist(obj, nil, :each_pair) {|k, v|
 
250
        keys = obj.keys
 
251
        if 0 < keys.length
 
252
          key_class = keys[0].class
 
253
          if key_class < Comparable && keys.all? {|k| k.class == key_class }
 
254
            keys.sort!
 
255
          end
 
256
        end
 
257
        seplist(keys, nil, :each) {|k|
 
258
          v = obj[k]
251
259
          group {
252
260
            pp k
253
261
            text '=>'
283
291
    # This module provides predefined #pretty_print methods for some of
284
292
    # the most commonly used built-in classes for convenience.
285
293
    def pretty_print(q)
286
 
      if /\(Kernel\)#/ !~ method(:inspect).inspect
 
294
      if /\(Kernel\)#/ !~ Object.instance_method(:method).bind(self).call(:inspect).inspect
287
295
        q.text self.inspect
288
 
      elsif /\(Kernel\)#/ !~ method(:to_s).inspect && instance_variables.empty?
 
296
      elsif /\(Kernel\)#/ !~ Object.instance_method(:method).bind(self).call(:to_s).inspect && instance_variables.empty?
289
297
        q.text self.to_s
290
298
      else
291
299
        q.pp_object(self)
317
325
    # However, doing this requires that every class that #inspect is called on
318
326
    # implement #pretty_print, or a RuntimeError will be raised.
319
327
    def pretty_print_inspect
320
 
      if /\(PP::ObjectMixin\)#/ =~ method(:pretty_print).inspect
 
328
      if /\(PP::ObjectMixin\)#/ =~ Object.instance_method(:method).bind(self).call(:pretty_print).inspect
321
329
        raise "pretty_print is not overridden for #{self.class}"
322
330
      end
323
331
      PP.singleline_pp(self, '')
516
524
      a = OverriddenStruct.new(1,2)
517
525
      assert_equal("#<struct Struct::OverriddenStruct members=1, class=2>\n", PP.pp(a, ''))
518
526
    end
 
527
 
 
528
    def test_redefined_method
 
529
      o = ""
 
530
      def o.method
 
531
      end
 
532
      assert_equal(%(""\n), PP.pp(o, ""))
 
533
    end
519
534
  end
520
535
 
521
536
  class HasInspect