標籤:ruby學習筆記之前一直對ruby只停留在聽說過的狀態,最近有一些閑暇的事件,學習一下ruby,為將來的ruby on rails開發做一些準備。ruby由日本的松本行弘(まつもとゆきひろ/Yukihiro Matsumoto)建立於1993年。相對於java這樣的大而全的開發語言,ruby可以說是小而美的,非常類似於python,通常這樣的語言的代碼量只有java的五分之一吧,而且學習起來也比較容易,如果有效提高開發速度。ruby有很多優秀的特性,如果要說兩個最重要的特點,
class String def has_one_in?(string_Arr) has = false string_Arr.each { |word| has= self.include?(word) if has break end } has endenddef decode_subject(sub) if sub.include?("B?") encode_str = sub.match(/=\?(.*
$res = "__"def lamb(&lamb)3.times do puts $res=lamb.call end puts "-------at the end of lamb() : #{$res}"enddef lamb_test lamb { return puts " return in lamb() " } puts "--------at the lamb_test() end"enddef bl3.times do puts $
2006初,我接到了公司分配的一個遺留項目,讓我負責一個基於C/S的系統的伺服器端。其實是系統是基於HTTP協議的,因為負責用戶端的同事對於伺服器端編程不甚瞭解,雖然使用PHP對熟悉C++的他來說是駕輕就熟,但是在進一步實現更多的功能和更高的效能上就捉襟見肘了。項目是在非常突然的情況下交給我的,因為該同事在用戶端上有更多的事情要做。我在分析了他的資料庫結構和PHP原始碼之後,決定按照與用戶端的通訊協議重寫他的伺服器端。為了能應付老闆苛刻的時間限制,我打算使用正在學習的Ruby on Rails。
irb(main):022:0* 1.next=> 2irb(main):023:0> "a".next=> "b"irb(main):024:0> "1".next=> "2"irb(main):025:0>效能比較:require 'benchmark'n=(1..1000000).to_adef num_next(first,last) while first != last first=first.next end
class Fixnum attr_accessor :valueendx=1p x.object_idx.value="Anleb"p x.value.object_iddef change(x) p x.object_id p x.value.object_id x=2 #指標改變 x.value="Mr.w" p x.object_id p x.value.object_id
class A def self.ask1 puts "the method of class" end def ask2 puts "the method of instance" endend#類的執行個體對象的方法,方法屬於類所產生New出來的執行個體對象。 p a.methods.length p a.class.instance_methods.length p A.instance_methods.length p