Time of Update: 2014-11-07
標籤:blog http io ar os 使用 sp for 檔案 最近在看一個Rails項目,漸漸的接觸到Ruby語言,其中有些概念之前比較混亂,模稜兩可,相信也有人跟我一樣,剛開始學rub
Time of Update: 2014-07-09
標籤:style blog http color art html #!/usr/bin/env rubyclass MegaGreeter attr_accessor :names # 初始化這個物件 def initialize(names = "World") @names =
Time of Update: 2014-07-07
標籤:使用 檔案 os 代碼 io 安裝 安裝ruby yum install ruby irb rdoc 安裝Haskallyum install
Time of Update: 2014-06-27
標籤:des style blog code java http 構造字串字面量方法一:最簡單的使用單引號或者雙引號括起來的字串,比如"hello"。方法二:使用%q配合分界符,%q代表單引號str=%q!he/lo!方法三:使用%Q配合分界符,%Q代表雙引號str=%Q{he/lo
Time of Update: 2014-10-09
標籤:物件導向、基本概念 我這個人記憶力一直比較差,需要沒事多看看,今天再看Ruby物件導向編程的內容,把其中一些概念記下來,以便日後回憶使用。 基本概念: 一。局部變數、全域變數、執行個體變數(物件變數)和類變數。 二。類方法和執行個體方法(對象方法)。 三。繼承。
Time of Update: 2014-09-07
標籤:message product errors 資料庫 title 要有zh-CN.yml這個檔案,這個可以去github上下載,有別人做的要安裝i18n 的gemconfig下application.rb裡要有config.i18n.default_locale = "zh-CN"在yml檔案裡加上zh-CN:
Time of Update: 2014-08-03
標籤:style blog http color 使用 os io for http://rvm.io/rvm/install Install RVM (development version):\curl -sSL
Time of Update: 2014-07-30
標籤:style blog color 使用 代碼 div c++ new 上一篇講了ruby中的可調用對象proc和lambda,他們都是塊轉換成的對象。ruby中的可調用對象還有方法。通過使用method方法,並且以方法
Time of Update: 2014-07-28
標籤:style blog color strong div ar new log ruby中的私人方法是指方法只能被隱含調用,不能被顯示調用。而當沒有顯示接收者的時候,會把self當成接收者。因此,只能在自身中調用私人方法
Time of Update: 2014-07-16
標籤:style blog color div re c #######################類變數######################class Cloud @@count=0 def initialize(user,password,ip)
Time of Update: 2018-12-08
Private private 函數只能 在本類和子類的 上下文中調用,且只能通過self訪問。 這個意思就是:private函數,只能在本對象內部訪問到。 對象執行個體變數(@)的存取權限就是 private。 複製代碼 代碼如下:class AccessTest def test return “test private” end def test_other(other) “other object ”+ other.test end end t1 = AccessTest.new t2
Time of Update: 2018-12-08
代碼如下:複製代碼 代碼如下:require 'date' day = Date.new(2008, 2, -1) end_of_month = day.strftime('%d').to_i year_and_month = day.strftime('%Y%m') for today in 1..end_of_month do p sprintf('%s%02d', year_and_month, today)
Time of Update: 2018-12-08
一、數字Ruby支援整數和浮點數,整數可以是任意長度一定範圍內的整數以二進位存放,它們屬於fixnum類型,當超出這個範圍時則自動轉換為bignum類型表達方式:符號+一串字元,數字串中的底線會被忽略,(首碼包括:0表示八進位, 0x表示十六進位, 0b表示二進位)123_456_789_123_345_789 # Bignum0xaabb # 十六進位也可以通過在前面加上問號來得到ASCII碼字元對應的整數值和逸出序列的值?a # 一般字元?\n # 分行符號 (0x0a)?\C-a #
Time of Update: 2018-12-08
解釋的不錯,應該明確了不少 ruby symbol詳解 起因 最近在學習ruby on rails,的確是一個優秀的資料庫開發架構。但在過程中,發現在視圖檔案夾中的rhtml檔案裡有大量的類似於以下的語句: <td><%= link_to recipe.title, :action => “show”, :id => 1 %></td>
Time of Update: 2018-12-08
全域變數由$開頭.它們可以在程式的任何位置訪問到.在初始化前,全域變數有一個特殊的值 nil. ruby> $foo nil ruby> $foo = 5 5 ruby> $foo 5 應謹慎使用全域變數.由於在任何地方都可以被寫因此他們相當危險.濫用全域變數會導致很難隔離臭蟲;同時也視為程式的設計未經嚴格考慮.當你發現必須要使用全域變數時,記得給它一個不會在其它地方一不小心就用到的描述性名字(像上面那樣叫$foo可能不是一個好想法).
Time of Update: 2018-12-08
Ruby將字串像數字一樣處理.我們用單引號('...')或雙引號("...")將它們括起來.ruby> "abc" "abc"ruby> 'abc' "abc"單引號和雙引號在某些情況下有不同的作用.一個由雙引號括起來的字串允許字元由一個前置的斜杠引出,而且可以用#{}內嵌運算式.而單引號括起來的字串並不會對字串作任何解釋;你看到的是什麼便是什麼.幾個例子:ruby> print "a\nb\nc","\n"ac nilruby> print 'a\nb\n'
Time of Update: 2018-12-08
我們總是希望對未知事件分類.當它發生時,向其它方法傳遞一塊作為參數的代碼是最容易地解決方案,也就是說我們希望像處理資料一樣處理代碼. 一個新的過程對象可以通過proc建立: ruby> quux = proc { | print "QUUXQUUXQUUX!!!\n" | } #<Proc:0x4017357c> 現在quux指向一個對象,像其它對象一樣,它也有可以調用的行為.特別的,我們可以用call方法執行它: ruby>
Time of Update: 2018-12-07
具體演算法Peter Norvig大神已經說得很清楚了,偶就不囉嗦了。初學ruby練練手。 class Sudoku WIDTH = 9 HEIGHT = 9 UNIT = 3 def initialize() init_dependency_table() end def ok(quiz_candidates)
Time of Update: 2018-12-07
文章目錄 VariablesConditionsLoopsError HandlingMethodsClassesUsing Code from Other Files
Time of Update: 2018-12-07
This is to setup a developement environment for Ruby 1.87 and Rails 2.2.3 on Ubuntu 10.04 (Lucid).[sourcecode language="bash"]# make sure ubuntu is up to date$ sudo apt-get update$ sudo apt-get dist-upgrade# install ruby$ sudo apt-get install ruby1.8