Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Data#to_s

() -> ::String
to_s → string

Alias of #inspect

Returns a string representation of self:

Example
Measure = Data.define(:amount, :unit)

distance = Measure[10, 'km']

p distance  # uses #inspect underneath
#<data Measure amount=10, unit="km">

puts distance  # uses #to_s underneath, same representation
#<data Measure amount=10, unit="km">
See also #inspect #to_h #with #members also in 4.0 · 3.4 · 3.3 · 3.2