elixir - 使用 i 来查看某个变量的具体情况(类似与 ruby 的 .inspect)
访问量: 1455
参考:https://stackoverflow.com/questions/28377135/how-do-you-check-for-the-type-of-variable-in-elixir
iex(10)> i %{ 1 => 10, 2 => 20}
Term
%{1 => 10, 2 => 20}
Data type
Map
Reference modules
Map
Implemented protocols
Collectable, Enumerable, IEx.Info, Inspect
不过还有更好的办法
IO.puts "===== hi ,now print inspect"
IO.inspect some_var
遇到下面的问题怎么办?
** (Mix) Could not start application explorer: Explorer.Application.start(:normal, []) returned an error: shutdown: failed to start child: Explorer.Chain.Events.Listener ** (EXIT) an exception was raised: ** (ArgumentError) cannot convert the given list to a string. To be converted to a string, a list must either be empty or only contain the following elements: * strings * integers representing Unicode code points * a list containing one of these three elements
你一定是在代码里面这样写了: IO.puts "==== hi #{some_var}" 如果some_var是个数组,这里就会报错。
写成这样:
IO.puts "=== hi #{inspect some_var}"