Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB
ÈÈÃűêÇ©£º c c# c++ asp asp.net linux php jsp java vb Python Ruby mysql sql access Sqlite sqlserver delphi javascript Oracle ajax wap mssql html css flash flex dreamweaver xml
 ×îÐÂÎÄÕ : Ruby

×Ô¶¯»¯²âÊÔ֮·£¨Ò»£© ruby³õ̽

´Ó½ñÌìÆð²»ÔÙÀË·Ñʱ¼ä£¬¿ªÊ¼×ßÏò×Ô¶¯»¯²âÊÔÕâÌõ¹âÃ÷µÄµÀ·£¬²¢ÒԴһ¸ö×Ô¶¯»¯²âÊÔƽ̨ΪĿ±ê£¬²¢Õâ¸ö¹ý³ÌÒ»µãµãµÄ¼Ç¼ÏÂÀ´ºÍ´ó¼Ò·ÖÏí
Ê×ÏÈ£¬ÊÇruby»·¾³µÄ´î½¨
£¨1£©µ½rubyµÄ¹ÙÍø£ºhttp://www.ruby-lang.org/en/ÏÂÔØ ruby°²×°³ÌÐò;
      PS £ºÑ¡Ôñ ruby on windows,ÎÒÏÂÔصÄÊÇRuby 1.8.6 One-Click Installer
£¨2£©Ë«»÷ºó°²×°ruby£¬Ò»Â·next£¬È»ºófinish¾ÍÐУ¬Ä¬ÈÏ°²×°ÔÚcÅÌ
£¨3£©½øÈ뿪ʼ²Ëµ¥->ÔËÐÐ->cmd ÊäÈëruby -v²é¿´µ±Ç°µÄrubyµÄ°æ±¾ºÅ£¬ÀýÈçÎҵĻáÏÔʾ ruby 1.8.6
È»ºó£¬ÎÒÃÇÀ´³¢ÊÔÔËÐÐÒ»¸örubyµÄС³ÌÐò
£¨1£©½øÈ뿪ʼ²Ëµ¥->ÔËÐÐ->cmd ÊäÈëruby -e 'print "Ruby,I am Coming!"'
       ÆÁÄ»»áÏÔʾ £º Ruby£¬I am Coming!
       PS :ruby µÄº¬ÒåÊǸæËßϵͳ£¬ÎÒÒªÔËÐÐÒ»¸öruby³ÌÐòÁË
              -e   µÄº¬ÒåÊǸæËßϵͳ£¬°ïÎÒºóÃæµÄÒ»Ðе±×÷Ò»¸öruby½Å±¾À´ÔËÐÐ ......

