Skip to content

Commit

Permalink
* lib/pp.rb: don't use local variable `pp'.
Browse files Browse the repository at this point in the history
* lib/prettyprint.rb: ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5200 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
akr committed Dec 16, 2003
1 parent c5bbcad commit ff9f067
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 188 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Tue Dec 16 21:20:47 2003 Tanaka Akira <[email protected]>

* lib/pp.rb: don't use local variable `pp'.

* lib/prettyprint.rb: ditto.

Tue Dec 16 13:20:43 2003 Hidetoshi NAGAI <[email protected]>

* ext/tk/lib/tk.rb: condition bug of if statement on
Expand Down
194 changes: 97 additions & 97 deletions lib/pp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,17 @@ def pp(*objs)

class PP < PrettyPrint
def PP.pp(obj, out=$>, width=79)
pp = PP.new(out, width)
pp.guard_inspect_key {pp.pp obj}
pp.flush
#$pp = pp
q = PP.new(out, width)
q.guard_inspect_key {q.pp obj}
q.flush
#$pp = q
out << "\n"
end

def PP.singleline_pp(obj, out=$>)
pp = SingleLine.new(out)
pp.guard_inspect_key {pp.pp obj}
pp.flush
q = SingleLine.new(out)
q.guard_inspect_key {q.pp obj}
q.flush
out
end

Expand Down Expand Up @@ -246,20 +246,20 @@ module ObjectMixin
# 3. specific to_s if instance variable is empty
# 4. generic pretty_print

def pretty_print(pp)
def pretty_print(q)
if /\(Kernel\)#/ !~ method(:inspect).inspect
pp.text self.inspect
q.text self.inspect
elsif /\(Kernel\)#/ !~ method(:to_s).inspect && instance_variables.empty?
pp.text self.to_s
q.text self.to_s
else
pp.pp_object(self)
q.pp_object(self)
end
end

