今天,下面這段程式讓我糾結了很久,Ruby中private的概念真的很奇怪。。。 class Test private def test_print puts 'test' endendclass Test2 < Test def test_print2 # self.test_print #=> 這裡加上self就不能調用,private method `test_print' called for # (NoMethodError) test_print
#靜態方法的4種寫法class Test def Test.StaticMethod1 puts "Test.StaticMethod1" end def self.StaticMethod2 puts "Test.StaticMethod2" end class << Test def StaticMethod3 puts "Test.StaticMethod3" end end class << self
#關閉命令顯示@echo off#提示資訊echo Now,listing the controller,please not shutdown the DOS File!#切換到當前路徑,.bat檔案和.rb檔案放在一起就可以了set pa=%cd%#執行ruby指令碼ruby test.rbpause 當我們利用cmd命令執行:ruby test.rb的時候,你可能會發現,我們需要cd 到test.rb的目錄,可以利用DOS命令實現這個 路徑,這樣無論你的指令碼在哪,批處理調用ruby
此筆記是為了協助理解 "<<" 指令 ruby語言允許我們在一個對象的基礎上定義類,使得我們可以單獨擴充一個對象的行為,例子如下 test="hello" #普通string normal=a.dup #還是普通string class << test def to_s "value is #{self}" end end #test對象已經被更新, normal保持不變 運行完上述代碼以後
今天被人投訴說 blog 多日未更新,影響了閱讀情緒,偶趕緊開動起來 ^_^# Part oneaFile = File.new("C:\\1.txt","w") aFile.puts "the 1" aFile.puts "the 2"aFile.close # Part twoaFile = File.new("C:\\2.txt","w") puts "the 1" puts "the
毫不例外,和所有其他的開源項目一樣,如果你想進入Ruby on rails的世界,會發現異常的的艱難,文檔很少,而且很零散,下載下來的檔案缺乏基本的說明,本人的親身體驗就是一個典型例子,不廢話了,現在開始介紹:一、安裝環境<windows>Ruby on rails網站:http://www.rubyonrails.org/ 1、在這裡下載Ruby 1.8.6 http://rubyforge.org/frs/?group_id=167 其中已經包含rubygems