зеркало из https://github.com/github/ruby.git
* lib/prettyprint.rb (PrettyPrint#seplist): added.
* lib/pp.rb (PPMethods#pp_object): use seplist. (PPMethods#pp_hash): ditto. (Array#pretty_print): ditto. (Struct#pretty_print): ditto. (MatchData#pretty_print): ditto. * lib/set.rb (Set#pretty_print): use seplist. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5623 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
90d8cbb1ee
Коммит
0c792a32b7
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
||||||
|
Thu Feb 5 23:56:55 2004 Tanaka Akira <akr@m17n.org>
|
||||||
|
|
||||||
|
* lib/prettyprint.rb (PrettyPrint#seplist): added.
|
||||||
|
|
||||||
|
* lib/pp.rb (PPMethods#pp_object): use seplist.
|
||||||
|
(PPMethods#pp_hash): ditto.
|
||||||
|
(Array#pretty_print): ditto.
|
||||||
|
(Struct#pretty_print): ditto.
|
||||||
|
(MatchData#pretty_print): ditto.
|
||||||
|
|
||||||
|
* lib/set.rb (Set#pretty_print): use seplist.
|
||||||
|
|
||||||
Wed Feb 4 22:39:46 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Wed Feb 4 22:39:46 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* file.c (rb_stat_mode): should not sign-expand, so backout.
|
* file.c (rb_stat_mode): should not sign-expand, so backout.
|
||||||
|
|
17
lib/pp.rb
17
lib/pp.rb
|
@ -203,10 +203,9 @@ class PP < PrettyPrint
|
||||||
|
|
||||||
def pp_object(obj)
|
def pp_object(obj)
|
||||||
object_address_group(obj) {
|
object_address_group(obj) {
|
||||||
obj.pretty_print_instance_variables.each {|v|
|
seplist(obj.pretty_print_instance_variables, lambda { text ',' }) {|v|
|
||||||
v = v.to_s if Symbol === v
|
|
||||||
text ',' unless first?
|
|
||||||
breakable
|
breakable
|
||||||
|
v = v.to_s if Symbol === v
|
||||||
text v
|
text v
|
||||||
text '='
|
text '='
|
||||||
group(1) {
|
group(1) {
|
||||||
|
@ -219,8 +218,7 @@ class PP < PrettyPrint
|
||||||
|
|
||||||
def pp_hash(obj)
|
def pp_hash(obj)
|
||||||
group(1, '{', '}') {
|
group(1, '{', '}') {
|
||||||
obj.each {|k, v|
|
seplist(obj, nil, :each_pair) {|k, v|
|
||||||
comma_breakable unless first?
|
|
||||||
group {
|
group {
|
||||||
pp k
|
pp k
|
||||||
text '=>'
|
text '=>'
|
||||||
|
@ -279,8 +277,7 @@ end
|
||||||
class Array
|
class Array
|
||||||
def pretty_print(q)
|
def pretty_print(q)
|
||||||
q.group(1, '[', ']') {
|
q.group(1, '[', ']') {
|
||||||
self.each {|v|
|
q.seplist(self) {|v|
|
||||||
q.comma_breakable unless q.first?
|
|
||||||
q.pp v
|
q.pp v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -310,8 +307,7 @@ end
|
||||||
class Struct
|
class Struct
|
||||||
def pretty_print(q)
|
def pretty_print(q)
|
||||||
q.group(1, '#<struct ' + self.class.name, '>') {
|
q.group(1, '#<struct ' + self.class.name, '>') {
|
||||||
self.members.each {|member|
|
q.seplist(self.members, lambda { q.text "," }) {|member|
|
||||||
q.text "," unless q.first?
|
|
||||||
q.breakable
|
q.breakable
|
||||||
q.text member.to_s
|
q.text member.to_s
|
||||||
q.text '='
|
q.text '='
|
||||||
|
@ -420,8 +416,7 @@ class MatchData
|
||||||
def pretty_print(q)
|
def pretty_print(q)
|
||||||
q.object_group(self) {
|
q.object_group(self) {
|
||||||
q.breakable
|
q.breakable
|
||||||
1.upto(self.size) {|i|
|
q.seplist(1..self.size, lambda { q.breakable }) {|i|
|
||||||
q.breakable unless q.first?
|
|
||||||
q.pp self[i-1]
|
q.pp self[i-1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,6 +159,19 @@ class PrettyPrint
|
||||||
@group_stack.last
|
@group_stack.last
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def seplist(list, sep=nil, iter_method=:each)
|
||||||
|
sep ||= lambda { comma_breakable }
|
||||||
|
first = true
|
||||||
|
list.__send__(iter_method) {|*v|
|
||||||
|
if first
|
||||||
|
first = false
|
||||||
|
else
|
||||||
|
sep.call
|
||||||
|
end
|
||||||
|
yield(*v)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def first?
|
def first?
|
||||||
current_group.first?
|
current_group.first?
|
||||||
end
|
end
|
||||||
|
|
|
@ -418,14 +418,7 @@ class Set
|
||||||
def pretty_print(pp) # :nodoc:
|
def pretty_print(pp) # :nodoc:
|
||||||
pp.text sprintf('#<%s: {', self.class.name)
|
pp.text sprintf('#<%s: {', self.class.name)
|
||||||
pp.nest(1) {
|
pp.nest(1) {
|
||||||
first = true
|
pp.seplist(self) { |o|
|
||||||
each { |o|
|
|
||||||
if first
|
|
||||||
first = false
|
|
||||||
else
|
|
||||||
pp.text ","
|
|
||||||
pp.breakable
|
|
||||||
end
|
|
||||||
pp.pp o
|
pp.pp o
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче