摘要:(1) Execute方法$irb>> exec 'echo "hello $HOMENAME"'(2) System方法>>system 'echo "hello $HOMENAME"'(3) 反引号>> today= `date`(4) open3#popen3>>stdin,stdout,stderr=open3.popen3('dc')(5) IO#popen>>IO.popen("date") {|f| puts f.
阅读全文
随笔分类 - Ruby
摘要:irb是从命令行运行的交互式shell在命令行中输入irb后回车,进入交互式ruby模式(1) 可以用load载入rb文件执行,如以下文件code/fib_up_to.rbdef fib_up_to(max)i1,i2=1,1while i1<=maxyield i1i1,i2=i2,i1+i2endend%irbirb(main):001:0>load 'code/fib_up_to.rb'=>trueirb(main):002:0>result=[]=>[]irb(main):003:0>fib_up_to(20){|var| resul
阅读全文
摘要:1.要求安装ruby1.8.3以上,并且需要安装rails,版本也要匹配好,否则会出错。(下文用typo4.1和rails1.2.3安装成功)2.下载并安装typo,gem install typo -v"=4.1"3.升级rake,gem update rake4.安装mongrel,gem install mongrel5.进入mysql,建库和表mysql -uroot -p'你的密码'mysql>create database typo;mysql>GRANT ALL ON typo.* to typo@localhost IDENTIF
阅读全文
摘要:# Sample code from Programing Ruby, page 250require 'tk'class GifViewer def initialize(filelist) setup_viewer(filelist) end def run Tk.mainloop end def setup_viewer(filelist) @root = TkRoot.new {title 'Scroll List'} frame = TkFrame.new(@root) image_w = TkPhotoImage.new TkLabel.new(fr
阅读全文
摘要:# # To change this template, choose Tools | Templates# and open the template in the editor.# Sample code from Programing Ruby, page 248require 'tk'class Draw def do_press(x, y) @start_x = x @start_y = y @current_line = TkcLine.new(@canvas, x, y, x, y) end def do_motion(x, y) if @current_line
阅读全文

浙公网安备 33010602011771号