Last active
August 29, 2015 14:12
-
-
Save shiroyasha/5df7355ef99f979814f7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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