写的一个inter类模仿ruby整数的行为
我们知道ruby中对于整数的[],[]=,<<,>>操作是针对于二进制的值来运算的。
我现在写一个针对十进制数操作的类,拥有整数的所有方法,如下:
class InterEx
def initialize(val=0)
@val=val
end
def to_s
@val.to_s
end
def [](idx)
self.to_s[idx].to_i
end
def []=(idx,val)
s=self.to_s
s[idx] = val.to_s
@val=s.to_i
end
def coerce(other)
[other,@val]
end
def <<(v)
return InterEx.new(@val) if v==0
InterEx.new(@val*10**v)
end
def >>(v)
return InterEx.new(@val) if v==0
s=self.to_s
s=s[0..(-1*v-1)]
InterEx.new(s.to_i)
end
def method_missing(mtd,*args)
InterEx.new(@val.send mtd,*args)
end
end
ruby还提供了delegate机制便于代理一个类,比如要想代理Fixnum类,
可以这么写:
require 'delegate'
class InterEx<DelegateClass(Fixnum)
...
end
相关文档:
The following is improved version of the code created by David Mullet, from
http://rubyonwindows.blogspot.com/2007/03/ruby-ado-and-sqlserver.html
require 'win32ole'
class SqlServer
# This class manages database connection and queries
attr_accessor :connection, :data, :fields
attr_wr ......
1,安装ruby
下载地址: http://rubyinstaller.org/download.html
2,安装rails
使用命令下载:在命令行运行gem install rails --remote
2,初步了解ruby的文章
http://www.bcbbs.net/html/29671.html
http://www.bcbbs.net/dev/List64.aspx ......
转自 http://www.advidea.cn/biancheng/200943135232.html
Ruby watir 测试框架
大多数人都会安装 ruby,
也通过Ruby 安装 gem,
也安装了ruby IDE开发工具:netbeans,
但就是不能跑watir环境,狂晕加吐中。。。
错误如下:
in `require': no such file to load -- watir (LoadError)
反正就是找不到watir,这里 ......
安装环境:
OS:Windows XP
Ruby: Ruby1.9.1
Mysql: Mysql5.1.46 (username/password: root/root port:3306)
Ruby-Mysql Driver: mysql-2.8.1-x86-mswin32.gem
(注:用2.7.3版本的驱动在测试时会出现 require"mysql",找不到指定模块 错误)
IDE:RubyMine2.0.1
安装Ruby,RubyMine,Mysql的事项在这里就不多 ......