Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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ѧϰ±Ê¼ÇËÄ——Ä£¿é


#Ò»¡¢Ä£¿é¶¨Òå¼°ÒýÓã¬Ä£¿é¾ÍÊÇÒ»¶Î´úÂ룬ÀïÃæÓÐһЩ·½·¨·ÅÒ»Æð¡£
#¶¨ÒåÄ£¿éÓÃmodule...end ¡£Ä£¿éÓëÀà·Ç³£ÏàËÆ£¬µ«ÊÇ£º
#A) Ä£¿é²»¿ÉÒÔÓÐʵÀý¶ÔÏó£»
#B) Ä£¿é²»¿ÉÒÔÓÐ×ÓÀà¡£
include Math
puts sqrt(91);
module Me
  def sqrt(a)
  puts a*a;
  return a*a;
end
PI=3.1415926
end
include Me
puts sqrt(10)
puts Math.sqrt(10);
puts Math::PI;
puts Me::PI;#±äÁ¿ÒýÓÃÓë·½·¨µ÷Óò»Í¬£¬ÓÃ˫ðºÅ£¬¶ø²»ÊǵãºÅ
#¶þ¡¢¿É±ä²ÎÊý
def params(*num)
"This is text sqrt. "
puts num.size
puts num[1]
puts num.inspect
end
params(4,2,3)
#Èý¡¢Ä£¿éµÄµÚÈý¸ö×÷Óã¬ÊµÏÖÀàËÆÓÚ¶àÖؼ̳еŦÄÜ£¬Ò²³ÆMix-in
#ÎÒÃÇÓÐÒ»¸öStudentÀ࣬ÓÐ×ÅPersonÀàµÄÊôÐԺͷ½·¨£¬»¹»á×öÊýѧÌâ——Çóƽ·½¸ù¡£ÒѾ­ÓÐÁËMeÄ£¿é£¬Ö»ÒªMix-in ÔÚStudentÀàÀï¾Í¿ÉÒÔÁË¡£
module Me
  def sqrt(num, rx=1, e=1e-10)
    num*=1.0
    (num - rx*rx).abs <e ? rx : sqrt(num, (num/rx + rx)/2, e)
  end
end
class Person
  def talk
    puts "I'm t ......

תÔØ——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,&nb ......

21±¾¾­µäruby railsµç×ÓÊé


Beginning Ruby from Novice To Perfessional

Head First Rails

Agile Web Development with Rails 3rd Edition(new)

Agile Web Development with Rails 3rd Edition

Agile Web Development with Rails 3rd EditionÖÐÎÄ

Rails ¿ìËÙÉÏÊÖÖÐÎĽ̲Ä

Ruby On Rails Web ¿ª·¢Ö®ÂÃ

Agile Web Development with Rails 2nd Edition

Best of Ruby Quiz

Rails Recipes

Ruby Cookbook

Ruby for Rails

Ruby ÓïÑÔÈëÃŽ̳Ì

Agile Web Development with Rails

Programming Ruby 2nd Edition

Rolling with Ruby on Rails

Ruby on Rails ʵ¼ù

Ruby on Rails API

RubyÎĵµÖÐÐÄ

Ruby Course

Ruby in a Nut shell

......

phpRPC + Ruby + Arduino = Ô¶³Ì¿ØÖÆ

