ruby on rails - result of passing a symbol to method -
i have method declaration 1 argument :
def my_method(argum) if argum.empty? puts "argument empty" else puts "argument not empty" end end
when call method , pass symbol : my_method(:aleatoir_symbol)
show me argument not empty , when pass literal symbol my_method(:"")
show argument empty
i test irb , result :
:a_symbol.empty? => false :"".empty? => true
my question why when pass symbol :any_symbol show argument not empty ??
i'm searching , find similar question here there 1 answer given't me clear comprehension of reason. clear answer helpful . thank's
** update **
here original question, , open question because don't have answer
symbol#empty
defined self.to_s.empty?
(with self
being symbol).
so answer question why :"".empty?
true
: because :"".to_s
(the empty string) empty.
to adress comment: :any_symbol.empty?
false
, because :any_symbol.to_s.empty?
false
. it's same thing. maybe empty?
not method looking for. maybe didn't asking.
Comments
Post a Comment