Ruby¿ìËÙÈëÃÅ£¨¶þ£©£º±äÁ¿
ÉÏһƪÎÄÕÂ
˵ÁËRubyµÄ°²×°ºÍÔËÐУ¬Ò²¼òµ¥µÄ˵ÁËÏÂÀàºÍ¶ÔÏó¡£ÕâÀïÖ÷Ҫ̸̸±äÁ¿µÄÎÊÌâ¡£
ÏÈ˵³£Á¿
¡£Èç¹û±äÁ¿ÃûÒÔ´óд×Öĸ¿ªÍ·£¬¾Í±»ÊÓΪ³£Á¿£¬µ«Í¨³£ÊÇËùÓÐ×Öĸ¶¼´óд¡£µ«ºÍÆäËûÓïÑÔ²»Í¬£¬ÔÚRubyÖУ¬ÄãÈÔÈ»¿ÉÒԸı䳣Á¿µÄÖµ£¬µ±È»½âÊÍÆ÷»áÅ׳öÒ»¸ö¾¯¸æ£º
#! /usr/bin/ruby
CONSTANT = 1
print "#{CONSTANT}\n"
CONSTANT += 1
print "#{CONSTANT}\n"
Õâ¶Î´úÂ붨ÒåÁËÒ»¸öÃûΪCONSTANTµÄ³£Á¿£¬²¢³õʼ»¯Îª1¡£È»ºó¶ÔÆäµÄ¸Ä¶¯È´ÊDZ»ÔÊÐíµÄ£¬µ«½âÊÍÆ÷»áÅ׳öÒ»¸öÈçÏÂËùʾµÄ¾¯¸æ£º
./2.rb:4: warning: already initialized constant CONSTANT
ÏÖÔÚ¿ªÊ¼¿´±äÁ¿
¡£ÔÚRubyÖУ¬±äÁ¿¶¼ÊÇ“ÎÞÀàÐÍ”µÄ£¬²»ÓÃÖ¸¶¨Æä¾ßÌåÀàÐÍ£¬½âÊÍÆ÷»á¸ù¾ÝÆäÖµ×ÔÐÐÅжϡ£µ«RubyÒ²ÌṩÁËһЩ·½·¨À´ÅжϱäÁ¿µÄµ±Ç°ÀàÐÍ£º
print "#{1.class}\n"
print "#{1.kind_of? Integer}\n"
µÚÒ»ÐдúÂë´òÓ¡±äÁ¿1µÄÀàÐÍ£¨»¹¼ÇµÃÔÚRubyÖУ¬Ò»Çж¼ÊǶÔÏó°É£¿£¡£©£¬µÚ¶þÐÐÔòÊÇ´òÓ¡1ÊÇ·ñÊÇIntegerµÄ½á¹û¡£
ͬʱ£¬Ruby»¹ÌṩÁËһЩº¯Êý½øÐбäÁ¿ÀàÐ͵Äת»»£¬ÈçÕûÊý¿Éµ÷ÓÃto_fº¯Êýת»¯Îª¸¡µãÊý¡¢µ÷ÓÃto_sº¯Êýת»¯Îª×Ö·û´®µÈµÈ¡£
ÏÖÔÚ¿´¿´±äÁ¿µÄ×÷ÓÃÓò
¡£
Ïà¹ØÎĵµ£º
×î½üÒ»¶Îʱ¼ä£¬ÔÚæºõ£ò£õ£â£ùµÄ²âÊÔ¿ò¼Ü¡£
´Ó²»ÊìϤBDD,RSpecµ½Ä¿Ç°Äܹ»ÉÔ΢×öµã¶«Î÷£¬¸Ð¾õ·Ç³£²»´í¡£
RubyÊÇÃŷdz£Áé»îµÄ½Å±¾ÓïÑÔ£¬´Ó¶øÒ²×ÔÈ»ÏëÓÃËü×÷Ϊ²âÊԽű¾¡£ÈÃÎÒÃDZàдµÄ´úÂë½øÈë£Ô£Ä£ÄµÄģʽ¡£
µ±È»£Ô£Ä£Ä¾¹ýÕâЩÄêµÄ·¢Õ¹£¬ÏÖÔÚÒѾ½øÈëBDD(Behaviour-Driven Develop)µÄʱ´ú¡£
BDDºÍTDDÖ÷ÒªµÄ× ......
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³ÌÐòÉè¼ÆµÄÖØÒª¹Ø¼ü¡£
²»¹ý£¬µü´úÆ÷ȷʵÓбȽϳéÏóµÄµØ·½£¬Óï·¨Ò²Óеã¹ÖÒ죨ÓÈÆäÊÇyieldµÄÓ÷¨£©£¬¹âÊÇÒÀ¿¿ÎÄ×Ö˵Ã÷¡¢¿´Ò»Á½¸öʾÀý£¬»¹ÊDz»Ì«ºÃ¶®¡£Æäʵ£¬µ±³õ±ÊÕß¿ªÊ¼Ñ§Ï°Rubyʱ¾Í¿¨ÔÚÕâÀºÜ¾Ã¶¼¸ã²»¶®¡£
ËùÒÔÔÚ± ......
Ò»¡¢ÀàµÄ¶¨Òå¡¢ÀàµÄʵÀý·½·¨ ¶þ¡¢Ìض¨¶ÔÏóµÄ·½·¨ ÔÚRubyÀÎÒÃÇ¿ÉÒÔΪһ¸ö¶ÔÏ󵥶À¶¨Òå·½·¨ Èý¡¢Öض¨Òå·½·¨ ´ÓÏÂÃæ´úÂë¿ÉÒÔ¿´³ö£¬ºóÃæµÄ¶¨Òå»á¸²¸ÇÇ°ÃæµÄ¶¨Òå ËÄ¡¢ÖØдò¿ªÀà RubyÀïÎÒÃÇ¿ÉÒÔÔÙ´ò¿ªÒ»¸öÀ࣬ÏòÕâÀàÌí¼Ó·½·¨£¬ÓеãÏñC#ÀïµÄ·Ö²¿À࣬µ«²»ÓüÓÌرð±ê¼Ç. ÎÒÃÇÒ»°ã²»Òª²ð¿ªÀàµÄ¶¨Ò壬ÒòΪÄÇÑù²»ºÃÀí½ ......
require 'win32ole'
fns = Dir.glob("*.xls")
application = WIN32OLE.new("excel.application")
application.visible = TRUE
f = File.new('errorCauseEN.xml','w')
f.puts('<?xml version="1.0" encoding="utf-8"?>')
f.puts('<!-- edited with XMLSPY v5 U (http://www.xmlspy.com) by et8 (et8) ......