我正在学习Ruby,而且我已经看到了一些令我困惑的方法,特别是to_svs to_str(以及to_i/ to_int,to_a/ to_ary,&to_h/ to_hash).我读过的内容解释了较短的形式(例如to_s)用于显式转换,而较长的形式用于隐式转换.
to_s
to_str
to_i
to_int
to_a
to_ary
to_h
to_hash
我真的不明白to_str将如何使用.除了String以外的东西会定义to_str吗?你能为这种方法提供实际应用吗?
ruby string methods
methods ×1
ruby ×1
string ×1