ENV and IRB
2015-07-27 23:48
148 查看
1. ENV
ENV can be inherited by children, but what children do will be transparent to parent.
2. irb
2.1 complete facility
Open the tab completion facility in irb. If you press TAB partway through a word, irb will look for possible completions. If there is only one possible, irb will fill it automatically. If there is more than one option, irb does nothing. However if you press
TAB again, it will display the list of all the completions at the terminal.
Ways to enable the completion:
2. subsession and bind
irb support multiple and concurrent sessions. And each subsession has seperate environment. enter a "irb" to create a new subsession, and use 'fg' to change diffrent subsession.
The code bellow illustrate the subsession.
While, if you pass an object to the irb command, then the object will be binding to the self, and you can involk all the method directly without the object name.
ENV can be inherited by children, but what children do will be transparent to parent.
puts "In parent, term = #{ENV['TERM']}" fork do puts "Start of child 1, term = #{ENV['TERM']}" ENV['TERM'] = "ansi" fork do puts "Start of child 2, term = #{ENV['TERM']}" end Process.wait puts "End of child 1, term = #{ENV['TERM']}" end Process.wait puts "Back in parent, term = #{ENV['TERM']}"
2. irb
2.1 complete facility
Open the tab completion facility in irb. If you press TAB partway through a word, irb will look for possible completions. If there is only one possible, irb will fill it automatically. If there is more than one option, irb does nothing. However if you press
TAB again, it will display the list of all the completions at the terminal.
Ways to enable the completion:
irb -r irb/completion irb -r irb/completion
2. subsession and bind
irb support multiple and concurrent sessions. And each subsession has seperate environment. enter a "irb" to create a new subsession, and use 'fg' to change diffrent subsession.
The code bellow illustrate the subsession.
irb(main):001:0> a = 12 => 12 irb(main):002:0> irb irb#1(main):001:0> a = [1,2,3] => [1, 2, 3] irb#1(main):002:0> jobs => #0->irb on main (#<Thread:0x007fdd328bc8d0>: stop) #1->irb#1 on main (#<Thread:0x007fdd339fb6a0>: running) irb#1(main):003:0> fg 0 => #<IRB::Irb: @context=#<IRB::Context:0x007fdd339c82c8>, @signal_status=:IN_EVAL, @scanner=#<RubyLex:0x007fdd3281d690>> irb(main):003:0> a => 12
While, if you pass an object to the irb command, then the object will be binding to the self, and you can involk all the method directly without the object name.
irb(main):001:0> a = [1,2,3] => [1, 2, 3] irb(main):002:0> irb a irb#1([1, 2, 3]):001:0> size => 3 irb#1([1, 2, 3]):002:0> reverse => [3, 2, 1] irb#1([1, 2, 3]):003:0> self => [1, 2, 3] irb#1([1, 2, 3]):004:0> irb_exit => #<IRB::Irb: @context=#<IRB::Context:0x007fd2fa2c4320>, @signal_status=:IN_EVAL, @scanner=#<RubyLex:0x007fd2fb809708>> irb(main):003:0> a => [1, 2, 3] irb(main):004:0> size NameError: undefined local variable or method `size' for main:Object from (irb):4 from /usr/bin/irb:12:in `<main>' irb(main):005:0>
相关文章推荐
- apk防止重新签名
- 20150727
- 导入项目 R.java没有
- 轻装上阵,安卓工程师之路---day06(HTTP & Servlet)
- ncurses简单的一个多窗口程序
- 原创jQuery插件之loadmore
- bzoj1179
- poj2109&nyoj773
- [黑马程序员](第40天)一些平时刷的题
- 使用Fragment(3)
- Wormholes (POJ 3259)
- Android图像格式类及图像转换方法
- [黑马程序员](第17)异常
- 通过统计工具做数据分析、优化和挖掘
- Basic Calculator 基本计算器-Leetcode
- 表格布局和线性布局
- 移动H5前端性能优化指南
- java学习笔记(五)collections--vector
- Android第一夜
- HDU 1171 Big Event in HDU