Module: EnumerableToString

Defined in:
lib/utilrb/enumerable/to_s_helper.rb

Class Method Summary collapse

Class Method Details

.to_s_helper(enumerable, start, stop) ⇒ Object

This method is a generic implementaion of #to_s on enumerables.


3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/utilrb/enumerable/to_s_helper.rb', line 3

def self.to_s_helper(enumerable, start, stop)
	stack = (Thread.current[:to_s_helper] ||= [])
	if stack.include?(enumerable.object_id)
 "..."
	else
 begin
		stack.push enumerable.object_id
		start.dup << enumerable.map { |el| yield(el) }.join(", ") << stop
 ensure
		stack.pop
 end
	end
end