phpRPC + Ruby + Arduino = 遠³Ì¿ØÖÆLED開關(?)
àÅ£¬ÎÒÖªµÀ這ÊÇ個ºÜ無ÁĵÄSample :P
關ì¶phpRPC與Arduino請×ÔÐÐGoogle
觀¿´´Ëdemo֮ǰ請ÏÈ°²裝ÁíÍâһƪËùÌáµ½µÄserialport
與ÁíÍâÒ»個Gem
Ì×¼þ£ºphprpc
ÔÚ這個範ÀýÖУ¬ÎÒ͸過PHPRPC½¨Á¢Ò»個Server£¬並ÇÒ͸過RPCºô½ÐһЩmethodÈ¥¿ØÖÆUSB Serial Port
¶øÔÚ實現這個demo時£¬ÎÒ們±Ø須½¨Á¢Server&Client兩¶Ë
µ×ÏÂÊÇSource code:
複製內Èݵ½¼ô貼°å
´ú碼:
# Server
#!/usr/bin/env ruby
require 'rubygems'
require 'serialport'
require 'phprpc'
class Cloud
  def initialize
    @@sp ||= SerialPort.new("/dev/cu.usb
serial-A600bMiv", {:baudrate => 9600})
  end
  
  def write(color)
    @@sp.write("##{color}")
  end
  
  def close
    ......

²ËÄñºÍRMXPºÍRubyÓïÑÔ

      ϲ»¶Íæ°¢ÔÂϵÁÐRPGÓÎÏ·µÄÎÒ£¬¸ú²»ÉÙͯЬһÑùÏÂÁËRPGMakerXPÀ´Õ°Ñöһϡ£µ±Ê±¾õµÃÕâ¸öÈí¼þÌ«·½±ãÁË£¬ÓÃÊó±êËæ±ãµãµã¾ÍÄÜŪ³öÀ´¸öÓÐȤµÄСÓÎÏ·¡£ÒòΪÀïÃæ²»½ö×Ô´ø²»ÉÙµØͼºÍÈËÎïÐÐ×ßͼµÈËزģ¬ÈÝÒ×ÉÏÊֵIJÙ×÷·½Ê½Ò²ÈÃ×Ô¼º´óÓгɾ͸Ѕ…¿ÉÊÇÓÎÏ·±Ï¾¹ÊÇÀë²»¿ª±à³Ì£¬½â¿ªÓÎÏ·°ü£¬¿´¿´È˼ÒÓÎÏ·ÀïµÄ½Å±¾£¬¼òÖ±¾ÍÏñÌìÊéÒ»Ñù£¬ÏëѧѧÔõÑù×ö³ö¸ü¸ß¼¶µÄЧ¹û£¬ÒòΪ¶Ô±à³ÌÒ»Çϲ»Í¨µÄÔµ¹ÊÊDz»¿ÉÄܵġ£È·Êµ£¬³ýÁ˽ű¾ÒÔÍ⣬Ïë´ÓÆäËû¹¦ÄÜÉÏ¿ª·¢ÐµÄÁÁµãÊÇ×ö²»µ½ÁË£¬Î¨Óдӽű¾ÏÂÊÖ£¬´ÓѧϰRubyÓïÑÔ¿ªÊ¼¡£
      ËùÒÔ£¬Ï¾öÐÄÊÔ׎Ӵ¥ÕâÖÖÓïÑÔ¡£
      ´ÓÀ´Ã»½Ó´¥¹ý±à³ÌµÄÎÒʵÔÚ²»¶®ÕⶫÎ÷¸ÃÔõôѧ……²»¹ý¼ÈÈ»´ÓÁãѧÆðÄǾÍÏÈÈ¥¹ÙÍø¿´¿´°É¡£
      ¹ÙÍøÉϵÄÊÕ»ñ£¬³ýÁËRuby±à¼­Æ÷µÄÏÂÔØÖ®Í⣬»¹·¢ÏÖÁËÒ»¸öºÜºÃµÄÍøÕ¾¡£
      www.pine.fm/LearnToProgram
      ÄÇÊÇÒ»¸ö½ÐChris PineµÄÈË×öµÄRuby³õѧÕ̡߽̳£ÎÒÉÔÉÔ¿´ÁËЩ£¬¾õµÃ·Ç³£¼òµ¥Ò׶®¡£²»ÖªÓÐûÓÐÓÐÐÄÈËÒѾ­¿ªÊ¼×öÁË·­Òë¡£²»¹ýÎÒ×¼±¸ÔÚ×Ô¼ ......

Fix Thrift 0.2.0 Installation with Ruby 1.9.1

When I try the command "gem install thrift" with Ruby 1.9.1, I got a compilation error with something related to a C function "strlcpy()".
Then I searched the web. It seems I am not alone and the community know it.
However I do not want to wait for official update, I want to try Cassandra and Thrift is a dependency I have to use now.
So, read on if you want a dirty fix.
Start command line console and run:
  $ gem install thrift
If you got the error with "strlcpy", you should have thrift code downloaded in your ruby gems folder.
It is "C:\Ruby\lib\ruby\gems\1.9.1\gems\thrift-0.2.0" for my computer on Windows.
  $ cd C:\Ruby\lib\ruby\gems\1.9.1\gems\thrift-0.2.0\ext
If you are using linux, check the lib/.../ext folder.
Open "extconf.rb" and "struct.c" with a text editor. Comment out HAVE_STRLCPY in "struct.c" like this:
  /*
    #ifndef HAVE_STRLCPY
     ......
×ܼǼÊý:146; ×ÜÒ³Êý:25; ÿҳ6 Ìõ; Ê×Ò³ ÉÏÒ»Ò³ [8] [9] [10] [11] 12 [13] [14] [15] [16] [17]  ÏÂÒ»Ò³ βҳ
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