Project

General

Profile

Bug #7656 ยป ruby-docs-201301_PP-Debug-ENV.patch

documentation against 902a36c1f6157385fc8cd914f3c8824017efbfeb - vbatts (Vincent Batts), 01/06/2013 06:14 AM

View differences:

hash.c
2566 2566
    return ary;
2567 2567
}
2568 2568

  
2569
/*
2570
 * call-seq:
2571
 *   ENV.each_key { |name| } -> Hash
2572
 *   ENV.each_key            -> Enumerator
2573
 *
2574
 * Yields each environment variable name.
2575
 *
2576
 * An Enumerator is returned if no block is given.
2577
 */
2578 2569
static VALUE
2579 2570
rb_env_size(VALUE ehash)
2580 2571
{
......
2593 2584
    return LONG2FIX(cnt);
2594 2585
}
2595 2586

  
2587
/*
2588
 * Document-method: ENV.each_key
2589
 *
2590
 * call-seq:
2591
 *   ENV.each_key { |name| } -> Hash
2592
 *   ENV.each_key            -> Enumerator
2593
 *
2594
 * Yields each environment variable name.
2595
 *
2596
 * An Enumerator is returned if no block is given.
2597
 */
2596 2598
static VALUE
2597 2599
env_each_key(VALUE ehash)
2598 2600
{
lib/debug.rb
891 891
  @stdout = STDOUT
892 892

  
893 893
  class << DEBUGGER__
894
    # Returns the IO used as stdout. Defaults to STDOUT
894 895
    def stdout
895 896
      @stdout
896 897
    end
897 898

  
899
    # Sets the IO used as stdout. Defaults to STDOUT
898 900
    def stdout=(s)
899 901
      @stdout = s
900 902
    end
901 903

  
904
    # Returns the display expression list
905
    #
906
    # See DEBUGGER__ for more useage
902 907
    def display
903 908
      @display
904 909
    end
905 910

  
911
    # Returns the list of break points to stop operation at
912
    #
913
    # See DEBUGGER__ for more useage
906 914
    def break_points
907 915
      @break_points
908 916
    end
909 917

  
918
    # Returns the list of waiting threads.
919
    #
920
    # When stepping through thre traces of a function, thread gets suspended, to be resumed later.
910 921
    def waiting
911 922
      @waiting
912 923
    end
lib/pp.rb
106 106
  end
107 107

  
108 108
  module PPMethods
109

  
110
    # Yields to a block
111
    # and preserves the previous set of objects being printed.
109 112
    def guard_inspect_key
110 113
      if Thread.current[:__recursive_key__] == nil
111 114
        Thread.current[:__recursive_key__] = {}.untrust
......
125 128
      end
126 129
    end
127 130

  
131
    # Check whether the object_id +id+ is in the current buffer of objects
132
    # to be pretty printed. Used to break cycles in chains of objects to be
133
    # pretty printed.
134
    # As follows:
135
    #
136
    #   obj = Object.new
137
    #   => #<Object:0x843a384>
138
    #   check_inspect_key(obj.object_id)
139
    #   => false
140
    #   push_inspect_key(obj.object_id)
141
    #   => true
142
    #   check_inspect_key(obj.object_id)
143
    #   => true
144
    #
128 145
    def check_inspect_key(id)
129 146
      Thread.current[:__recursive_key__] &&
130 147
      Thread.current[:__recursive_key__][:inspect] &&
131 148
      Thread.current[:__recursive_key__][:inspect].include?(id)
132 149
    end
150

  
151
    # Adds the object_id +id+ to the set of objects being pretty printed, so
152
    # as to not repeat objects.
133 153
    def push_inspect_key(id)
134 154
      Thread.current[:__recursive_key__][:inspect][id] = true
135 155
    end
156

  
157
    # Removes an object from the set of objects being pretty printed.
136 158
    def pop_inspect_key(id)
137 159
      Thread.current[:__recursive_key__][:inspect].delete id
138 160
    end
......
165 187
      group(1, '#<' + obj.class.name, '>', &block)
166 188
    end
167 189

  
190
    # A mask used in formating object_id's into a hexadecimal id
168 191
    PointerMask = (1 << ([""].pack("p").size * 8)) - 1
169 192

  
170 193
    case Object.new.inspect
171 194
    when /\A\#<Object:0x([0-9a-f]+)>\z/
195
      # String Formating for hexadecimal id
172 196
      PointerFormat = "%0#{$1.length}x"
173 197
    else
174 198
      PointerFormat = "%x"
175 199
    end
176 200

  
177
    def object_address_group(obj, &block)
201
    # A convenience method, like object_group, but also reformats the Object's
202
    # object_id.
203
    def object_address_group(obj, &block) # :yield:
178 204
      id = PointerFormat % (obj.object_id * 2 & PointerMask)
179 205
      group(1, "\#<#{obj.class}:0x#{id}", '>', &block)
180 206
    end
......
225 251
      }
