Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

RubyÓïÑÔѧϰϵÁÐ »ù±¾µÄrubyÓï·¨


RubyÓïÑÔѧϰϵÁÐ--»ù±¾µÄrubyÓï·¨
 
1.     »ù±¾µÄrubyÓï·¨
1.1      ±äÁ¿¡¢³£Á¿ºÍÀàÐÍ
1)      ¶¨Òå±äÁ¿
±äÁ¿ÀàÐÍ
ÃèÊö
ʾÀý
¾Ö²¿±äÁ¿£¨»òα±äÁ¿£©
ÒÔСд×Öĸ»òÏ»®Ïß¿¨Í·
var    _var
È«¾Ö±äÁ¿
ÒÔ$¿ªÍ·
$var
Àà±äÁ¿
ÀàÖж¨Ò壬ÒÔ@@¿ªÍ·
@@var
ʵÀý±äÁ¿
¶ÔÏóÖж¨Ò壬ÒÔ@¿ªÍ·
@var
³£Á¿
ÒÔ´óд×Öĸ¿ªÍ·
Var
2) ±äÁ¿ÄÚ²å
  ÔÚË«ÒýºÅÄÚʹÓÓ#{±äÁ¿Ãû}”ÄÚ²å±äÁ¿
a = 2
b = 3
puts "#{a} + #{b} = #{a+b}"  #ÊäÈë½á¹ûΪ£º2 + 3 = 5
 
1.2      ×¢ÊÍ
1£©µ¥ÐÐ×¢ÊÍ£ºÒÔ#¿ªÍ·£¬È磺 #×¢ÊÍÄÚÈÝ
2£©¶àÐÐ×¢ÊÍ£ºÔÚ=begin ºÍ =end Ö®¼ä¶¨Ò壬È磺
=begin
×¢ÊÍÄÚÈÝ
=end
1.3    Ñ­»·ºÍ·ÖÖ§
1.3.1        Ìõ¼þÓï¾ä
If ÐÎʽ
unless ÐÎʽ
a =1 if y==3
a=1 unless y!=3
x= if a > 0 then b else c end
x= unless a<=0 then a else b end
 if x<5 then
  a =1
else
   a =2
end
unless x<5 then
   a =2
else
   a =1
end
 
1.3.2        Ñ­»·½á¹¹
#whileÑ­»·
i= 0
while i< list.size do
print “#list[i] ”
I += 1
end
#untilÑ­»·
i= 0
until i == list.size do
print “#list[i]”
i += 1
end
#forÑ­»·
for x in lisy do
 print “#{x}”
end
#eachÑ­»·
list.each do |x|
 print “#{x}”
end
#loopÑ­»·
i = 0
n = list.size-1
loop do
print “#{list[i]}”
i += 1
break id i > n
end
#timesÑ­»·
n = list.size
n.times do |i|
 print “#{list[i]}”
end
#uptoÑ­»·
n =list.size–1
0.upto(n) do |i|
 print “#{list[i]}”
end
#each_indexÑ­»·
list.each_index do |x|
 print “#{list[x]}”
end
 
1.3.3        Òì³£
begin
    x = Math.sqrt(y/z)       
rescue ArgumentError   


Ïà¹ØÎĵµ£º

rubyËæ»úÔÚ¿ØÖÆÌ¨ÏÔʾ×Ö·û´®

require 'curses'
module Curses
def self.program
main_scr=init_screen
noecho
cbreak
curs_set(0)
main_scr.keypad=true
yield main_scr
end
end
Curses.program do |scr|
max_x=scr.maxx
max_y=scr.maxy
100.times do
scr.setpos(rand(max_y),rand(max_x))
......

RUBYʵ¼ù—´øÃÜÂë¼ÓÃܵÄÓû§´´½¨¼°ÐÞ¸Ä

¿ª·¢»·¾³
Ruby: Ruby1.9.1
Rails: Rails2.3.5
Mysql:Mysql5.0.9
Driver:mysql-2.8.1-x86-mingw32.gem
IDE:Rubymine2.0.1
Ò»¡¢´´½¨Êý¾Ý±íUsers
ÀûÓÃRubyMine×Ô´øµÄScaffold¹¤¾ß´´½¨Êý¾Ý±íUsers£¬Ò²¿ÉÒÔÊÖ¶¯´´½¨
¶þ¡¢´´½¨ControllerºÍView
RubyÏîÄ¿—>ÓÒ¼ü—>Create Model
Íê³Éºó½«×Ô¶¯Éú³ÉÏàÓ¦µÄÎ ......

Use lambda in Ruby ¾ÅͲһÌõ

http://www.robertsosinski.com/2008/12/21/understanding-ruby-blocks-procs-and-lambdas/
Understanding Ruby Blocks, Procs and Lambdas
Blocks, Procs and lambdas (referred to as closures
in Computer Science) are one of the most powerful aspects of Ruby, and
also one of the most misunderstood. This ......

RubyÖÐ%µÄÓ÷¨(°Ù·ÖºÅµÄÓ÷¨)

%{String}  ÓÃÓÚ´´½¨Ò»¸öʹÓÃË«ÒýºÅÀ¨ÆðÀ´µÄ×Ö·û´® 
%Q{String} ÓÃÓÚ´´½¨Ò»¸öʹÓÃË«ÒýºÅÀ¨ÆðÀ´µÄ×Ö·û´® 
%Q!Some String of “Characters”! <==> ” Some String of \”Characters\” “
%q{String} ÓÃÓÚ´´½¨Ò»¸öʹÓõ¥ÒýºÅÀ¨ÆðÀ´µÄ×Ö·û´® 
%q!Som ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