ruby Ï̵߳ÄÐÔÄܲâÊÔ
ÔÚʹÓÃÖÐrubyµÄ¹ý³ÌÖÐÄÑÃâ»áÓöµ½Ìá¸ßÐÔÄܵÄÎÊÌ⣬Óɴ˱ãÏëÆðÁËrubyÏ̡߳£µ«ÊÇÎÒÔÚʹÓÃÖÐÈ´·¢ÏÖrubyµÄÏß³ÌÈ´²»ÄÜÌá¸ßÐÔÄÜ¡£ÎÒдÁËÒÔÏ´úÂ룬×öÁËЩ¼òµ¥²âÊÔ¡£
´úÂë
# -*- coding: GB2312 -*-
require 'date'
# ʹÓÃỊ̈߳¬Ï̵߳Ĵ¦Àí´úÂëÀïûÓÐsleep
def have_thread_no_sleep
p Time.now
thread1 = Thread.new do
a = 0
20000.times do |v|
a = DateTime.parse('1993-02-24T12:30:45')
end
p a
end
thread2 = Thread.new do
a = 0
10000.times do |v|
a = DateTime.parse('1993-02-25T12:30:45')
end
p a
end
thread = [thread1,thread2]
thread.each {|t| t.join }
p Time.now
end
# ûÓÐʹÓÃỊ̈߳¬Ï̵߳Ĵ¦Àí´úÂëÀïûÓÐsleep
def no_thread_no_sleep
p Time.now
a = 0
20000.times do |v|
a = DateTime.parse('1993-02-24T12:30:45')
end
p a
a = 0
10000.times do |v|
a = DateTime.parse('1993-02-25T12:30:45')
end
p a
p Time.now
end
# ʹÓÃỊ̈߳¬Ï̵߳Ĵ¦Àí´úÂëÀïÓÐsleep
def have_thread_have_sleep
p Time.now
thread1 = Thread.new do
a = 1 + 2
sleep 3
p a
end
thread2 = Thread.new do
a = 0
a = 1 + 2
sleep 2
p a
end
thread = [thread1,thread2]
thread.each {|t| t.join }
p Time.now
end
# ûÓÐʹÓÃỊ̈߳¬Ï̵߳Ĵ¦Àí´úÂëÀïÓÐsleep
def no_thread_have_sleep
p Time.now
a = 1 + 2
sleep 3
p a
a = 0
a = 1 + 2
sleep 2
p a
p Time.now
end
p "ûÓÐʹÓÃỊ̈߳¬Ï̵߳Ĵ¦Àí´úÂëÀïûÓÐsleep"
no_thread_no_sleep
p "ʹÓÃỊ̈߳¬Ï̵߳Ĵ¦Àí´úÂëÀïûÓÐsleep"
have_thread_no_sleep
p "ʹÓÃỊ̈߳¬Ï̵߳Ĵ¦Àí´úÂëÀïÓÐsleep"
have_thread_have_sleep
p "ûÓÐʹÓÃỊ̈߳¬Ï̵߳Ĵ¦Àí´úÂëÀïÓÐsleep"
no_thread_have_sleep
²âÊÔ½á¹ûÈçÏÂ
"ûÓÐʹÓÃỊ̈߳¬Ï̵߳Ĵ¦Àí´úÂëÀïûÓÐsleep" -> 24Ãë
2009-12-02 23:03:11 +0800
#<DateTime: 1993-02-24T12:30:45+00:00 (4702162601/1920,0/1,2299161)>
#<DateTime: 1993-02-25T12:30:45+00:00 (4702164521/1920,0/1,2299161)>
2009-12-02 23:03:35 +0800
"ʹÓÃỊ̈߳¬Ï̵߳Ĵ¦Àí´úÂëÀïûÓÐsleep" -> 26Ãë
2009-12-02 23:03:35 +0800
#<DateTime: 1993-02-2
Ïà¹ØÎĵµ£º
#include < ruby.h > //
static int id_sum;
int Values[] = {5, 10 ,15,-1,20,0};
static VALUE wrap_sum(VALUE args)
{
VALUE * values = (VALUE *) args;
VALUE summer = values[0];
VALUE max = values[1];
return rb_funcall(summer,id_sum,1,max);
}
static VALUE ......
¶©µ¥´¦Öã¬Ê×ÏÈÒªÓÐÒ»¸ö¶©µ¥µÄÏêϸÁÐ±í£¨°üÀ¨ÊýÁ¿£¬¼ÛǮɶµÄ£©ºÍÒ»¸ö¶ÔÓÚ¸öÈ˵ÄһЩÐÅÏ¢µÄÒ»¸ö±í¡£Òò¶øÎÒÃÇ´´ÔìÁ½¸öÄ£ÐÍ£¬line_item(ÁбíÏî),order(Áбí)£¬Æäºó±àÕßÈç´Î
/db/migrate xxx_create_order xxx_line_item
Ruby´úÂë
Ò».class CreateOrders < ActiveRecord::Migration
¶þ.def self.up
3. create_tabl ......
¹«Ë¾ÀïÔ½À´Ô½¶àµÄ½Ó¿ÚÒÔICE·½Ê½ÌṩÁË£¬ÒÔǰû½Ó´¥¹ý£¬ËùÒÔÎÒÕâÁ½ÌìÒ²³éÁ˵ãʱ¼äÑо¿ÁËÏÂICE£¬²Î¿¼ÁËÍøÉϺܶàÌû×Ó£¬²ÅÖÕÓÚÅÜͨµÚÒ»¸ö¼òµ¥µÄICE
½ÓÏÂÀ´ÌùÉÏÎÒËùÓл·¾³µÄ´î½¨¹ý³ÌÒÔ¼°´úÂ룬ºÍ´ó¼Ò·ÖÏíÏÂICEËù´øÀ´µÄ¿ìÀÖ
ICEÊÇʲôÎҾͲ»¶à˵ÁË
1¡¢ Ò»¿î¸ßÐÔÄܵÄÖмä¼þ£¬»ùÓÚICE¿ÉÒÔʵÏÖµçÐż¶µÄ½ ......
1.install ruby
download from http://www.ruby-lang.org/en/news/2009/12/07/ruby-1-9-1-p376-is-released/
2.install rails
ruby gem install rails --include-dependencies
3.install mysql
download from http://sourceforge.net
ruby gem install&nb ......
Ëɱ¾ÐкêÈçÔ¼ÓÚÊ¥µ®½Ú·¢²¼ÁËRuby 1.9¡£¸ù¾ÝRubyµÄ¹ßÀý£¬Ð¡ÊýµãºóÃæµÚһλÈç¹ûÊǵ¥Êý£¬ÄÇô¾Í±íÃ÷ÕâÊÇÒ»¸öʵÑé°æ±¾£¬²»ÍƼöÓÃÓÚ²úÆ·»·¾³¡£Ëùν“²úÆ·»·¾³”£¬¶ÔÓÚÄ¿Ç°µÄRubyÀ´Ëµ£¬»ù±¾ÉϾÍÊÇRuby on Rails¡£´ÓÄ¿Ç°RoRÉçȺµÄ·´Ó³À´¿´£¬È·ÊµÓÐÈËÕýÔÚ³¢ÊÔÓÃRuby 1.9ÅäºÏRoR£¬µ«ÊÇÉÐÊô ......