Ruby 命令行 常用命令
从命令行启动Ruby解释器时,你不仅可以提供程序文件的名字,而且可以提供一个或多个命令行开关。你选择的开关指示解释器以一种特定的方式运转,并且/或者执行特定的操作。
Ruby命令行开关有20多个,其中有些很少使用,有些则每天被很多Ruby程序员使用。在这里我们将再看几个最常用的。(你已经看到过其中的两个,-c和–w,它们结合在一起使用。)这些常用的开关总结在表1-2中,我们将分别给予解释。
表1-2 常用的Ruby命令行开关总结
命令行开关
描 述
例 子
-c
不执行程序,只检查(check)程序文件的语法
ruby –c c2f.rb
-w
在程序执行过程中给出警告(warnig)信息
ruby –w c2f.rb
-e
执行(execute)在命令行中引号内的代码
ruby –e 'puts"code demo! "'
-v
显示Ruby版本(version)信息,在详信(verbose)模式下执行程序
ruby –v
-l
行(line)模式:如果没有换行则在每一行输出后输出一个换行
ruby –l –e 'print "Will jump down! "'
-rname
加载指定的扩展(require)
ruby –rprofile
--version
显示Ruby版本(version)信息
ruby --version
相关文档:
1.install ruby
download from http://www.ruby-lang.org/en/news/2009/12/07/ruby-1-9-1-p376-is-released/
2.install rails
ruby gem install rails --include-dependencies
3.install mysql
download from http://sourceforge.net
ruby gem install&nb ......
因为一次偶然的机会接触了Ruby语言。然后下载了Ruby Shoes工具。
发现Ruby还是蛮有趣的。
花了一段时间熟悉了它的语法。
下面来试试它的鼠标功能。
Shoes.app do
#图片初始化
@img = image "http://www.google.cn/intl/zh-CN/images/logo_cn.gif"
#图片关于鼠标的调用
& ......
class Tree
def initialize
puts "Make a normal tree"
end
def decorate
puts "Make sure the tree won\'t fall"
end
end
class RedBalls < Tree
def initialize(tree)
@parent = tree;
end
def decorate
@parent.decorate
puts "Put on some red balls"
end
end
......
ruby中自带实现观察者模式的类observer。可以利用它来实现观察者模式。
代码例子:
# -*- coding: GB2312 -*-
require 'observer'
# 观察者模式(ruby)的使用例子
# 被观察者P
class PObservable
include Observable
end
# 观察者A
class AObserver
# update方法名是必须的要有的
def update(arg)
puts "AO ......
1. ruby已成为1.87
2. 必须先安装安装光盘里的新的xcode,在"optional"目录里
3. 可能需要重新安装macport
http://trac.macports.org/wiki/Migration
4. 或者升级macport
http://weblog.rubyonrails.org/2009/8/30/upgrading-to-snow-leopard
$ sudo port selfupdate
$ sudo port sync
$ sudo port upgrade --force insta ......