For overflow below, the quotes are surrounding an array.
overflow = [5,6,7]
p overflow #=> [5, 6, 7]
p "#{overflow}" #=> "[5, 6, 7]"
For stack below, the results are strange for the interpolated expression.
stack = 1234.to_s.chars.reverse.each_slice(3).map { |s| s.reverse.join }.reverse
p stack #=> ["1", "234"]
p "#{stack}" #=> "[\"1\", \"234\"]"
How does the p method show escape characters with stack, but not with overflow? Why does this occur only with interpolation as opposed to when printed without interpolation?
overflowis an array of integers whilestackis an array of strings. There's nothing to escape inoverflow.Possibly you meant to make
stackan array ofFxinumas well, in which case add.map(&:to_i)at the end of the method chain:For the second question, that's how the method
pworks. To ge precise, the behavior is defined inString#inspectas that's the methodpis using: