[Elixir005] 查看指定数据的详细信息 i helper

#查看变量描述
iex(1)> i {:test, "That sounds great"}
Term
{:test, "That sounds great"}
Data type
Tuple
Reference modules
Tuple
#查看Module描述(有点类似于Erlang的lists:module_info)
iex(2)> i List
Term
List
Data type
Atom
Module bytecode
usr/local/Cellar/elixir/1.2.0/bin/../lib/elixir/ebin/Elixir.List.beam
Source
private/tmp/elixir20160101-48495-1fg1arr/elixir-1.2.0/lib/elixir/lib/list.ex
Version
[322093417650371381585336045669056703278]
Compile time
2016-1-1 11:57:45
Compile options
[:debug_info]
Description
Use h(List) to access its documentation.
Call List.module_info() to access metadata.
Raw representation
:"Elixir.List"
Reference modules
Module, Atom
@doc """
Prints information about the given data type.
"""
def i(term) do
info = ["Term": inspect(term)] ++ IEx.Info.info(term) for {subject, info} <- info do
info = info |> to_string() |> String.strip() |> String.replace("\n", "\n ")
IO.puts IEx.color(:eval_result, to_string(subject))
IO.puts IEx.color(:eval_info, " #{info}")
end dont_display_result
end
defprotocol IEx.Info do
@fallback_to_any true @spec info(term) :: [{atom, String.t}]
def info(term)
end defimpl IEx.Info, for: Tuple do
def info(_tuple) do
["Data type": "Tuple",
"Reference modules": "Tuple"]
end
end
它是一个protocol,在这个文件中把elixir的基本类型都实现了一次,它会返回一个keyword list, 所以我们才能看到,那么如果我们试试自己定义?
iex(3)> defmodule User do
…(3)> defstruct name: "John", age: 25
…(3)> @type t :: %User{name: String.t, age: non_neg_integer}
…(3)> end
因为在info.ex中已处理struct的类型, 如果我们现在直接i的结果它是
iex(4)> i %User{}
Term
%User{age: 25, name: "John"}
Data type
User
Description
This is a struct. Structs are maps with a __struct__ key.
Reference modules
User, Map
接下来, 我们来自定义看看
iex(5)> defimpl IEx.Info, for: User do
…(5)> def info(item) do
…(5)> ["Data type": User, "Description": "The customer is god, pleasure they", "Reference": "blablabla..."]
…(5)> end
…(5)> end
iex(6)> i %User{}
Term
%User{age: 25, name: "John"}
Data type
Elixir.User
Description
The customer is god, pleasure they
Reference
blablabla...
成功!
官方文档: http://elixir-lang.org/docs/stable/iex/IEx.Helpers.html#i/1
彩蛋:
有没有看到我们输入i得到的结果,只是把格式用有颜色的格式打印出来,但是确没有看到返回值被打印出来。。。
它的结果无论如何都打印不出来滴。因为它调用了
IEx.dont_display_result
在 evaluator.ex 里面:
unless result == IEx.dont_display_result, do: io_inspect(result)
if my fingers were erlang processes

[Elixir005] 查看指定数据的详细信息 i helper的更多相关文章
- asp.net/wingtip/显示数据和详细信息
前边我们的工作处于wingtip工程基础建设阶段,先是建立了“数据访问层”,然后设计建设了“UI和导航”的框架,接下来要充实工程的内容,显示“数据和详细信息”. 一. 添加数据控件(Data Cont ...
- 操作系统复习——如何查看一个进程的详细信息,如何追踪一个进程的执行过程 ,如何在 Linux 系统下查看 CPU、内存、磁盘、IO、网卡情况?epoll和select区别?
1. 如何查看一个进程的详细信息,如何追踪一个进程的执行过程 通过pstree命令(根据pid)进行查询进程内部当前运行了多少线程:# pstree -p 19135(进程号) 使用top命令查看(可 ...
- 使用tcpdump查看HTTP请求响应 详细信息 数据
安装tcpdump: sudo yum install tcpdump 查看get请求: tcpdump -s 0 -A 'tcp dst port 80 and tcp[((tcp[12:1] &a ...
- 【数据库】】MySQL之desc查看表结构的详细信息
在mysql中如果想要查看表的定义的话:有如下方式可供选择 1.show create table 语句: show create table table_name; 2.desc table_nam ...
- MySQL之desc查看表结构的详细信息
在mysql中如果想要查看表的定义的话:有如下方式可供选择 1.show create table 语句: show create table table_name; 2.desc table_nam ...
- Python查看模块函数,查看函数方法的详细信息
Python查看方法的详情 1.通用的帮助函数help() 使用help()函数来查看函数的帮助信息. 如: import requests help(requests) 会有类似如下输出: 2.查询 ...
- 查看mssql死锁的详细信息(存储过程)
CREATE procedure [dbo].[sp_who_lock]asbegindeclare @spid int,@bl int, @intTransactionCountOn ...
- docker查看容器元数据、详细信息,查看容器挂载的目录
通过 docker inspect 175f 查看容器元数据 我们启动docker的时候会挂载目录,但是挂载之后 后面就忘了 如何查看挂载的目录位置呢 可以通过 docker inspect a7a6 ...
- linux下如何查看某个容器的详细信息?
答: 使用docker inspect <CONTAINER ID>即可
随机推荐
- 【整理总结】目录 - 代码沉淀 - 常见Nuget包介绍及使用
为了团队项目或者后期代码维护方便,现在项目已经极致推荐使用Nuget管理第三方类库了,所以下面列举的类库,都会在Nuget上获取到.目录排序不分先后,如果查找困难,请使用 ctrl + F 重要提示: ...
- 使用libssh2连接到远程服务器
libssh2-1.7.0.tar.gz 示例代码:libssh2-1.7.0.tar.gz\libssh2-1.7.0\example 官网示例 https://www.libssh2.org/e ...
- CFGym 101194D 题解
一.题目链接 http://codeforces.com/gym/101194/problem/D 二.题意 给定一个数字n和一个数字k,一个n个整数的序列,让你在里面找尽可能多的长度为k的符合“要求 ...
- 记一次全站升级https引发的一系列问题
中秋假期,闲来无事.花了一下午折腾了下https,说实话这年头还有网站不上https显然是折腾精神不够啊~ 1.SSL证书评估 看了市面上各种类型的证书,有收费的也有免费的,但是最终还是选择了腾讯云提 ...
- MPI 并行奇偶交换排序 + 集合通信函数 Sendrecv() Sendvecv_replace()
▶ <并行程序设计导论>第三章的例子程序 ● 代码 #include <stdio.h> #include <mpi.h> #include <stdlib. ...
- 1.ehcache实现页面整体缓存和页面局部缓存
转自:https://www.cnblogs.com/jianjianyang/p/4933016.html 好长时间没写博客了,真的是没时间啊.ps:其实就是懒!!接下来几篇要写下缓存,这里主要写下 ...
- windows 关机 重启 命令
关机 shutdown -s -t 0 重启 shutdown -r -t 0 重启电脑windows 立即关机 shutdown -s 三十分钟后关机 shutdown -s -t 30 举例说明一 ...
- 下拉列表插件bootstrap-select使用实例
网页实例 http://www.jq22.com/yanshi302 使用bootstrap-select插件来实现下来菜单搜索匹配功能,如图 实现代码如下 <html> <head ...
- maven的pom报plugins缺失的解决方法
maven的pom报plugins却是的解决方法. 引用 Failure to transfer org.apache.maven.plugins:maven-surefire-plugin:pom: ...
- 7.25 6figting!
TEXT 82 Proton 马来西亚宝腾汽车 A fork in the road 何去何从?(陈继龙编译) Nov 30th 2006 | HONG KONG From The Economist ...