ENV and IRB

1. ENV


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>



  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值