Óà Ruby ²È²ÈËÄÈË°ï
ÉÏÉÏÖÜÔÚÊéµê¿´µ½Ò»±¾¡¶Ruby
Éè¼Æģʽ¡·£¬¼ñÆðÀ´ 10 ·ÖÖÓ¿´Í꣬ÈÓÁË£¨±ðÎÊÎÒΪʲô……£©
ÏÂÃæÓÃ Ruby
ддÉè¼Æģʽ£¬Ë³±ãÅúÒ»Åú Java ºÍ Gof
¡£
1.Factory
ºÍ Abstract Factory
class
Factory
attr_accessor :product
def
produce
@product
.new
end
end
class
Product
#..
end
fac = Factory.new
fac.product = Product
fac.produce
class Factory
attr_accessor :product
def produce
@product.new
end
end
class Product
#..
end
fac = Factory.new
fac.product = Product
fac.produce
JavaдµÄ¹¤³§ÓÐÕâô¼òµ¥£¬ÕâôÈÝÒ×ÖØÓÃô£¿
2.Builder
# ¹¤Í·
class
Director
def
build_with builder
acc = ''
[:header
, :body
, :footer
].each
do
|m|
acc += builder.__send__ m if
builder.respond_to? m
end
acc
end
end
# ¹¤ÈË
class
HTMLBuilder
def
header; '<html><title>html builder</title>'
;end
def
body; '<body>html builder</body>'
;end
def
footer; '</html>'
;end
end
Ïà¹ØÎĵµ£º
http://zh.wikipedia.org/wiki/WxWidgets ÖÐÎĵÄ
http://zh.wikipedia.org/zh-cn/WxWidgets ¼òÌåÖÐÎÄ
http://wxruby.rubyforge.org/wiki/wiki.pl?Using_GUI_Designers
http://visualwx.altervista.org/ RAD http://www.wxwidgets.org/
http://wiki.wxwidgets.org/Main_Page ......
SOAP ·þÎñ¶Ë£º
#!/usr/local/bin/ruby
require 'soap/rpc/standaloneServer'
module MySOAP
class Timer
def now
Time.new.strftime("%Y-%m-%d %H:%M:%S")
end
end
class Add
def add(i, j)
return i.to_i + j.to_i
&nb ......
Ò»¡¢ÀàµÄ¶¨Òå¡¢ÀàµÄʵÀý·½·¨ ¶þ¡¢Ìض¨¶ÔÏóµÄ·½·¨ ÔÚRubyÀÎÒÃÇ¿ÉÒÔΪһ¸ö¶ÔÏ󵥶À¶¨Òå·½·¨ Èý¡¢Öض¨Òå·½·¨ ´ÓÏÂÃæ´úÂë¿ÉÒÔ¿´³ö£¬ºóÃæµÄ¶¨Òå»á¸²¸ÇÇ°ÃæµÄ¶¨Òå ËÄ¡¢ÖØдò¿ªÀà RubyÀïÎÒÃÇ¿ÉÒÔÔÙ´ò¿ªÒ»¸öÀ࣬ÏòÕâÀàÌí¼Ó·½·¨£¬ÓеãÏñC#ÀïµÄ·Ö²¿À࣬µ«²»ÓüÓÌرð±ê¼Ç. ÎÒÃÇÒ»°ã²»Òª²ð¿ªÀàµÄ¶¨Ò壬ÒòΪÄÇÑù²»ºÃÀí½ ......
ÓÃrubyн¨Ò»¸öexcelÎļþ£¬²¢ÇÒÉèÖÃһЩֵ¡£
require 'win32ole'
excel = WIN32OLE.new("excel.application")
excel.Visible = true
excel.WorkBooks.Open("d:\\test.xls")
excel.WorkSheets("sheet1").Activate
excel.Cells(2,3).value = "ÕÅÈý"
exce ......
def delVss(path)
if File.directory?(path)
for f in d = Dir.open(path)
fpath = File.join(path, f)
if(f!="."&&f!="..")
......