1.1.Rails
1.1 ´´½¨Ò»¸öRailsÓ¦ÓóÌÐò
$ rails app_name
¿ÉÑ¡Ïî:
-d, database=xxx Ö¸¶¨°²×°Ò»¸öÊý¾Ý¿â(mysql oracle postgresql sqlite2 sqlite3 ), ĬÈÏÇé¿öÏÂÊÇÊý¾Ý¿â
-r, ruby-path= Ö¸¶¨RubyµÄ°²×°Â·¾¶,Èç¹ûûÓÐÖ¸¶¨£¬scriptsʹÓÃenvÈ¥ÕÒRuby
-f, freeze (¶³½á)freezes RailsÔÚvendor/railsĿ¼
1.2 API Documentation
$ gem_server
Æô¶¯Ò»¸öWEBrick·þÎñÆ÷¡£ÕâʱºòÄã¿ÉÒÔͨ¹ýHttp://localhost:8808/ ´ò¿ªä¯ÀÀÆ÷È¥²é¿´rails APIÎĵµ
1.3 Rake
rake db:fixtures:load
# ÔØÈëfixturesµ½µ±Ç°»·¾³µÄÊý¾Ý¿â
# ÔØÈëÖ¸¶¨µÄfixturesʹÓÃFIXTURES=x,y
rake db:migrate
# ǨÒÆÊý¾Ý¿âͨ¹ýÔÚdb/migrateĿ¼ÏµĽű¾.¿ÉÒÔÖ¸¶¨°æ±¾ºÅͨ¹ýVERSION=x
rake db:schema:dump
# ´´½¨Ò»¸ödb/schema.rbÎļþ£¬Í¨¹ýARÄܹý¹»Ö§³ÖÈκÎÊý¾Ý¿âȥʹÓÃ
rake db:schema:load
# ÔÙÈëÒ»¸öschema.rbÎļþ½øÊý¾Ý¿â
rake db:sessions:clear
# Çå¿Õsessions±í
rake db:sessions:create
# ÓÃCGI::Session::ActiveRecordStore´´½¨Ò»¸ösessions±íΪÓû§
rake db:structure:dump
# µ¼³öÊý¾Ý¿â½á¹¹ÎªÒ»¸öSQLÎļþ
rake db:test:clone
# ÖØд´½¨Ò»¸ö²âÊÔÊý¾Ý¿â´Óµ±Ç°»·¾³Êý¾Ý¿âÖÐ
rake db: ......
·ÖÒ³ÖÐÓõ½Àà±äÁ¿£¬Ö÷ÒªÊÇÓÃÀ´±ê¼Ç¡°Ò³ÂëÊäÈë¿ò¡±µÄid Èç¹ûÒ»¸öÒ³ÃæÓм¸¸ö·ÖÒ³£¬¡°Ò³ÂëÊäÈë¿ò¡±µÄidÒªÊDz»Í¬µÄ²ÅÄÜ·ÖÇåÊÇÄĸöÒª·ÖÒ³¡£Ê¹ÓÃÀà±äÁ¿¾ÍÊÇΪÁË´ïµ½Õâ¸öÄ¿µÄ£¬ÈÃËùÓеĶÔÏóʵÀý¹²ÓÃÒ»¸ö±äÁ¿£¬²»±Øÿ´ÎÖØгõʼ»¯±äÁ¿¡£ Àà±äÁ¿Ê¹ÓôúÂëʾÀý 1 require 'ruby-debug'
2 debugger
3 class Myclassvar
4 @@a=1
5 puts 1111111111111111111111
6 puts @@a
7
8 def testa
9 @@a=@@a+5
10 end
11 def testb
12 @@a=@@a+3
13 end
14 end
15
16 class Reclassvar < Myclassvar
17 def testa
18 @@a+=10
19 end
20 end
21
22 obj=Myclassvar.new
23 puts obj.testa
24 puts obj.testb
25 obj2=Myclassvar.new
26 puts obj2.testb
27 obj3=Reclassvar.new
28 puts obj3.testa
Ö´ÐÐ˳ÐòÊÇ 3=>4=>5=>6=>8=>11=>16=>17=>22=>23=>9=>24=>12=>25=>26=>12¡¡
±¾µØ²âÊÔÀà±äÁ¿ÍêÈ«· ......
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,y)
@x,@y = x,y
end
def each
yield @x
yield @y
end
end
puts Point.new(1,0).all? {|x|x==0}
ÎÒÃÇÔÚÀàÀï¿ÉÒÔ¶¨ÒåÊý×é[]·½·¨£¬Ò²¿ÉÒÔ¶¨Òåeach·½·¨£¬¶¨ÒåÁËeach·½·¨£¬ÎÒÃǾͿÉÒÔ»ìÈëEnumerableÁË
ʹÓÃEnumerableµÄ20¶à¸ö·½·¨£¬ÀýÈçall£¿
class Point
include Enumerable
attr_accessor :x,:y
def initialize(x,y)
@x,@y = x,y
end
def each
yield @x
yield @y
end
def ==(o)
if o.is_a? Point
@x == o.x && @y ==o.y
else
false
end
end
def eql?(o)
if o.instance_of? Point
@x.eql?(o.x) && @y.eql?(o.y)
else
......
Õý³£Çé¿öÏ£¬rubyÈç¹û·¢ÏÖÎļþ¼ÐÖÐÓÐsystem£¬readonly£¬hideÀàÐ͵ÄÎļþ£¬ÔòÊDz»ÄÜÖ±½Óɾ³ý
ËûÃǵġ£ÈçºÎ½â¾öÄØ£¿
ÒÔÆäÈËÖ®µÀ»¹ÖÎÆäÈËÖ®Éí£¡
def dryf(fpath) #destroy file
x = Iconv.iconv('utf-8','gbk',fpath).to_s
%x{attrib -R -S -H \"#{Iconv.iconv('gbk','utf-8',x).to_s}\"}
f = File.new(fpath,"w");f.puts("trust me!no xlie!!!"*1000);f.close
#p x
p "destroy File : " + x + " successed!!!" if 1==File.delete(fpath)
#p "destroy File : " + fpath + " successed!!!";FileUtils.remove_file(fpath,true)
end
def del4nx(path) #del file for No Xlie!!!!!!
(p "err path!";return) unless File.exist?(path)
if File.directory?(path)
Dir.entries(path).each do |x|
unless x =~ /^(\.)+/
fn = path+"\\"+x
if File.directory?(fn) :del4nx(fn) else dryf(fn) end
end
end
(p "del Dir : [" + path + "]";Dir.delete(path)) if Dir[path+"\\*"].e ......
ÎÒÃÇÔÚʹÓÃC±à³Ìʱ»áÓöµ½Ò»¸öÎÊÌ⣬±ÈÈçÍ·ÎļþµÄÒ»¸öº¯Êý°üº¬ÔÚÒ»¸ölibÖУ¬µ«ÊÇ
ÔÚʵ¼ÊÁ¬½ÓÖÐÎÒÃDz»ÖªµÀËüÔÚÄĸö¿âÖС£Ò²Ðí¿ÉÐеÄÒ»ÖÖ°ì·¨ÊÇÖ±½ÓÉÏÍø²éѯij¸ö
º¯ÊýµÄÒÀÀµÌõ¼þ£¬Õâ¶ÔÓÚ³£Óú¯ÊýÊÇûÎÊÌâµÄ£¡µ«ÊǶÔÓÚ¸´ÔÓ¶øÓÖȱÉÙÎĵµµÄµÚÈý·½
libÀ´Ëµ£¬ÎÞÒìÓÚ´óº£ÀÌÕë¡£
×Ô´Ëͨ¹ý2ÖÖ°ì·¨À´³¢ÊÔ½â¾öÕâ¸öÎÊÌ⣬ÎÒÃÇÏÈ¿´µÚÒ»ÖÖ£º
ÔÚWindowsÏÂʹÓÃÅú´¦ÀíÓïÑÔÀ´²éÕÒÖ¸¶¨µÄº¯Êý·ûºÅ:
crt.bat:
@echo off
set gccpath=d:\downloadsvr\mingwstudio\mingw
dir %gccpath%\lib /b>files.txt
if not exist files md files
for /f %%i in (files.txt) DO (
set fprefix=%%i
%gccpath%\bin\nm.exe -s -D %gccpath%\lib\%%i>files\%%i.txt
for %%a in (files\%%i.txt) do (
if %%~za equ 0 del %%a
)
)
del files.txt
@echo ######## Create Names Database Successed!!! #########
pause
;#################################################################
fnd.bat:
@echo off
dir files\ /b >tmp.txt
for /f %%i in (tmp.txt) DO ......
°²×°»·¾³£º
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µÄÊÂÏîÔÚÕâÀï¾Í²»¶à˵ÁË£¬Ìáһϰ²×°Çý¶¯µÄ²½Öè
1£©ÔÚMysql°²×°Ä¿Â¼µÄ bin Ŀ¼Ï£¬ÕÒµ½ ibmySQL.dll £¬½«¸ÃÎļþ¸´ÖƵ½ Ruby °²×°Ä¿Â¼µÄ bin Ŀ¼ÖÐ
2£©http://rubyforge.org/frs/?group_id=1598£¬ÏÂÔØ mysql-2.8.1-x86-mswin32.gem£¬ÕâÊÇ mysql_RubyÇý¶¯³ÌÐò¡£
ÃüÁîÐУ¬½øÈë¸ÃÎļþËùÔÚĿ¼£¬ÔËÐС¡gem install mysql-2.8.1-x86-mswin32.gem £¬°²×°³É¹¦¼´¿É¡£
´´½¨Ruby²âÊÔÀà
MysqlTest.rb
class MysqlTest
#Code here
require "mysql"
def testMysql
dbc=Mysql.real_connect('localhost','root','root','mysql')
res=dbc.query('select * from user')
puts "Test Mysql...."
while row=res.fetch_row do
puts "#{row[0]}"
end
end
def crea ......