Rails¡¢Ruby¡¢JAVAÇ°¾°±È½Ï

        ÔÚÂÛ̳Àï¿´ÁËdaquan198163ËùдµÄ¡¶³õѧRORµÄÒÉ»ó¡·ÕâƪÎÄÕ£¬robbinÔڻظ´ÖиøÁËÏêϸµÄ½â´ð£¬¿ÉÊÇ¿´Íê½â´ðÖ®ºó£¬ÎÒÒ²²úÉúÁËһЩÒÉ»ó£¬ÔÚ´ËÏëÎÊÎÊ¡£
        ÔÚrobbinËù¸ø³öµÄ½â´ðµ±ÖУ¬¸ü¶àµÄÊDzûÊörailsµÄºÃ´¦£¬È»¶ø´ó¼Ò¶¼ÖªµÀ£¬railsÖ»ÊÇÒ»ÖÖÓÃÀ´¿ìËÙ¿ª·¢µÄ¿ò¼Ü£¬¶øRubyÖ®ËùÒÔÈç´Ë»ðºì£¬´ó²¿·ÖÔ­ÒòÊÇÒòΪrails£¬Õâµã²»¿É·ñÈÏ£¬µ«ÊǶÔÓÚRORµÄδÀ´£¬ÎÒʼÖÕÓÐËù»³ÒÉ£¬¼ÈÈ»railsÊÇ¿ò¼Ü£¬Äǵ±ÆäËûÓïÑÔʵÏÖÁËÀàËƵĿò¼ÜÖ®ºó£¨ÏÖÔÚÒѾ­ÓÐÀàËƵĿò¼Ü£¬µ«ÈÔȻδ³ÉÊ죩£¬RORµÄδÀ´ÓÖÈçºÎÄØ£¿Ä¿Ç°RORµÄÓÅÊÆÖ÷ÒªÔÚÓÚ¿ìÈËÒ»²½£¬¶øRubyÓïÑÔ±¾Éí£¬ÔÚÓïÑÔÐÔÄÜÉÏÈ´ÊDz»¼°ÆäËûÓïÑÔ£¬Ò²Ðíµ±Ruby2.0Õýʽ³ö°æºó£¬Í¨¹ýYARV¿ÉÄܶÔÐÔÄÜÓÐÒ»¸öºÜ´óµÄÌáÉý£¬µ«ÊÇÏàÐÅÒ²½ö½öÊǺÍÆäËû¶¯Ì¬ÓïÑÔÏà±È£¬ÓëJAVAÖ®ÀàµÄ¾²Ì¬ÓïÑÔ¿ÉÄÜÈÔÈ»Óвî¾à¡£Äǵ±JAVA³öÏÖÁËÒ»¸ö±Èrails¸üÍêÉƵĿò¼ÜµÄʱºò£¬RORÓÖ¸ÃÈçºÎÄØ£¿ÔÚ¸ÃÎÄÕµĻظ´ÖУ¬robbin˵¹ý“ÓÉÓÚ±à³ÌÓïÑÔÄÚÔÚ²îÒ죬JavaÔÙ¼ò»¯Ò²¼ò»¯²»µ½railsµÄ³Ì¶È¡£”£¬µ«ÊÇÄã²»ÒªÍü¼Ç£¬ÕýÒòΪ¶¯Ì¬ÓïÑÔ ¾ßÓÐJAVAËùûÓеÄÓÅÊÆ£¬JAVAÔÚеİ汾ÖÐÒ²ÒѾ­ÕûºÏÁ˶¯Ì¬ÓïÑÔ£¬Õâ¸öÎÊÌâÔÚδÀ ......

Rails¡¢Ruby¡¢JAVAÇ°¾°±È½Ï

        ÔÚÂÛ̳Àï¿´ÁËdaquan198163ËùдµÄ¡¶³õѧRORµÄÒÉ»ó¡·ÕâƪÎÄÕ£¬robbinÔڻظ´ÖиøÁËÏêϸµÄ½â´ð£¬¿ÉÊÇ¿´Íê½â´ðÖ®ºó£¬ÎÒÒ²²úÉúÁËһЩÒÉ»ó£¬ÔÚ´ËÏëÎÊÎÊ¡£
        ÔÚrobbinËù¸ø³öµÄ½â´ðµ±ÖУ¬¸ü¶àµÄÊDzûÊörailsµÄºÃ´¦£¬È»¶ø´ó¼Ò¶¼ÖªµÀ£¬railsÖ»ÊÇÒ»ÖÖÓÃÀ´¿ìËÙ¿ª·¢µÄ¿ò¼Ü£¬¶øRubyÖ®ËùÒÔÈç´Ë»ðºì£¬´ó²¿·ÖÔ­ÒòÊÇÒòΪrails£¬Õâµã²»¿É·ñÈÏ£¬µ«ÊǶÔÓÚRORµÄδÀ´£¬ÎÒʼÖÕÓÐËù»³ÒÉ£¬¼ÈÈ»railsÊÇ¿ò¼Ü£¬Äǵ±ÆäËûÓïÑÔʵÏÖÁËÀàËƵĿò¼ÜÖ®ºó£¨ÏÖÔÚÒѾ­ÓÐÀàËƵĿò¼Ü£¬µ«ÈÔȻδ³ÉÊ죩£¬RORµÄδÀ´ÓÖÈçºÎÄØ£¿Ä¿Ç°RORµÄÓÅÊÆÖ÷ÒªÔÚÓÚ¿ìÈËÒ»²½£¬¶øRubyÓïÑÔ±¾Éí£¬ÔÚÓïÑÔÐÔÄÜÉÏÈ´ÊDz»¼°ÆäËûÓïÑÔ£¬Ò²Ðíµ±Ruby2.0Õýʽ³ö°æºó£¬Í¨¹ýYARV¿ÉÄܶÔÐÔÄÜÓÐÒ»¸öºÜ´óµÄÌáÉý£¬µ«ÊÇÏàÐÅÒ²½ö½öÊǺÍÆäËû¶¯Ì¬ÓïÑÔÏà±È£¬ÓëJAVAÖ®ÀàµÄ¾²Ì¬ÓïÑÔ¿ÉÄÜÈÔÈ»Óвî¾à¡£Äǵ±JAVA³öÏÖÁËÒ»¸ö±Èrails¸üÍêÉƵĿò¼ÜµÄʱºò£¬RORÓÖ¸ÃÈçºÎÄØ£¿ÔÚ¸ÃÎÄÕµĻظ´ÖУ¬robbin˵¹ý“ÓÉÓÚ±à³ÌÓïÑÔÄÚÔÚ²îÒ죬JavaÔÙ¼ò»¯Ò²¼ò»¯²»µ½railsµÄ³Ì¶È¡£”£¬µ«ÊÇÄã²»ÒªÍü¼Ç£¬ÕýÒòΪ¶¯Ì¬ÓïÑÔ ¾ßÓÐJAVAËùûÓеÄÓÅÊÆ£¬JAVAÔÚеİ汾ÖÐÒ²ÒѾ­ÕûºÏÁ˶¯Ì¬ÓïÑÔ£¬Õâ¸öÎÊÌâÔÚδÀ ......

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

