- 浏览: 118907 次
- 性别:
- 来自: 上海
最新评论
-
sqz10200:
不错挺好使.
Javascript实现把网页中table的内容导入到excel中的几种方法 -
zxboom:
非常感谢,好用。
rails使用fasterCSV将csv文件导入到数据库 -
liyh:
fasterCSV操作 -
weskycn:
欣赏了!
Eclipse中集成Aptana+RadRails -
hlily2005:
ie.Document.getElementById(&quo ...
Win32ole
转!
1 检测文件是否存在及其大小
FileTest的 exist?方法可以检测一个文件是否存在:
如果我们想要知道文件是否有内容,可以使用File::Stat的zero? 方法:
这个将会返回true,这是因为在ruby中0也是true,nil才是false.
所以我们可以使用size?方法:
FileTest模块里面也有zero? 和size?方法:
这里还有一个size方法:
2 检测特殊文件属性
这边要注意,File类mix了FIleTest模块,并且FileTest模块和File::Stat模块功能上也有很多重复.
unix/linux有面向字符和面向块的设备。FileTest的方法blockdev?和chardev?可以进行测试:
有时我们想要知道一个流是否联系到了终端,这时我们可以使用IO类的tty?方法:
一个流可以是一个管道,或者一个socket:
要区分目录和普通文件我们这样使用:
File还有一个类方法ftype,他将返回流的类型.他也在File::Stat里面,只不过是实例方法.它的返回值可能是下面的字符
串(file、directory、blockSpecial、characterSpecial、fifo、link或socket).
要测试一个文件是否为另一个文件的链接,可以使用FileTest的symlink?方法,要计算链接数量,可以使用nlink方法:
3 使用管道
ruby中使用IO.popen打开管道:
要注意 必须调用close_write,如果没有调用它,读取管道的时候,就不能到达文件的末尾.
下面是一个block的形式:
如果指定了一个字符串"-",那么一个新的ruby实例将被创建.如果指定了一个block,那么这个block将会作为两个独立
的进程运行。子进程得到nil,父进程得到一个IO对象:
pipe方法也返回互相连接的一对管道:
4 使用非阻塞IO
ruby会在后台执行一些操作,使io不会被阻断,因此大部分情况下可以使用ruby线程来管理IO,当一个线程被Io阻塞之
后,另外的线程能够继续执行.
由于ruby的线程不是一个native的线程,因此ruby的线程都在同一个进程里面.
如果你想关闭一个非阻塞io,你可以这样做:
5 使用readpartial
readpartial被设计来用于就像socket这样的流.
readpartial要求提供最大长度的参数,如果指定了buffer,那么这个buffer应指向用于存储数据的一个字符串。
readpartial 方法,不能接受非阻塞的flag,他有时会阻塞:IO对象的buffer是空的;流的内容为空;流没有到达文件末尾
。
因此,如果流中还有数据的话,readpartial将不会阻塞.
如果流没有数据,并且他已经抵达文件的末尾,readpartial 将会立即抛出一个EOFError.
如果调用阻塞,他将会等待直到接收到数据或者得到一个EOF.
当sysread 调用在阻塞模式下,他的行为与readpartial相似.
6 操作路径名
先来看一下File.dirname和File.basename方法:
File.split方法,可以将一个文件的路径名和文件名分隔开:
类方法expand_path 将一个相对路径,转换为一个绝对路径名:
对于打开的文件,path 将会返回这个文件的路径名:
类方法类方法join正好和split相反:
7使用Pathname
pathname类实际上是,Dir, File, FileTest,和FileUtils的包装器,它包含他们的很多功能:
再看看其他的有用的方法:
relative和absolute判断路径是否是相对的:
8 Command-Level 文件操作
其实也就是copy, delete, rename,等等 些操作了:
fileUtils也有很多有用的方法
9 从键盘抓取输入
也就是抓取用户从键盘输入的字符。
unix平台:
windows平台:
10 读取整个文件到内存
读取整个文件到数组,你不需要打开文件,IO.readlines 可以完成这个工作,他自己会open和close.
也可以用IO.read(它返回一个大的字符串):
由于File继承了IO,因此File也有这两个方法.
11 逐行迭代一个文件
我们可以使用IO.foreach 方法,或者each方法,如果是前者文件不需要显示打开:
12逐字节对文件进行遍历
可以使用each_byte方法,如果你想要转换byte到字符的话使用chr方法:
12 把字符串当文件来用
我们可以使用stringio库:
13读取嵌套在程序中的数据
ruby中程序末尾的__END__ 标记说明,下面的数据是程序内嵌的数据,你可以使用一个IO对象DATA来读取。
14 读取程序源码
DATA指向__END__ 后面的数据,如果你调用rewind,它将会将文件指针指向程序的开头:
1 检测文件是否存在及其大小
FileTest的 exist?方法可以检测一个文件是否存在:
- flag = FileTest::exist?("LochNessMonster")
- flag = FileTest::exists?("UFO")
- # exists? is a synonym for exist?
flag = FileTest::exist?("LochNessMonster") flag = FileTest::exists?("UFO") # exists? is a synonym for exist?
如果我们想要知道文件是否有内容,可以使用File::Stat的zero? 方法:
flag = File.new("somefile").stat.zero?
这个将会返回true,这是因为在ruby中0也是true,nil才是false.
所以我们可以使用size?方法:
- if File.new("myfile").stat.size?
- puts "The file has contents."
- else
- puts "The file is empty."
- end
if File.new("myfile").stat.size? puts "The file has contents." else puts "The file is empty." end
FileTest模块里面也有zero? 和size?方法:
flag1 = FileTest::zero?("file1") flag2 = FileTest::size?("file2")
这里还有一个size方法:
size1 = File.size("file1") size2 = File.stat("file2").size
2 检测特殊文件属性
这边要注意,File类mix了FIleTest模块,并且FileTest模块和File::Stat模块功能上也有很多重复.
unix/linux有面向字符和面向块的设备。FileTest的方法blockdev?和chardev?可以进行测试:
- flag1 = FileTest::chardev?("/dev/hdisk0") # false
- flag2 = FileTest::blockdev?("/dev/hdisk0") # true
flag1 = FileTest::chardev?("/dev/hdisk0") # false flag2 = FileTest::blockdev?("/dev/hdisk0") # true
有时我们想要知道一个流是否联系到了终端,这时我们可以使用IO类的tty?方法:
flag1 = STDIN.tty? # true flag2 = File.new("diskfile").isatty # false
一个流可以是一个管道,或者一个socket:
flag1 = FileTest::pipe?(myfile) flag2 = FileTest::socket?(myfile)
要区分目录和普通文件我们这样使用:
- file1 = File.new("/tmp")
- file2 = File.new("/tmp/myfile")
- test1 = file1.directory? # true
- test2 = file1.file? # false
- test3 = file2.directory? # false
- test4 = file2.file? # true
file1 = File.new("/tmp") file2 = File.new("/tmp/myfile") test1 = file1.directory? # true test2 = file1.file? # false test3 = file2.directory? # false test4 = file2.file? # true
File还有一个类方法ftype,他将返回流的类型.他也在File::Stat里面,只不过是实例方法.它的返回值可能是下面的字符
串(file、directory、blockSpecial、characterSpecial、fifo、link或socket).
- this_kind = File.ftype("/dev/hdisk0") # "blockSpecial"
- that_kind = File.new("/tmp").stat.ftype # "directory"
this_kind = File.ftype("/dev/hdisk0") # "blockSpecial" that_kind = File.new("/tmp").stat.ftype # "directory"
要测试一个文件是否为另一个文件的链接,可以使用FileTest的symlink?方法,要计算链接数量,可以使用nlink方法:
- File.symlink("yourfile","myfile") # Make a link
- is_sym = FileTest::symlink?("myfile") # true
- hard_count = File.new("myfile").stat.nlink # 0
File.symlink("yourfile","myfile") # Make a link is_sym = FileTest::symlink?("myfile") # true hard_count = File.new("myfile").stat.nlink # 0
3 使用管道
ruby中使用IO.popen打开管道:
- check = IO.popen("spell","r+")
- check.puts("'T was brillig, and the slithy toves")
- check.puts("Did gyre and gimble in the wabe.")
- check.close_write
- list = check.readlines
- list.collect! { |x| x.chomp }
- # list is now %w[brillig gimble gyre slithy toves wabe]
check = IO.popen("spell","r+") check.puts("'T was brillig, and the slithy toves") check.puts("Did gyre and gimble in the wabe.") check.close_write list = check.readlines list.collect! { |x| x.chomp } # list is now %w[brillig gimble gyre slithy toves wabe]
要注意 必须调用close_write,如果没有调用它,读取管道的时候,就不能到达文件的末尾.
下面是一个block的形式:
- File.popen("/usr/games/fortune") do |pipe|
- quote = pipe.gets
- puts quote
- # On a clean disk, you can seek forever. - Thomas Steel
- end
File.popen("/usr/games/fortune") do |pipe| quote = pipe.gets puts quote # On a clean disk, you can seek forever. - Thomas Steel end
如果指定了一个字符串"-",那么一个新的ruby实例将被创建.如果指定了一个block,那么这个block将会作为两个独立
的进程运行。子进程得到nil,父进程得到一个IO对象:
- IO.popen("-") do |mypipe|
- if mypipe
- puts "I'm the parent: pid = #{Process.pid}"
- listen = mypipe.gets
- puts listen
- else
- puts "I'm the child: pid = #{Process.pid}"
- end
- end
- # Prints:
- # I'm the parent: pid = 10580
- # I'm the child: pid = 10582
IO.popen("-") do |mypipe| if mypipe puts "I'm the parent: pid = #{Process.pid}" listen = mypipe.gets puts listen else puts "I'm the child: pid = #{Process.pid}" end end # Prints: # I'm the parent: pid = 10580 # I'm the child: pid = 10582
pipe方法也返回互相连接的一对管道:
- pipe = IO.pipe
- reader = pipe[0]
- writer = pipe[1]
- str = nil
- thread1 = Thread.new(reader,writer) do |reader,writer|
- # writer.close_write
- str = reader.gets
- reader.close
- end
- thread2 = Thread.new(reader,writer) do |reader,writer|
- # reader.close_read
- writer.puts("What hath God wrought?")
- writer.close
- end
- thread1.join
- thread2.join
- puts str # What hath God wrought?
pipe = IO.pipe reader = pipe[0] writer = pipe[1] str = nil thread1 = Thread.new(reader,writer) do |reader,writer| # writer.close_write str = reader.gets reader.close end thread2 = Thread.new(reader,writer) do |reader,writer| # reader.close_read writer.puts("What hath God wrought?") writer.close end thread1.join thread2.join puts str # What hath God wrought?
4 使用非阻塞IO
ruby会在后台执行一些操作,使io不会被阻断,因此大部分情况下可以使用ruby线程来管理IO,当一个线程被Io阻塞之
后,另外的线程能够继续执行.
由于ruby的线程不是一个native的线程,因此ruby的线程都在同一个进程里面.
如果你想关闭一个非阻塞io,你可以这样做:
- require 'io/nonblock'
- # ...
- test = mysock.nonblock? # false
- mysock.nonblock = true # turn off blocking
- # ...
- mysock.nonblock = false # turn on again
- mysock.nonblock { some_operation(mysock) }
- # Perform some_operation with nonblocking set to true
- mysock.nonblock(false) { other_operation(mysock) }
- # Perform other_operation with non-blocking set to false
require 'io/nonblock' # ... test = mysock.nonblock? # false mysock.nonblock = true # turn off blocking # ... mysock.nonblock = false # turn on again mysock.nonblock { some_operation(mysock) } # Perform some_operation with nonblocking set to true mysock.nonblock(false) { other_operation(mysock) } # Perform other_operation with non-blocking set to false
5 使用readpartial
readpartial被设计来用于就像socket这样的流.
readpartial要求提供最大长度的参数,如果指定了buffer,那么这个buffer应指向用于存储数据的一个字符串。
data = sock.readpartial(128) # Read at most 128 bytes
readpartial 方法,不能接受非阻塞的flag,他有时会阻塞:IO对象的buffer是空的;流的内容为空;流没有到达文件末尾
。
因此,如果流中还有数据的话,readpartial将不会阻塞.
如果流没有数据,并且他已经抵达文件的末尾,readpartial 将会立即抛出一个EOFError.
如果调用阻塞,他将会等待直到接收到数据或者得到一个EOF.
当sysread 调用在阻塞模式下,他的行为与readpartial相似.
6 操作路径名
先来看一下File.dirname和File.basename方法:
- str = "/home/dave/podbay.rb"
- dir = File.dirname(str) # "/home/dave"
- file1 = File.basename(str) # "podbay.rb"
- file2 = File.basename(str,".rb") # "podbay"
str = "/home/dave/podbay.rb" dir = File.dirname(str) # "/home/dave" file1 = File.basename(str) # "podbay.rb" file2 = File.basename(str,".rb") # "podbay"
File.split方法,可以将一个文件的路径名和文件名分隔开:
info = File.split(str) # ["/home/dave","podbay.rb"]
类方法expand_path 将一个相对路径,转换为一个绝对路径名:
- Dir.chdir("/home/poole/personal/docs")
- abs = File.expand_path("../../misc") # "/home/poole/misc"
Dir.chdir("/home/poole/personal/docs") abs = File.expand_path("../../misc") # "/home/poole/misc"
对于打开的文件,path 将会返回这个文件的路径名:
file = File.new("../../foobar") name = file.path # "../../foobar"
类方法类方法join正好和split相反:
path = File.join("usr","local","bin","someprog")
7使用Pathname
pathname类实际上是,Dir, File, FileTest,和FileUtils的包装器,它包含他们的很多功能:
- require 'pathname'
- path = Pathname.new("home/hal")
- file = Pathname.new("file.txt")
- p2 = path + file
- path.directory? # true
- path.file? # false
- p2.directory? # false
- p2.file? # true
- puts parts = p2.split # [Pathname:/home/hal, Pathname:file.txt]
- puts ext = p2.extname # .txt
require 'pathname' path = Pathname.new("home/hal") file = Pathname.new("file.txt") p2 = path + file path.directory? # true path.file? # false p2.directory? # false p2.file? # true puts parts = p2.split # [Pathname:/home/hal, Pathname:file.txt] puts ext = p2.extname # .txt
再看看其他的有用的方法:
- p1 = Pathname.new("//") # odd but legal
- p1.root? # true
- p2 = Pathname.new("/home/poole")
- p3 = p2.parent # Pathname:/home
- items = p2.children # array of Pathnames (all files and
- # dirs immediately under poole)
p1 = Pathname.new("//") # odd but legal p1.root? # true p2 = Pathname.new("/home/poole") p3 = p2.parent # Pathname:/home items = p2.children # array of Pathnames (all files and # dirs immediately under poole)
relative和absolute判断路径是否是相对的:
p1 = Pathname.new("/home/dave") p1.absolute? # true p1.relative? # false
8 Command-Level 文件操作
其实也就是copy, delete, rename,等等 些操作了:
- File.delete("history")
- File.unlink("toast")
- File.rename("Ceylon","SriLanka")
- File.link("/etc/hosts","/etc/hostfile") # hard link
- File.symlink("/etc/hosts","/tmp/hosts") # symbolic link
- File.truncate("myfile",1000) # Now at most 1000 bytes
File.delete("history") File.unlink("toast") File.rename("Ceylon","SriLanka") File.link("/etc/hosts","/etc/hostfile") # hard link File.symlink("/etc/hosts","/tmp/hosts") # symbolic link File.truncate("myfile",1000) # Now at most 1000 bytes
fileUtils也有很多有用的方法
- require "fileutils"
- same = FileUtils.compare_file("alpha","beta") # true
- # Copy epsilon to theta and log any errors.
- FileUtils.copy("epsilon","theta", true)
- FileUtils.move("/tmp/names","/etc") # Move to new directory
- FileUtils.move("colours","colors") # Just a rename
- FileUtils.safe_unlink("alpha","beta","gamma")
- # Log errors on the next two files
- FileUtils.safe_unlink("delta","epsilon",true)
- FileUtils.install("foo.so","/usr/lib")
require "fileutils" same = FileUtils.compare_file("alpha","beta") # true # Copy epsilon to theta and log any errors. FileUtils.copy("epsilon","theta", true) FileUtils.move("/tmp/names","/etc") # Move to new directory FileUtils.move("colours","colors") # Just a rename FileUtils.safe_unlink("alpha","beta","gamma") # Log errors on the next two files FileUtils.safe_unlink("delta","epsilon",true) FileUtils.install("foo.so","/usr/lib")
9 从键盘抓取输入
也就是抓取用户从键盘输入的字符。
unix平台:
- def getchar
- system("stty raw -echo") # Raw mode, no echo
- char = STDIN.getc
- system("stty -raw echo") # Reset terminal mode
- char
- end
def getchar system("stty raw -echo") # Raw mode, no echo char = STDIN.getc system("stty -raw echo") # Reset terminal mode char end
windows平台:
require 'Win32API' def getchar char = Win32API.new("crtdll", "_getch", [], 'L').Call end
10 读取整个文件到内存
读取整个文件到数组,你不需要打开文件,IO.readlines 可以完成这个工作,他自己会open和close.
- arr = IO.readlines("myfile")
- lines = arr.size
- puts "myfile has #{lines} lines in it."
- longest = arr.collect {|x| x.length}.max
- puts "The longest line in it has #{longest} characters."
arr = IO.readlines("myfile") lines = arr.size puts "myfile has #{lines} lines in it." longest = arr.collect {|x| x.length}.max puts "The longest line in it has #{longest} characters."
也可以用IO.read(它返回一个大的字符串):
- str = IO.read("myfile")
- bytes = arr.size
- puts "myfile has #{bytes} bytes in it."
- longest = str.collect {|x| x.length}.max # strings are enumerable!
- puts "The longest line in it has #{longest} characters."
str = IO.read("myfile") bytes = arr.size puts "myfile has #{bytes} bytes in it." longest = str.collect {|x| x.length}.max # strings are enumerable! puts "The longest line in it has #{longest} characters."
由于File继承了IO,因此File也有这两个方法.
11 逐行迭代一个文件
我们可以使用IO.foreach 方法,或者each方法,如果是前者文件不需要显示打开:
- # Print all lines containing the word "target"
- IO.foreach("somefile") do |line|
- puts line if line =~ /target/
- end
- # Another way...
- file = File.new("somefile")
- file.each do |line|
- puts line if line =~ /target/
- end
# Print all lines containing the word "target" IO.foreach("somefile") do |line| puts line if line =~ /target/ end # Another way... file = File.new("somefile") file.each do |line| puts line if line =~ /target/ end
12逐字节对文件进行遍历
可以使用each_byte方法,如果你想要转换byte到字符的话使用chr方法:
- file = File.new("myfile")
- e_count = 0
- file.each_byte do |byte|
- e_count += 1 if byte == ?e
- end
file = File.new("myfile") e_count = 0 file.each_byte do |byte| e_count += 1 if byte == ?e end
12 把字符串当文件来用
我们可以使用stringio库:
- require 'stringio'
- ios = StringIO.new("abcdefghijkl\nABC\n123")
- ios.seek(5)
- ios.puts("xyz")
- puts ios.tell # 8
- puts ios.string.dump # "abcdexyzijkl\nABC\n123"
- c = ios.getc
- puts "c = #{c}" # c = 105
- ios.ungetc(?w)
- puts ios.string.dump # "abcdexyzwjkl\nABC\n123"
- puts "Ptr = #{ios.tell}"
- s1 = ios.gets # "wjkl"
- s2 = ios.gets # "ABC"
require 'stringio' ios = StringIO.new("abcdefghijkl\nABC\n123") ios.seek(5) ios.puts("xyz") puts ios.tell # 8 puts ios.string.dump # "abcdexyzijkl\nABC\n123" c = ios.getc puts "c = #{c}" # c = 105 ios.ungetc(?w) puts ios.string.dump # "abcdexyzwjkl\nABC\n123" puts "Ptr = #{ios.tell}" s1 = ios.gets # "wjkl" s2 = ios.gets # "ABC"
13读取嵌套在程序中的数据
ruby中程序末尾的__END__ 标记说明,下面的数据是程序内嵌的数据,你可以使用一个IO对象DATA来读取。
- # Print each line backwards...
- DATA.each_line do |line|
- puts line.reverse
- end
- __END__
- A man, a plan, a canal... Panama!
- Madam, I'm Adam.
- ,siht daer nac uoy fI
- .drah oot gnikrow neeb ev'uoy
# Print each line backwards... DATA.each_line do |line| puts line.reverse end __END__ A man, a plan, a canal... Panama! Madam, I'm Adam. ,siht daer nac uoy fI .drah oot gnikrow neeb ev'uoy
14 读取程序源码
DATA指向__END__ 后面的数据,如果你调用rewind,它将会将文件指针指向程序的开头:
发表评论
-
Ruby中对XML文档的解析
2009-11-18 14:41 0引用至:http://www.cnblogs.com/code ... -
rails缓存及生成静态页面
2009-08-04 10:29 0http://www.xiuce888.cn/2009/07/ ... -
install ror on ubuntu
2009-08-04 10:09 0#install rubygems sudo apt-get ... -
RJB使用
2008-11-12 01:35 0RJB使用 RJB(ruby java bridge) ... -
install ruby on rails On Ubuntu
2008-05-09 19:23 01,用apt-get来安装ruby rdoc irb,ri之类 ... -
ruby正则表达式
2008-05-08 18:23 1283转 Ruby的正则表达式以"//"作为基本 ... -
Sitealizer Web Stats
2008-05-04 18:52 1706This plugin lets you track visi ... -
win32ole操作outlook
2008-04-30 09:58 2000通过win32ole我们可以操作outlook,例如平时我们所 ... -
Ruby Date, DateTime and Time extensions
2008-04-16 18:40 0转class Date def begin_of_day ... -
Win32ole
2008-04-15 17:52 6918Win32ole为标准Ruby发行版的一部分。Win32ole ... -
Eclipse中集成Aptana+RadRails
2008-04-15 13:08 4219转 Aptana+RadRails,将其以插件的形式集成到Ec ... -
fasterCSV操作
2008-04-09 17:25 2399fasterCSV This class provides ... -
rails使用fasterCSV将csv文件导入到数据库
2008-04-09 11:52 3282fasterCSV是一个处理 CSV 文件的库, 在ruby ... -
不好说明,进来看代码
2007-12-12 11:29 1139第一步 在页面得到id 第二步 到控制器里面做查询 第三步 得 ... -
rails 自关联 删除父节点删除子节点
2007-12-04 15:02 2434class Module < Activ ... -
Exception Notifier - Ruby on Rails plugin
2007-11-13 16:56 1587在ROR的wiki里面有文章介绍如何在发生错误的时候发送ema ... -
Rails Migration参考
2007-11-13 16:23 2384更新到最新版本: rake db:migrate 重设数据 ... -
rails级联
2007-09-28 20:28 2335这是一个关于省份和城市的级联操作,当选择省份的时候,省份的状 ... -
rails批量更新
2007-09-28 19:42 4838rails批量更新 ruby 代码 user_contro ...
相关推荐
ruby文件操作
ruby文件操作大全,主要是DIR,FILE和文件夹类的相关操作,比较实用
主要介绍了Ruby常用文件操作方法,本文讲解了新建文件、读取文件、删除、重命名文件、目录操作等常用文件操作方法,需要的朋友可以参考下
Ruby的Ini文件读写,含实例,操作方法 对于学习Ruby的人会有一定的参考价值。
ruby 目录操作详细介绍,增删查改,移动文件等等操作
刚学习ruby,交出自己的学习成果,请大侠们不要见笑,希望对初学者能有所帮助,我们共同提高!
ruby-git, ruby/Git是一个 ruby 库,可以通过将系统调用包装到Git二进制文件来创建读取和操作Git存储库 用于 ruby的 Git库在 ruby 中使用Git的库。主页项目源代码的Git public 位于:...
Squid - 一个Ruby库用于在PDF文件中绘制图表
主要介绍了Ruby中操作文件的方法介绍,是Ruby学习当中的基础知识,需要的朋友可以参考下
CombinePDF - 一个合并PDF文件的纯ruby库
由于想操作excel文件,对其的数据进行修改,但是因为没有office2003(价格原因)所以无法直接修改。所以调查了一下,有很多日本人做好的gem(spreadsheet.gem)可以直接拿来用。也就可以不安装office就可以对excel...
主要介绍了Ruby常用文件操作代码实例,如新建文件、输出文件内容、IO操作、输出文件路径、stringio使用等内容,需要的朋友可以参考下
sql缓存指之前执行过的查询sql语句以及他的结果缓存在内存中,在一段时间内用相同的sql语句执行查询操作时不经过数据库直接返回内存中数据。rubyPHP使用Redis以键值方式缓存sql语句以及他的对应结果。rubyPHP能够在...
在对Ruby进行了简要的综述之后,《Ruby编程语言》详细介绍了以下内容:Ruby的句法和语法结构,数据结构和对象,表达式和操作符,语句和控制结构,方法、proc、lambda和闭包,反射和元编程,Ruby平台。本书还包含对...
{Hornetseye::Malloc.new} 可以分配内存,使用 {Hornetseye::Malloc#+} 可以做指针操作,{Hornetseye::Malloc#read} 和 {Hornetseye::Malloc#write} 提供读取 Ruby从内存中取出字符串并将 Ruby 字符串写入内存。...
运行安装程序: 双击下载的Ruby Installer安装程序(通常是一个.exe文件),然后按照安装向导的指示进行操作。在安装过程中,您可以选择安装目录、添加环境变量等选项。 完成安装: 安装程序会将Ruby解释器、...