易截截图软件、单文件、免安装、纯绿色、仅160KB

写的一个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



相关文档:

ruby 连接操作 sql2005


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 ......

ruby on rails


rubygems
Ruby on Rails 是一个可以使你开发,部署,维护 web 应用程序变得简单的框架。
  Ruby的作者于1993年2月24日开始编写Ruby,直至1995年12月才正式公开发布于fj(新闻组)。之所以称为Ruby,是因为Perl的发音与6月的诞生石pearl(珍珠)相同,因此Ruby以7月的诞生石ruby(红宝石)命名。rails在英文中是栏杆的 ......

Ruby watir 测试框架

转自 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,这里 ......

ruby的类与模块(1)

class Point
@x = 1
@y = 2
def initialize(x,y)
@x,@y = x,y
end
end 
代码中的@x,@y为实例变量,实例变量只对self的环境起作用,因此initialize外面的@x=1,@y=2只对类本身起作用,而方法内部,的@x,@y是对对象的实例起作用的。
class Point
include Enumerable
def initialize(x ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号