Skip to content

Instantly share code, notes, and snippets.

@shiroyasha
Last active August 29, 2015 14:12
Show Gist options
  • Save shiroyasha/5df7355ef99f979814f7 to your computer and use it in GitHub Desktop.
Save shiroyasha/5df7355ef99f979814f7 to your computer and use it in GitHub Desktop.
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