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-08
標籤:rubyIn Ruby language, the return statement in the Ruby functions are interesting, Let‘s explore them as below:def concatenate(name_one=nil, name_two="") return name_one + name_twoendname = concatenate "wuhan",
Time of Update: 2014-07-06
標籤:style blog http color 使用 os define simple method定義簡單方法關鍵字def用於方法定義,在其後是方法名和可選的參數名列表,參數名列表會用一對圓括弧括住。構成方法主體的代碼放在參數列表之後,end用於結束方法定義。#define a
Time of Update: 2014-07-10
標籤:http 使用 strong os 問題 for https://ruby-china.org/wiki/install_ruby_guide如何快速正確的安裝 Ruby, Rails 運行環境對於新入門的開發人員,如何安裝 Ruby, Ruby Gems 和 Rails
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: 2018-12-08
在上次的內容裡,我們建立了訂單的Model,和表示頁面,這次繼續編寫CHECKOUT的處理。 1. 在checkout.rhtml的頁面上,有一個CHECKOUT按鈕,上次還沒有給它編寫處理代碼,現在在store_controller中添加save_order方法,代碼如下:def save_order@cart = find_cart@order = Order.new(params[:order])@order.line_items <<@cart.itemsif @
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
一、數字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
新版本的will_paginate已經拋棄了這樣的做法,轉而使用gem的方式,本文通過建立一個名為foobar的應用來瞭解一下will_paginate的用法。 ============================== C:\>rails foobar -d mysql C:\>cd foobar C:\foobar>ruby script/generate scaffold article title:string content:text
Time of Update: 2018-12-08
#scanweb.rb #用法ruby scanweb.rb www.jb51.net 將當前結果儲存在c:\1.txt require 'net/http' filename= File.new('c:\1.txt',"w+") if $*[0]==nil puts "hehe,沒有輸入網址" else h = Net::HTTP.new($*[0], 80) resp, data = h.get('/index.html', nil) if resp.message == "OK"
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入門,完全讀完只需20分鐘。這裡假設讀者已經安裝了Ruby,如果你沒有安裝的話,請在閱讀文前訪問Ruby官方網站進行下載並安裝。 互動Ruby 開啟IRB(互動式Ruby外殼): 如果你使用Mac OS X,那麼請開啟終端視窗輸入irb; 如果你使用Linux,那麼請開啟shell輸入irb; 如果你使用windows,那麼請在開始菜單中找到Ruby->fxri,並執行它。
Time of Update: 2018-12-07
python,ruby都是很優秀的語言,都強調以人為本,各有千秋,不過我感覺ruby的親和力似乎更大一些。ruby吸取了smalltalk, python,perl的優點。推薦一下學習ruby的好資源:英文清晰短小的免費電子書,我覺得是最好的入門書 http://www.sapphiresteel.com/The-Little-Book-Of-Ruby瀏覽器裡學ruby,不用安裝
Time of Update: 2018-12-07
Rails把java的方式戲稱為XML仰臥起坐(sit-ups)。Rails是一個完整的,開源的web開發架構,更多的快樂和更少的代碼。貫穿整個架構的是DRY(不要重複)原則,具體體現比如:定義好資料庫表後,類名字和對象屬性名稱字都自動確定了。用過hibernate的朋友知道我在說什麼(你也許會說xdoclet,
Time of Update: 2018-12-07
一、建立檔案 f=File.new(File.join("C:","Test.txt"), "w+")f.puts("I am Jack")f.puts("Hello World")檔案模式"r" :Read-only. Starts at beginning of file (default mode). "r+" :Read-write. Starts at beginning of file. "w" :Write-only. Truncates existing file to
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
Ubuntu 安裝,開發包$ sudo apt-get install wget vim build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libxml2-dev libxslt-dev autoconf automake libtool imagemagick libpcre3-dev步驟1 - 安裝 RVMRVM
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
Time of Update: 2014-07-03
想邊自己寫ruby代碼,邊部署隨時可以到處查看,heroku網域名稱又不友好,速度在國內又慢,於是乎想起來capistrano,於是學起 ...capistrano 一點入門認知https://www.evernote.com/shard/s6/sh/72a2b7c8-d531-4efc-9e16-ac82af2a92b7/e54fca8a9e7014ad87c79e7a7a5538c4capistrano