Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class Animal
def initialize(name)
@name = name
end
def to_s
@name
end
end
result = [Animal.new("Pera"), Animal.new("Djura")].to_s
# in ruby 1.9
puts result # => "[Pera, Djura]"
# in ruby 2.0
puts result # => "[#<Animal:0x00000002266b08 @name=\"Pera\">, #<Animal:0x00000002266ab8 @name=\"Djura\">]"
# in other words
# - in ruby 1.9 an array calls recursively `to_s` on its elements
# - in ruby 2.0 an array calls recursively `inspect` on its elements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.