Actions
Feature #4621
closedNilClass#to_hash
Feature #4621:
NilClass#to_hash
Description
=begin
Various methods defined on NilClass are handy to avoid Method undefined on NilClass errors. For example,
-
to_afor multiple dimensioned array when there might not be some values for some indices: -
to_sfor pattern match that might fail: -
to_i,to_f,to_cfor index search that might fail, etc:
But there is no NilClass#to_hash even though there is Hash#to_hash. If such method existed (equivalent to class NilClass; def to_hash; {} end end), then we would be able to do:
-
to_hashfor multiple embedded hash when there might not be some values for some keys:
Is there any reason why to_a, to_s, to_i, to_f, to_c are all defined on NilClass but not for to_hash? If there is not, I would like to request this feature.
=end
Actions