ENV and IRB

来源:互联网 发布:有抢房秒杀的软件吗 编辑:程序博客网 时间:2024/05/22 16:44
1. ENV


ENV can be inherited by children, but what children do will be transparent to parent.


puts "In parent, term = #{ENV['TERM']}" fork doputs "Start of child 1, term = #{ENV['TERM']}" ENV['TERM'] = "ansi"  fork doputs "Start of child 2, term = #{ENV['TERM']}"   end      Process.wait  puts "End of child 1, term = #{ENV['TERM']}" endProcess.waitputs "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/completionirb -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=> 12irb(main):002:0> irbirb#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 airb#1([1, 2, 3]):001:0> size=> 3irb#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> sizeNameError: undefined local variable or method `size' for main:Objectfrom (irb):4from /usr/bin/irb:12:in `<main>'irb(main):005:0>



0 0
原创粉丝点击