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

תÔØ——Ruby×Ö·û´®´¦Àí

ת×Ô£ºhttp://developer.51cto.com/art/200912/170762.htm 
Ruby×Ö·û´®´¦Àíº¯Êý×ܽáÁбí·ÖÏí
Ruby×Ö·û´®´¦Àíº¯Êý°üÀ¨·µ»Ø×Ö·û´®³¤¶Èº¯Êý£»ÅжÏ×Ö·û´®ÖÐÊÇ·ñ°üº¬ÁíÒ»¸ö´®º¯Êý£»×Ö·û´®²åÈ룻×Ö·û´®·Ö¸ô,ĬÈÏ·Ö¸ô·ûΪ¿Õ¸ñµÈµÈ¡£
 
str.length => integer 
str.include? other_str
 => true or false  
"hello".include? "lo"
 #=> true  
"hello".include? "ol"
 #=> false  
"hello".include? ?h
 #=> true 
RubyÓïÑÔ¶ÔÓÚ±à³ÌÈËÔ±À´ËµÊÇÒ»Ïî·Ç³£ÓÐÓõĺ¯Êý¡£Ñ§ºÃÕâÏîÓïÑÔ¿ÉÒÔ°ïÖúÎÒÃÇʵÏÖ¼ò±ãÇáËɵıàд·½Ê½¡£ÏÂÃæÎÒÃÇÏò´ó¼Ò½éÉÜÒ»ÏÂRuby×Ö·û´®´¦Àíº¯ÊýµÄһЩ»ù±¾¸ÅÄî¡£
Ruby×Ö·û´®´¦Àíº¯Êý1.·µ»Ø×Ö·û´®µÄ³¤¶È
Ruby×Ö·û´®´¦Àíº¯Êý2.ÅжÏ×Ö·û´®ÖÐÊÇ·ñ°üº¬ÁíÒ»¸ö´®
Ruby×Ö·û´®´¦Àíº¯Êý3.×Ö·û´®²åÈë:
str.insert(index, other_str) 
=> str   "abcd".insert(0, 'X')
 #=> "Xabcd"  "abcd".insert(3, 'X')
 #=> "abcXd"  "abcd".insert(4, 'X') 
#=> "abcdX"  "abcd".insert(-3, 'X')    -3, 'X') #=> "abXcd"  "abcd".insert(-1, 'X')
 #=> "abcdX" 
Ruby×Ö·û´®´¦Àíº¯Êý4.×Ö·û´®·Ö¸ô,ĬÈÏ·Ö¸ô·ûΪ¿Õ¸ñ
str.split(pattern=$;, [limit])
 => anArray   " now's the time".split #=> 
["now's", "the", "time"]  "1, 2.34,56, 7".split(%r{,\s*})
 #=> ["1", "2.34", "56", "7"]  "hello".split(//) #=> 
["h", "e", "l", "l", "o"]  "hello".split(//, 3) #=> 
["h", "e", "llo"]  "hi mom".split(%r{\s*}) #=> 
["h", "i", "m", "o", "m"]   "mellow yellow".split("ello")
 #=> ["m", "w y", "w"]  "1,2,,3,4,,".split(',') #=>
 ["1", "2", "", "3", "4"]  "1,2,,3,4,,".spl


Ïà¹ØÎĵµ£º

RubyµÄ×°ÊÎÆ÷ģʽʵÏÖ

class Tree
def initialize
puts "Make a normal tree"
end
def decorate
puts "Make sure the tree won\'t fall"
end
end
class RedBalls < Tree
def initialize(tree)
@parent = tree;
end
def decorate
@parent.decorate
puts "Put on some red balls"
end
end ......

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

´Ó½ñÌìÆð²»ÔÙÀË·Ñʱ¼ä£¬¿ªÊ¼×ßÏò×Ô¶¯»¯²âÊÔÕâÌõ¹âÃ÷µÄµÀ·£¬²¢ÒԴһ¸ö×Ô¶¯»¯²âÊÔƽ̨ΪĿ±ê£¬²¢Õâ¸ö¹ý³ÌÒ»µãµãµÄ¼Ç¼ÏÂÀ´ºÍ´ó¼Ò·ÖÏí
Ê×ÏÈ£¬ÊÇruby»·¾³µÄ´î½¨
£¨1£©µ½rubyµÄ¹ÙÍø£ºhttp://www.ruby-lang.org/en/ÏÂÔØ ruby°²×°³ÌÐò;
      PS £ºÑ¡Ôñ ruby on windows,ÎÒÏÂÔصÄÊÇRuby 1.8.6 One ......

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


ÈýÕßÖ®¼äÇø±ð²¢²»ÏñÄãÏëµÄÄÇôÄÑ£¬Ò²²»»áÏñÓÐЩÎÄÕÂдµÄÄÇô³¤¡£Í¦¼òµ¥µÄ¡£
Ïà֮ͬ´¦£ºÈýÕß¾ùÔÚkernelÖж¨ÒåµÄ£¬¾ùº¬Óаüº¬½øijÎïÖ®Òâ¡£
²»Í¬Ö®´¦£º
1¡¢requre,loadÓÃÓÚÎļþ£¬Èç.rbµÈµÈ½áβµÄÎļþ¡£
2¡¢includeÔòÓÃÓÚ°üº¬Ò»¸öÎļþ(.rbµÈ½áβµÄÎļþ)ÖеÄÄ£¿é¡£
3¡¢requreÒ»°ãÇé¿öÏÂÓÃÓÚ¼ÓÔØ¿âÎļþ£¬¶øloadÔòÓÃÓÚ¼ÓÔØÅ ......

Rubyѧϰ±Ê¼ÇÈý——Àà


#Ò»¡¢¶¨ÒåÒ»¸öÀà
class Person
  def initialize(name,age=18)
    @name=name;
    @age=age;
    @motherland="china";
  end
  def talk
    puts "my name is "+@name+" and I am "+@age.to_s
   &nb ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