Éè¼Æģʽ ¹Û²ìÕßģʽʵÏÖÀý×Ó(ruby)

rubyÖÐ×Ô´øʵÏÖ¹Û²ìÕßģʽµÄÀàobserver¡£¿ÉÒÔÀûÓÃËüÀ´ÊµÏÖ¹Û²ìÕßģʽ¡£
´úÂëÀý×Ó£º
# -*- coding: GB2312 -*-
require 'observer'
# ¹Û²ìÕßģʽ(ruby)µÄʹÓÃÀý×Ó
# ±»¹Û²ìÕßP
class PObservable
include Observable
end
# ¹Û²ìÕßA
class AObserver
# update·½·¨ÃûÊDZØÐëµÄÒªÓеÄ
def update(arg)
puts "AObserver ±»Í¨ÖªÁË " + arg
end
end
# ¹Û²ìÕßB
class BObserver
# update·½·¨ÃûÊDZØÐëµÄÒªÓеÄ
def update(arg)
puts "BObserver ±»Í¨ÖªÁË " + arg
end
end
# ¹Û²ìÕß³õʼ»¯
observer_a = AObserver.new
observer_b = BObserver.new
# ±»¹Û²ìÕß³õʼ»¯
obj = PObservable.new
# Ìí¼Ó¼àÊÓ¶ÔÏó
obj.add_observer(observer_a)
obj.add_observer(observer_b)
# ±»¹Û²ìÕ߸ıäÁË ->Õâ¶Î´úÂë ±ØÐëÓÐ ²»È»ÎÞ·¨Í¨Öªµ½¹Û²ìÕß
obj.changed
# ֪ͨ¹Û²ìÕß
obj.notify_observers("Test")

Êä³ö½á¹û£º
AObserver ±»Í¨ÖªÁË Test
BObserver ±»Í¨ÖªÁË Test ......

Çø±ðRubyµÄrequire,load,ºÍinclude