def pretty_print_cycle(pp)
pp.object_address_group(self) {
pp.breakable
pp.text '...'
def pretty_print_cycle(q)
q.object_address_group(self) {
q.breakable
q.text '...'
}
end

Expand All @@ -277,80 +277,80 @@ def pretty_print_inspect
end

class Array
def pretty_print(pp)
pp.group(1, '[', ']') {
def pretty_print(q)
q.group(1, '[', ']') {
self.each {|v|
pp.comma_breakable unless pp.first?
pp.pp v
q.comma_breakable unless q.first?
q.pp v
}
}
end

def pretty_print_cycle(pp)
pp.text(empty? ? '[]' : '[...]')
def pretty_print_cycle(q)
q.text(empty? ? '[]' : '[...]')
end
end

class Hash
def pretty_print(pp)
pp.pp_hash self
def pretty_print(q)
q.pp_hash self
end

def pretty_print_cycle(pp)
pp.text(empty? ? '{}' : '{...}')
def pretty_print_cycle(q)
q.text(empty? ? '{}' : '{...}')
end
end

class << ENV
def pretty_print(pp)
pp.pp_hash self
def pretty_print(q)
q.pp_hash self
end
end

class Struct
def pretty_print(pp)
pp.object_group(self) {
def pretty_print(q)
q.object_group(self) {
self.members.each {|member|
pp.text "," unless pp.first?
pp.breakable
pp.text member.to_s
pp.text '='
pp.group(1) {
pp.breakable ''
pp.pp self[member]
q.text "," unless q.first?
q.breakable
q.text member.to_s
q.text '='
q.group(1) {
q.breakable ''
q.pp self[member]
}
}
}
end

def pretty_print_cycle(pp)
pp.text sprintf("#<%s:...>", self.class.name)
def pretty_print_cycle(q)
q.text sprintf("#<%s:...>", self.class.name)
end
end

class Range
def pretty_print(pp)
pp.pp self.begin
pp.breakable ''
pp.text(self.exclude_end? ? '...' : '..')
pp.breakable ''
pp.pp self.end
def pretty_print(q)
q.pp self.begin
q.breakable ''
q.text(self.exclude_end? ? '...' : '..')
q.breakable ''
q.pp self.end
end
end

class File
class Stat
def pretty_print(pp)
def pretty_print(q)
require 'etc.so'
pp.object_group(self) {
pp.breakable
pp.text sprintf("dev=0x%x", self.dev); pp.comma_breakable
pp.text "ino="; pp.pp self.ino; pp.comma_breakable
pp.group {
q.object_group(self) {
q.breakable
q.text sprintf("dev=0x%x", self.dev); q.comma_breakable
q.text "ino="; q.pp self.ino; q.comma_breakable
q.group {
m = self.mode
pp.text sprintf("mode=0%o", m)
pp.breakable
pp.text sprintf("(%s %c%c%c%c%c%c%c%c%c)",
q.text sprintf("mode=0%o", m)
q.breakable
q.text sprintf("(%s %c%c%c%c%c%c%c%c%c)",
self.ftype,
(m & 0400 == 0 ? ?- : ?r),
(m & 0200 == 0 ? ?- : ?w),
Expand All @@ -365,64 +365,64 @@ def pretty_print(pp)
(m & 0001 == 0 ? (m & 01000 == 0 ? ?- : ?T) :
(m & 01000 == 0 ? ?x : ?t)))
}
pp.comma_breakable
pp.text "nlink="; pp.pp self.nlink; pp.comma_breakable
pp.group {
pp.text "uid="; pp.pp self.uid
q.comma_breakable
q.text "nlink="; q.pp self.nlink; q.comma_breakable
q.group {
q.text "uid="; q.pp self.uid
begin
name = Etc.getpwuid(self.uid).name
pp.breakable; pp.text "(#{name})"
q.breakable; q.text "(#{name})"
rescue ArgumentError
end
}
pp.comma_breakable
pp.group {
pp.text "gid="; pp.pp self.gid
q.comma_breakable
q.group {
q.text "gid="; q.pp self.gid
begin
name = Etc.getgrgid(self.gid).name
pp.breakable; pp.text "(#{name})"
q.breakable; q.text "(#{name})"
rescue ArgumentError
end
}
pp.comma_breakable
pp.group {
pp.text sprintf("rdev=0x%x", self.rdev)
pp.breakable
pp.text sprintf('(%d, %d)', self.rdev_major, self.rdev_minor)
q.comma_breakable
q.group {
q.text sprintf("rdev=0x%x", self.rdev)
q.breakable
q.text sprintf('(%d, %d)', self.rdev_major, self.rdev_minor)
}
pp.comma_breakable
pp.text "size="; pp.pp self.size; pp.comma_breakable
pp.text "blksize="; pp.pp self.blksize; pp.comma_breakable
pp.text "blocks="; pp.pp self.blocks; pp.comma_breakable
pp.group {
q.comma_breakable
q.text "size="; q.pp self.size; q.comma_breakable
q.text "blksize="; q.pp self.blksize; q.comma_breakable
q.text "blocks="; q.pp self.blocks; q.comma_breakable
q.group {
t = self.atime
pp.text "atime="; pp.pp t
pp.breakable; pp.text "(#{t.tv_sec})"
q.text "atime="; q.pp t
q.breakable; q.text "(#{t.tv_sec})"
}
pp.comma_breakable
pp.group {
q.comma_breakable
q.group {
t = self.mtime
pp.text "mtime="; pp.pp t
pp.breakable; pp.text "(#{t.tv_sec})"
q.text "mtime="; q.pp t
q.breakable; q.text "(#{t.tv_sec})"
}
pp.comma_breakable
pp.group {
q.comma_breakable
q.group {
t = self.ctime
pp.text "ctime="; pp.pp t
pp.breakable; pp.text "(#{t.tv_sec})"
q.text "ctime="; q.pp t
q.breakable; q.text "(#{t.tv_sec})"
}
}
end
end
end

class MatchData
def pretty_print(pp)
pp.object_group(self) {
pp.breakable
def pretty_print(q)
q.object_group(self) {
q.breakable
1.upto(self.size) {|i|
pp.breakable unless pp.first?
pp.pp self[i-1]
q.breakable unless q.first?
q.pp self[i-1]
}
}
end
Expand All @@ -434,8 +434,8 @@ class Object

[Numeric, Symbol, FalseClass, TrueClass, NilClass, Module].each {|c|
c.class_eval {
def pretty_print_cycle(pp)
pp.text inspect
def pretty_print_cycle(q)
q.text inspect
end
}
}
Expand Down Expand Up @@ -468,10 +468,10 @@ def initialize(a)
@a = a
end

def pretty_print(pp)
pp.text "<pretty_print:"
pp.pp @a
pp.text ">"
def pretty_print(q)
q.text "<pretty_print:"
q.pp @a
q.text ">"
end
end

Expand All @@ -484,10 +484,10 @@ def inspect
return "<inspect:#{@a.inspect}>"
end

def pretty_print(pp)
pp.text "<pretty_print:"
pp.pp @a
pp.text ">"
def pretty_print(q)
q.text "<pretty_print:"
q.pp @a
q.text ">"
end
end

Expand Down
Loading

0 comments on commit ff9f067

Please sign in to comment.