Bug #7656 » ruby-docs-201301_PP-Debug-ENV.patch
hash.c | ||
---|---|---|
return ary;
|
||
}
|
||
/*
|
||
* call-seq:
|
||
* ENV.each_key { |name| } -> Hash
|
||
* ENV.each_key -> Enumerator
|
||
*
|
||
* Yields each environment variable name.
|
||
*
|
||
* An Enumerator is returned if no block is given.
|
||
*/
|
||
static VALUE
|
||
rb_env_size(VALUE ehash)
|
||
{
|
||
... | ... | |
return LONG2FIX(cnt);
|
||
}
|
||
/*
|
||
* Document-method: ENV.each_key
|
||
*
|
||
* call-seq:
|
||
* ENV.each_key { |name| } -> Hash
|
||
* ENV.each_key -> Enumerator
|
||
*
|
||
* Yields each environment variable name.
|
||
*
|
||
* An Enumerator is returned if no block is given.
|
||
*/
|
||
static VALUE
|
||
env_each_key(VALUE ehash)
|
||
{
|
lib/debug.rb | ||
---|---|---|
@stdout = STDOUT
|
||
class << DEBUGGER__
|
||
# Returns the IO used as stdout. Defaults to STDOUT
|
||
def stdout
|
||
@stdout
|
||
end
|
||
# Sets the IO used as stdout. Defaults to STDOUT
|
||
def stdout=(s)
|
||
@stdout = s
|
||
end
|
||
# Returns the display expression list
|
||
#
|
||
# See DEBUGGER__ for more useage
|
||
def display
|
||
@display
|
||
end
|
||
# Returns the list of break points to stop operation at
|
||
#
|
||
# See DEBUGGER__ for more useage
|
||
def break_points
|
||
@break_points
|
||
end
|
||
# Returns the list of waiting threads.
|
||
#
|
||
# When stepping through thre traces of a function, thread gets suspended, to be resumed later.
|
||
def waiting
|
||
@waiting
|
||
end
|
lib/pp.rb | ||
---|---|---|
end
|
||
module PPMethods
|
||
# Yields to a block
|
||
# and preserves the previous set of objects being printed.
|
||
def guard_inspect_key
|
||
if Thread.current[:__recursive_key__] == nil
|
||
Thread.current[:__recursive_key__] = {}.untrust
|
||
... | ... | |
end
|
||
end
|
||
# Check whether the object_id +id+ is in the current buffer of objects
|
||
# to be pretty printed. Used to break cycles in chains of objects to be
|
||
# pretty printed.
|
||
# As follows:
|
||
#
|
||
# obj = Object.new
|
||
# => #<Object:0x843a384>
|
||
# check_inspect_key(obj.object_id)
|
||
# => false
|
||
# push_inspect_key(obj.object_id)
|
||
# => true
|
||
# check_inspect_key(obj.object_id)
|
||
# => true
|
||
#
|
||
def check_inspect_key(id)
|
||
Thread.current[:__recursive_key__] &&
|
||
Thread.current[:__recursive_key__][:inspect] &&
|
||
Thread.current[:__recursive_key__][:inspect].include?(id)
|
||
end
|
||
# Adds the object_id +id+ to the set of objects being pretty printed, so
|
||
# as to not repeat objects.
|
||
def push_inspect_key(id)
|
||
Thread.current[:__recursive_key__][:inspect][id] = true
|
||
end
|
||
# Removes an object from the set of objects being pretty printed.
|
||
def pop_inspect_key(id)
|
||
Thread.current[:__recursive_key__][:inspect].delete id
|
||
end
|
||
... | ... | |
group(1, '#<' + obj.class.name, '>', &block)
|
||
end
|
||
# A mask used in formating object_id's into a hexadecimal id
|
||
PointerMask = (1 << ([""].pack("p").size * 8)) - 1
|
||
case Object.new.inspect
|
||
when /\A\#<Object:0x([0-9a-f]+)>\z/
|
||
# String Formating for hexadecimal id
|
||
PointerFormat = "%0#{$1.length}x"
|
||
else
|
||
PointerFormat = "%x"
|
||
end
|
||
def object_address_group(obj, &block)
|
||
# A convenience method, like object_group, but also reformats the Object's
|
||
# object_id.
|
||
def object_address_group(obj, &block) # :yield:
|
||
id = PointerFormat % (obj.object_id * 2 & PointerMask)
|
||
group(1, "\#<#{obj.class}:0x#{id}", '>', &block)
|
||
end
|
||
... | ... | |
}
|
||
end
|
||
# A present standard failsafe for pretty printing any given Object
|
||
def pp_object(obj)
|
||
object_address_group(obj) {
|
||
seplist(obj.pretty_print_instance_variables, lambda { text ',' }) {|v|
|
||
... | ... | |
}
|
||
end
|
||
# A pretty print for a Hash
|
||
def pp_hash(obj)
|
||
group(1, '{', '}') {
|
||
seplist(obj, nil, :each_pair) {|k, v|
|
||
... | ... | |
end
|
||
class Array
|
||
# Used by PP to show Array specific pretty printing
|
||
def pretty_print(q)
|
||
q.group(1, '[', ']') {
|
||
q.seplist(self) {|v|
|
||
... | ... | |
}
|
||
end
|
||
# Used by PP to show a cycle, or repitition, of Arrays
|
||
def pretty_print_cycle(q)
|
||
q.text(empty? ? '[]' : '[...]')
|
||
end
|
||
end
|
||
class Hash
|
||
# Used by PP to show Hash specific pretty printing
|
||
def pretty_print(q)
|
||
q.pp_hash self
|
||
end
|
||
# Used by PP to show a cycle, or repitition, of Hashes
|
||
def pretty_print_cycle(q)
|
||
q.text(empty? ? '{}' : '{...}')
|
||
end
|
||
end
|
||
class << ENV
|
||
# Used by PP to show ENV specific pretty printing
|
||
def pretty_print(q)
|
||
h = {}
|
||
ENV.keys.sort.each {|k|
|
||
... | ... | |
end
|
||
class Struct
|
||
# Used by PP to show Struct specific pretty printing
|
||
def pretty_print(q)
|
||
q.group(1, sprintf("#<struct %s", PP.mcall(self, Kernel, :class).name), '>') {
|
||
q.seplist(PP.mcall(self, Struct, :members), lambda { q.text "," }) {|member|
|
||
... | ... | |
}
|
||
end
|
||
# Used by PP to show a cycle, or repitition, of Structs
|
||
def pretty_print_cycle(q)
|
||
q.text sprintf("#<struct %s:...>", PP.mcall(self, Kernel, :class).name)
|
||
end
|
||
end
|
||
class Range
|
||
# Used by PP to show Range specific pretty printing
|
||
def pretty_print(q)
|
||
q.pp self.begin
|
||
q.breakable ''
|
||
... | ... | |
class File < IO
|
||
class Stat
|
||
# Used by PP to show File::Stat specific pretty printing
|
||
def pretty_print(q)
|
||
require 'etc.so'
|
||
q.object_group(self) {
|
||
... | ... | |
end
|
||
class MatchData
|
||
# Used by PP to show MatchData specific pretty printing
|
||
def pretty_print(q)
|
||
nc = []
|
||
self.regexp.named_captures.each {|name, indexes|
|