ÈýÕßÖ®¼äÇø±ð²¢²»ÏñÄãÏëµÄÄÇôÄÑ£¬Ò²²»»áÏñÓÐЩÎÄÕÂдµÄÄÇô³¤¡£Í¦¼òµ¥µÄ¡£
Ïà֮ͬ´¦£ºÈýÕß¾ùÔÚkernelÖж¨ÒåµÄ£¬¾ùº¬Óаüº¬½øijÎïÖ®Òâ¡£
²»Í¬Ö®´¦£º
1¡¢requre,loadÓÃÓÚÎļþ£¬Èç.rbµÈµÈ½áβµÄÎļþ¡£
2¡¢includeÔòÓÃÓÚ°üº¬Ò»¸öÎļþ(.rbµÈ½áβµÄÎļþ)ÖеÄÄ£¿é¡£
3¡¢requreÒ»°ãÇé¿öÏÂÓÃÓÚ¼ÓÔØ¿âÎļþ£¬¶øloadÔòÓÃÓÚ¼ÓÔØÅäÖÃÎļþ¡£
4¡¢requre¼ÓÔØÒ»´Î£¬load¿É¼ÓÔضà´Î¡£
ÔõôÑù£¬¼òµ¥°É£¡ÔÙ¿´¸öÀý×Ó¡£
Èç¹û˵abc.rbÖаüº¬Ò»¸öÄ£¿éMa£¬ºÍ¼¸¸öÀàCa,CbµÈµÈ¡£ÄÇôÄãÈôÏëÔÚef.rbÎļþÖÐʹÓÃabc.rbÖеÄ×ÊÔ´£¬ÄãµÃÕâÑù:
require 'abc.rb'
Èô»¹ÏëÔÚef.rbµÄij¸öÀàÖÐʹÓÃabc.rbÖеÄÄ£¿é£¬ÔòÓ¦ÔÚÕâ¸öÀàÖмÓÈë
include Ma
Èç¹ûÄãÖ»ÏëÔÚef.rbÎļþµÄij¸öÀàÖÐʹÓÃabc.rbµÄÄ£¿é£¬ÄãµÃÕâÑù£º
require 'abc.rb'
include Ma
ÕâÁ½¾ä¾Í¸æËßÁËÄãËüÃÇÇø±ð¡£
ÏÂÃ沿·ÖÕª×ÔÓÚ£ºhttp://anw.stikipad.com/ocean/show/require+load+and+include
Ruby ÖÐ “require”, “load” ºÍ “include” ÓÐÉõ麼²»Í¬ÄØ? “require” ºÍ “load” ÓÃ;ÊÇÒ»ÖµÄ, ÓÃ來載ÈëеijÌʽ庫, “include” ÊÇÓÃ來 mix- ......

×Ô¶¯»¯²âÊÔ֮·£¨Èý£© rubyÀïµÄgetÓëset·½·¨

ÕÕÀý¿ÉÒÔÏÈ¿´¶Ë³ÌÐò
class Person
 
  def initialize( name,age=18 )
    @name = name
    @age = age
    @motherland = "China"
  end
 
  def talk
    puts "my name is "+@name+", age is "+@age.to_s
    if  @motherland == "China"
      puts "I\'m Chinese."
    else
      puts "I\'m foreigner."
    end
  end
 
  attr_writer :motherland
 
end
p1=Person.new("kaichuan",20)
p1.talk
p2=Person.new("Ben")
p2.motherland="ABC"
p2.talk
³ÌÐòÔËÐнá¹û
 my name is kaichuan, age is 20
I'm Chinese.
my name is Ben, age is 18
I'm foreigner.
>Exit code: 0
ÓйýÃæÏò¶ÔÏó±à³ÌÓïÑÔ¾­ÀúµÄͯЬºÜÈÝÒ׿ÉÒÔ¿´Ã÷°×£¬µ«ÊÇÀïÃæÖµµÄÒ»ÌáµÄÊÇÕâ¾ä£º“attr_writer :motherland”
Õâ¾ä»°Ï൱ÓÚÎÒÃÇÃæÏò¶ÔÏó±à³ÌÓïÑÔµÄset·½·¨£¬Ò²¿ÉÒÔÕâÑùд
def motherland=(value)
   return ......
×ܼǼÊý:146; ×ÜÒ³Êý:25; ÿҳ6 Ìõ; Ê×Ò³ ÉÏÒ»Ò³ [11] [12] [13] [14] 15 [16] [17] [18] [19] [20]  ÏÂÒ»Ò³ βҳ
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