ruby 语法
本文转自:
http://hi.baidu.com/24xinhui/blog/item/9f52dd34382e11325ab5f553.html
ruby-语法
2009年06月20日 星期六 上午 00:21
http://www.blogjava.net/xxllnnn/archive/2009/01/18/251762.html
http://www.cnblogs.com/cnblogsfans/archive/2009/01/24/1380804.html
__setobj__ (2009-7-14)
将接受委托的对象变为obj
SimpleDelegator.new(obj)
生成一个对象, 它委托obj来执行自身所拥有的方法
alias 与 alias_method的区别 (2009-7-14)
1. alias是Ruby的一个关键字,而alias_method是Module类的一个方法
2. alias的参数就是方法本身(method identify),注意,不是字符串,也不是Symbol,alias_method的参数则是字符串或者symbol,并且使用逗号分隔。
3. alias_method可以重定义,而alias则不能
alias new_method_name old_method_name
alias_method :new_method_name, :old_method_name
alias_method 'new_method_name', 'old_method_name'
=~ 完成match匹配操作 (2009-7-13 0:48)
正则匹配
相关文档:
require 'open-uri'
$NAME_CHARS= (?a..?z).to_a+(?0..?9).to_a
def is_name_used(name)
str=open('http://passport.csdn.net/UserExist.aspx?UserName='+name)
str=str.read
#str=str.encode('GBK','utf-8')
return true if str[/Red/]
end
def enum_names(len=2)
return if len<2
f=File.open(' ......
require 'curses'
module Curses
def self.program
main_scr=init_screen
noecho
cbreak
curs_set(0)
main_scr.keypad=true
yield main_scr
end
end
Curses.program do |scr|
max_x=scr.maxx
max_y=scr.maxy
100.times do
scr.setpos(rand(max_y),rand(max_x))
......
下文转自:
http://www.cnblogs.com/watir/archive/2009/04/25/1443440.html
ruby文件从命令行中接收参数
在命令行方法执行ruby文件时,需要从命令行中传入参数,可以使用全局变量:ARGV
如有ruby 文件test.rb,内容如下:
1 def hello(a)
2 puts a
3 end
4
5 ......
Bignum
+ 加
- 减
* 乘
/ 除
** 指数操作2**2 意思是2的平方
<=> 大于, ......