2013-02-14 47 views
0

doc無法理解的Ruby命令行開關-0digit

-0digit =>

指定輸入記錄分隔符($ /)作爲一個八進制數。如果沒有給出數字,則空字符是分隔符。其他開關可以在數字後面。 -00將Ruby轉換爲段落模式。 -0777使Ruby一次讀取整個文件作爲單個字符串,因爲沒有合法的字符與該值。

我的壞!根本無法消化它。所以讓我們開始玩吧。

C:\>ruby -0777 -e 'a= gets; puts a ' 
Hi, This is Ram. 
Could you help me here? 
^Z #~~~> pressed ENTER here after CTRL+Z and got the output as below- 
Hi, This is Ram. 
Could you help me here? 
C:\>ruby #~~~> return the prompt 

C:\>ruby -000 -e 'a= gets; puts a ' 
Hi, This is Ram. 
Could you help me here? 
^Z #~~~> pressed ENTER here after CTRL+Z and got the output as below- 
Hi, This is Ram. 
Could you help me here? 
C:\>ruby #~~~> return the prompt 

C:\>ruby -00 -e 'a= gets; puts a ' 
Hi, This is Ram. 
Could you help me here? #~~~> pressed ENTER 
#~~~> pressed ENTER here and got the output as below- 
Hi, This is Ram. 
Could you help me here? 
C:\>ruby #~~~> return the prompt 

問題:1 -我可以設置這樣octal$/爲下面?

carraige return (\r) 
tab (\t) 

如果是這樣,我可以有一個例子讓每個人看到他們的行爲?

問題:2 - 我也試圖打印的"$/"並沒有打印任何價值。那我應該怎麼看?

C:\>ruby -00 -e 'a= gets; puts a ;puts "here is: #{$/}"' 
hi 

hi 

here is: 


C:\>ruby -0777 -e 'a= gets; puts a ;puts "here is: #{$/}"' 
Hey! Arjun 
Are you going school? 

^Z 
Hey! Arjun 
Are you going school? 

here is: 

C:\> 
+0

任何人都可以請驗證我的答案嗎?或者如果有更多我需要放在那裏? – 2013-02-22 22:40:16

回答

0

Using as

最後我發現瞭如何設置carraige return (\r) and tab (\t)的方式。

找到下面的代碼:

C:\>ruby -00 -e 'a= gets; puts a ;puts "here is: #{$/.inspect}"' 
Hi 

Hi 

here is: "\n\n" 

C:\>ruby -015 -e 'a= gets; puts a ;puts "here is: #{$/.inspect}"' 
hi 
hi 
^Z 
hi 
hi 
here is: "\r" 

C:\>ruby -011 -e 'a= gets; puts a ;puts "here is: #{$/.inspect}"' 
Hello 

^Z 
Hello 

here is: "\t" 

C:\> 

最後,我可以用.inspect如下打印:

C:\>ruby -00 -e 'a= gets; puts a ;puts "here is: #{$/.inspect}"' 
Hi 

Hi 

here is: "\n\n" 

C:\> 

想分享我整天與紅寶石::)

從上述鏈接:ASCII Code

我得到了更多的轉義字符的八進制代碼,同時也打了他們使用Ruby命令行選項-0<digit>

這裏是例子的完整列表..閱讀和消化它。 :)

@ubuntu:~$ ruby -010 -e 'a= gets; puts a ;puts "here is: #{$/.inspect}"' 
This is a spoon. Do you need it.^H 
This is a spoon. Do you need it. 
here is: "\b" 

@ubuntu:~$ ruby -033 -e 'a= gets; puts a ;puts "here is: #{$/.inspect}"' 
Hi..How are you? 
Are you going ^[ school today? 
Hi..How are you? 
Are you going 
here is: "\e" 

@ubuntu:~$ ruby -011 -e 'a= gets; puts a ;puts "here is: #{$/.inspect}"' 
Today is very hot outside the room 
Today is very hot outside 
here is: "\t" 

@ubuntu:~$ ruby -015 -e 'a= gets; puts a ;puts "here is: #{$/.inspect}"' 
Are you mad?hey..^Mhello..I am telling you dude... 
Are you mad?hey.. 
here is: "\r" 

@ubuntu:~$ ruby -012 -e 'a= gets; puts a ;puts "here is: #{$/.inspect}"' 
Are you there? 
Are you there? 
here is: "\n" 

@ubuntu:~$ ruby -040 -e 'a= gets; puts a ;puts "here is: #{$/.inspect}"' 
Iammmmmmmmmm a 
Iammmmmmmmmm 
here is: " " 

@ubuntu:~$ ruby -014 -e 'a= gets; puts a ;puts "here is: #{$/.inspect}"' 
Earth is an planet.Remember it...^L dear brother 
Earth is an planet.Remember it... 

here is: "\f" 

@ubuntu:~$ ruby -000 -e 'a= gets; puts a ;puts "here is: #{$/.inspect}"' 
Hiiiii............ 

Hiiiii............ 

here is: "\n\n" 
@ubuntu:~$