226 252
    end
227 253

  
254
    # A present standard failsafe for pretty printing any given Object
228 255
    def pp_object(obj)
229 256
      object_address_group(obj) {
230 257
        seplist(obj.pretty_print_instance_variables, lambda { text ',' }) {|v|
......
240 267
      }
241 268
    end
242 269

  
270
    # A pretty print for a Hash
243 271
    def pp_hash(obj)
244 272
      group(1, '{', '}') {
245 273
        seplist(obj, nil, :each_pair) {|k, v|
......
325 353
end
326 354

  
327 355
class Array
356
  # Used by PP to show Array specific pretty printing
328 357
  def pretty_print(q)
329 358
    q.group(1, '[', ']') {
330 359
      q.seplist(self) {|v|
......
333 362
    }
334 363
  end
335 364

  
365
  # Used by PP to show a cycle, or repitition, of Arrays
336 366
  def pretty_print_cycle(q)
337 367
    q.text(empty? ? '[]' : '[...]')
338 368
  end
339 369
end
340 370

  
341 371
class Hash
372
  # Used by PP to show Hash specific pretty printing
342 373
  def pretty_print(q)
343 374
    q.pp_hash self
344 375
  end
345 376

  
377
  # Used by PP to show a cycle, or repitition, of Hashes
346 378
  def pretty_print_cycle(q)
347 379
    q.text(empty? ? '{}' : '{...}')
348 380
  end
349 381
end
350 382

  
351 383
class << ENV
384
  # Used by PP to show ENV specific pretty printing
352 385
  def pretty_print(q)
353 386
    h = {}
354 387
    ENV.keys.sort.each {|k|
......
359 392
end
360 393

  
361 394
class Struct
395
  # Used by PP to show Struct specific pretty printing
362 396
  def pretty_print(q)
363 397
    q.group(1, sprintf("#<struct %s", PP.mcall(self, Kernel, :class).name), '>') {
364 398
      q.seplist(PP.mcall(self, Struct, :members), lambda { q.text "," }) {|member|
......
373 407
    }
374 408
  end
375 409

  
410
  # Used by PP to show a cycle, or repitition, of Structs
376 411
  def pretty_print_cycle(q)
377 412
    q.text sprintf("#<struct %s:...>", PP.mcall(self, Kernel, :class).name)
378 413
  end
379 414
end
380 415

  
381 416
class Range
417
  # Used by PP to show Range specific pretty printing
382 418
  def pretty_print(q)
383 419
    q.pp self.begin
384 420
    q.breakable ''
......
390 426

  
391 427
class File < IO
392 428
  class Stat
429
    # Used by PP to show File::Stat specific pretty printing
393 430
    def pretty_print(q)
394 431
      require 'etc.so'
395 432
      q.object_group(self) {
......
471 508
end
472 509

  
473 510
class MatchData
511
  # Used by PP to show MatchData specific pretty printing
474 512
  def pretty_print(q)
475 513
    nc = []
476 514
    self.regexp.named_captures.each {|name, indexes|