Difference between `to_s` and `to_str` ๐Ÿ™Œ๐Ÿผ

Let's take an example of to_s and to_str here.

Both are used to transform a value from one type to another. We usually use to_s to convert an object into string while to_str allows you to verify that the object can be considered as string.

Code Snippet -

# String
โฏ "Ruby".to_s 					#=> "Ruby"
โฏ "Ruby".respond_to?(:to_str) 	#=> true
โฏ "Ruby".to_str 				#=> "Ruby"

# Integer
โฏ 10.to_s 					#=> "10"
โฏ 10.respond_to?(:to_str) 	#=> false
โฏ 10.to_str 				#=> NoMethodError: undefined method `to_str' for 10:Integer