无法理解Ruby命令行开关-0digit

时间:2013-02-14 11:21:25

标签: ruby ruby-1.9.3

来自doc

-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:\>

1 个答案:

答案 0 :(得分: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:\>

想与ruby分享我的一整天::)

从以上链接: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:~$