Feature #6697
closed[PATCH] Add Kernel#Symbol conversion method like String(), Array() etc.
Description
For consistency, it seems to make sense to add a Kernel#Symbol helper.
This change would not break any existing code and it provides a more consistent interface.
Thoughts?
Files
Updated by sorah (Sorah Fukumori) over 12 years ago
I can't think any use cases of Kernel.#Symbol, could you tell me the use case?
(Why Kernel.#Symbol makes sense?)
Updated by madeofcode (Mark Dodwell) over 12 years ago
You could make the same argument against String. Why would you use that over #to_s
? I can't think of any use cases for that :)
To me, it's really about API consistency. I don't believe you would actually use it frequently, but including it is following the principle of least surprise.
Fwiw. I discovered Symbol did not exist by writing some code to call it, expecting it (since there is String, Array, Hash, etc.) I doubt I'm the only one who's tried calling Symbol, expecting it to exist.
Updated by naruse (Yui NARUSE) over 12 years ago
- Status changed from Open to Feedback
String(obj) calls obj.to_str first, then calls obj.to_s.
So they are different.
Integer("foo") raises ArgumentError, but "foo".to_i returns 0.
Array("foo") returns ["foo"], but "foo".to_a raises NoMethodError on 1.9.
Hash(nil) returns {}, but nil.to_hash raises NoMethodError.
So your point about consistency is not reasonable.
Updated by ko1 (Koichi Sasada) about 12 years ago
- Assignee set to mame (Yusuke Endoh)
- Target version changed from 2.0.0 to 2.6
No feedback there.
Updated by mame (Yusuke Endoh) about 12 years ago
- Assignee changed from mame (Yusuke Endoh) to matz (Yukihiro Matsumoto)
In Ruby, it is not a good idea to propose something because of consistency.
--
Yusuke Endoh mame@tsg.ne.jp
Updated by duerst (Martin Dürst) about 12 years ago
On 2012/10/27 20:12, mame (Yusuke Endoh) wrote:
Issue #6697 has been updated by mame (Yusuke Endoh).
Assignee changed from mame (Yusuke Endoh) to matz (Yukihiro Matsumoto)
In Ruby, it is not a good idea to propose something because of consistency.
I guess this should say:
In Ruby, it is not a good idea to propose something only because of
consistency.
Consistency is good, but (as possibly in this proposal) adding a method
just for consistency, without demonstrating an actual need, isn't Ruby
style. So please show some strong uses cases for this method.
Regards, Martin.