#Class describ ------rdoc rules#= headers#this is header content#== sub header# this is sub header content#=== sub sub header# this is sub sub headerclass Animal attr_accessor :name #-------------① #this is the comment for the 'new' method ! def
Ruby 之 Block, Proc, LambdaBlockBlock 不是對象,是Ruby的語言特性,近似於閉包(Closure)。範例:def meth res= yield "Block called returns #{res}"endputs meth do next “next_value” end #Block called returns next_valueputs meth do break “break_value” end #
$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 $
1、Ruby-China網站原始碼包: https://github.com/huacnlee/ruby-china $ cd ~/workspace$ git clone https://github.com/huacnlee/ruby-china.git2、如果想要省心一點,請千萬不要嘗試在WINDOWS下安裝。昨晚上花了30分鐘嘗試WINDOWS下安裝,還安裝了git的WINDOWS用戶端,各種報錯,解決了幾個,後來太晚了,睡覺作罷。3、今天使用UBUNTU LINUX 11.10來安裝。
class Array def iterate!(&code) #注意這裡用了&符號 self.each_with_index do |n,i| self[i] = code.call(n) end endendarr = [1,2,3,4]arr.iterate! do |n| n ** 2end #[1, 4, 9,
今天又學了一會RUBY的閉包,主要是看《RUBY元編程(metapromgramming ruby)》一書:http://book.douban.com/subject/4086938/第三章閉包結尾的守關BOSS是一道題:編寫你的第一種領域專屬語言。event "the sky is falling" do @sky_height < 300endevent "It's getting closer" do @sky_height <
作為一個優秀的編程人員,應該很清楚Ruby on Rails開發架構的好處。在這裡我們就為大家介紹一下Ruby on Rails本地安裝的一些技巧。 很多資料都是介紹如何使用gem(One-Click Ruby Installer已經包含在裡面,安裝完後就可以使用gem)進行遠程安裝,如果碰上網路不好的時候就無法安裝。在網上看到一篇介紹本地安裝的方法,現在再把自己安裝的過程總結一下給大家。 Ruby on