Rubyѧϰ±Ê¼ÇÒ»——ÓïÑÔ»ù´¡
#Ò»¡¢ÕâÀïÊÇ×¢ÊÍ£¬Êǵ¥ÐÐ×¢ÊÍ£¬ÀàËÆÓÚ//
puts 3/5#ÕâÀïÊÇÕûÊýÐÎʽµÄ½á¹û
puts 3/5.0#ÕâÀïÊÇСÊýÐÎʽµÄ½á¹û
=begin
ÕâÊǶàÐÐ×¢ÊÍ£¬Êµ¼ÊÉÏÕâÒ²ÊÇRubyÄÚǶÎĵµ¸ñʽ£¬ÀàËÆÓÚJava doc
=end²»µ«ÒªÓÐÆðÖ¹£¬»¹ÒªËõ½ø²ÅÓÐÓá£
=end
#¶þ¡¢Á¬ÐÐ
puts "Hello Ruby!"; puts "This is a "\
"String";#ÐÐβµÄ·ÖºÅ¿ÉÒÔÊ¡ÂÔ?‘\’ÊÇÁ¬Ðзû£¬ÐÐβ¼´Ä¬ÈÏΪһ¸öÓï¾äµÄ½áÊø£¬¿ÉÒÔûÓзֺţ¬Èç¹û²»Ï£ÍûËü½áÊøµ«Ïë»»ÐУ¬ÐèÒª¼ÓÁ¬Ðзû'\'ÇÒÖ®ºó²»ÄÜÔÙ¼ÓÐÐ×¢ÊÍ¡£
#Èý¡¢print,puts,printf
#puts¿ÉÒÔ¼Ó¶à¸ö²ÎÊýÔÚºóÃ棬ÿÊä³öÒ»¸ö²ÎÊý×Ô¶¯¼ÓÒ»¸ö»»Ðзû£¬¶øprint²»¼Ó»»Ðзû
puts "%d,%s",100,"string, hello!";
#ÓøñʽÂÀÊä³öÓеãÏñCÓïÑÔ·ç¸ñ,ÓÃprintf
printf "%d,%s",100,"string, hello!";
#ËÄ¡¢Ò»Ð©Ó﷨֪ʶ
#0¿ªÍ·±í8½øÖÆÊý£¬0x¿ªÍ·±í16½øÖÆÊý,0b¿ªÍ·±í¶þ½øÖÆ£¬µ¥ÒýºÅË«ÒýºÅ¶¼¿ÉÒý×Ö·û´®
#Ò»¸öÊý×éÖеÄÔªËØ¿ÉÒÔ»¥²»Ïàͬ£¬ÊÇÈõÀàÐÍÓïÑÔ
#Çø¼ä£º1..5±í1£¬2£¬3£¬4£¬5¡£1...5±íʾ1£¬2£¬3£¬4
#¸³Öµ¿ÉÓÃÕâÖÖÐÎʽa,b,c=3,4,5;
#±È½ÏÔËËãʱ¡£==×îÈõ£¬Ö»ÒªÖµÏàͬ¼´¿É£¬Èç1==1.0ΪÕ棬eql?Ç¿Ò»µã£¬ÐèҪֵΪÀàÐÍÏàͬ£¬Èç1==1£¬equal?×îÇ¿ÐèÒªÁ½¸ö±äÁ¿µÄµØÖ·Ïàͬ£¬Èça=b,b==a²ÅΪÕæ¡£
#<=>±È½ÏÁ½¸ö¶ÔÏóµÄ´óС£¬´óÓÚµÈÓÚСÓڷֱ𷵻Ø1£¬0£¬-1¡£Èç“aaa” <=> "abc"·µ»Ø-1
#===ÓÃÀ´·µ»ØÓұߵÄÖµÊÇ·ñÊôÓÚ×ó±ßµÄÇø¼ä£¬Èç (0..9) === 4·µ»Øtrue
#=~ºÍ!~·Ö±ðÓÃÀ´±íʾÕýÔò±í´ïʽÊÇ·ñÆ¥Å䣬ǰÕßÆ¥Åäʱ·µ»ØλÖ㬲»Æ¥Åäʱ·µ»Ønil¡£ºóÕß·µ»Øtrue»òfalse
#Î塢ѡÔñÓï¾ä
#ÕâÊÇifÓï¾ä£¬µ¥ÐУ¬¶àÐÐÇé¿ö£¬ÓëJava¼°C/C++²»Í¬µÄÊÇ£¬ËüÓÐthen endµÈ¹Ø¼ü´Ê¡£
(puts "\n1==1";puts "and 2==2";) if(1==1 and 2==2)
if(1==1) then puts"here is 1==1, then end"; end;
if (1==2)
puts 1==2
elsif(2==2)
puts "2==2 is true"
else
puts 2434
end
#unlessÏ൱ÓÚif not.ÎÒ¾õµÃ½öÊÇÈç´ËµÄ»°£¬Ã»Ê²Ã´ÒâÒå
unless (1==2)
puts "unless 1==2"
end
#caseµÄÓ÷¨ÈçÏÂ.½á¹û£ºx=3;ÆäËü¿ÉÄÜ¡£caseÆäʵÓõñȽÏÉÙ£¬¼´Ê¹ÎÒ×Ô¼º±à³ÌÒ²ÓõñȽÏÉÙ¡£
x=3
case x
when 1..2
print "x=",x,";ÔÚ 1..2ÖÐ"
when 4..9, 0
print "x=",x,";ÔÚ4..9,0ÖÐ,»òÊÇ0"
else
print "x=",x,";ÆäËü¿ÉÄÜ\n"
end
#Áù¡¢Ñ»·Óï¾ä
=begin
Ò». while£¨µ±…£© Ñ»·
while Ìõ¼þ
Óï¾ä1; Óï¾ä
Ïà¹ØÎĵµ£º
¹ØÓÚC++0x
Ô¤¼ÆÓÚÃ÷Äêµ×ÍƳöµÄбê×¼C++0x£¬Ëä˵ÒѽӽüÊչٽ׶Σ¬È´ÈÔÓÐÈô¸ÉÓдý½ÓÄɵÄÐÂÌá°¸±»Ìá³ö¡£ÓÈÆäÖµµÃ¹Ø×¢µÄÊÇ£¬Óëlambda±í´ïʽÒÔ¼°¾Ö²¿º¯ÊýÏà¹ØµÄÌá°¸“Unified Function Syntax£¨Í³Ò»µÄº¯ÊýÓï·¨£©”£¬¾¡¹Ü²»Êܱê׼ίԱ»á´ý¼û£¨Á½Äê¼äÀú¾ËÄ´ÎÑÓ³Ù±í¾ö£¬Á½´Î²»Óèͨ¹ý£©£¬ÈÔÈ»“ÍçÇ¿µØ”ÍƳöÁ ......
PythonºÍRubyµÄ¶Ô±È£¬¾ÀÕýһЩÎó½â
ÏÂÃæÊÇÎÒÔÚ¿´Á½Æª¹ØÓÚPythonºÍRuby¶Ô±ÈµÄÎÄÕÂʱ£¬Ëù×÷µÄ¾ÀÕý£¬ÔÎĶ¼Êǹ㷺Á÷Ðеģ¬±È½ÏºÃÕÒ¡£
------------------------------------------------------
¡¶rubyºÍpythonµÄ±È½Ï¡·¸üÕýÒ»µãÊÂÇé
1¡¢Îĵµ¡¢¿ªÔ´ÏîÄ¿¡¢¿âÖ§³Ö£¬ÕâЩ¶«Î÷Ruby²»Òª¸úPython±È£¬²»ÊǼ¸¸öÊýÁ¿¼¶µÄÎÊÌ⣬ºÎ±ØÃ²Ë ......
ÔÚÂÛ̳Àï¿´ÁËdaquan198163ËùдµÄ¡¶³õѧRORµÄÒÉ»ó¡·ÕâƪÎÄÕ£¬robbinÔڻظ´ÖиøÁËÏêϸµÄ½â´ð£¬¿ÉÊÇ¿´Íê½â´ðÖ®ºó£¬ÎÒÒ²²úÉúÁËһЩÒÉ»ó£¬ÔÚ´ËÏëÎÊÎÊ¡£
ÔÚrobbinËù¸ø³öµÄ½â´ðµ±ÖУ¬¸ü¶àµÄÊDzûÊörailsµÄºÃ´¦£¬È»¶ø´ó¼Ò¶¼ÖªµÀ£¬railsÖ»Ê ......
ÈýÕßÖ®¼äÇø±ð²¢²»ÏñÄãÏëµÄÄÇôÄÑ£¬Ò²²»»áÏñÓÐЩÎÄÕÂдµÄÄÇô³¤¡£Í¦¼òµ¥µÄ¡£
Ïà֮ͬ´¦£ºÈýÕß¾ùÔÚkernelÖж¨ÒåµÄ£¬¾ùº¬Óаüº¬½øijÎïÖ®Òâ¡£
²»Í¬Ö®´¦£º
1¡¢requre,loadÓÃÓÚÎļþ£¬Èç.rbµÈµÈ½áβµÄÎļþ¡£
2¡¢includeÔòÓÃÓÚ°üº¬Ò»¸öÎļþ(.rbµÈ½áβµÄÎļþ)ÖеÄÄ£¿é¡£
3¡¢requreÒ»°ãÇé¿öÏÂÓÃÓÚ¼ÓÔØ¿âÎļþ£¬¶øloadÔòÓÃÓÚ¼ÓÔØÅ ......
ÕÕÀý¿ÉÒÔÏÈ¿´¶Ë³ÌÐò
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
&n ......