0

文档

-0 位 =>

将输入记录分隔符 ($/) 指定为八进制数。如果没有给出数字,则空字符是分隔符。其他开关可能跟在数字后面。-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:\>
4

1 回答 1

0

用作

最后我找到了如何设置 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码

我得到了更多转义字符的八进制代码,并使用 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:~$ 
于 2013-02-14T12:40:45.790 回答