instance method
PP::PPMethods#seplist
(untyped list, ?(^() -> void)? sep, ?::interned iter_method) { (*untyped, **untyped) -> void } -> void
seplist(list, sep=nil, iter_method=:each) { |element| ... }
lib/pp.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/lib/pp.rb, line 267
def seplist(list, sep=nil, iter_method=:each) # :yield: element
sep ||= lambda { comma_breakable }
first = true
kwsplat = EMPTY_KWHASH
list.__send__(iter_method) {|*v|
if first
first = false
else
sep.call
end
kwsplat ? yield(*v, **kwsplat) : yield(*v)
}
end
Adds a separated list. The list is separated by comma with breakable space, by default.
seplist iterates the list using iter_method. It yields each object to the block given for seplist. The procedure separator_proc is called between each yields.
If the iteration is zero times, separator_proc is not called at all.
If separator_proc is nil or not given, +lambda { comma_breakable }+ is used. If iter_method is not given, :each is used.
For example, following 3 code fragments has similar effect.
Example
q.seplist([1,2,3]) {|v| xxx v } q.seplist([1,2,3], lambda { q.comma_breakable }, :each) {|v| xxx v } xxx 1 q.comma_breakable xxx 2 q.comma_breakable xxx 3