0. Ruby install On windows
下載 DEvKit 表示可擴充的套件
0-1 RubyGems簡介
RubyGems是Ruby的套件管理系統,讓你輕易安裝及管理Ruby函式庫。你可以在RubyGems上找到所有的Ruby開源套件。另外,讀者如果想找Ruby或Rails有哪些好用的套件,也可以瀏覽看看The Ruby Toolbox,這個站依照套件的熱門程度排序,非常方便。
常用指令
gem -v 告訴你 RubyGems 的版本
gem update --system 升級RubyGems的版本
gem install gem_name 安裝某個套件
gem list 列出安裝的套件
gem update gem_name 更新最新版本
gem update 更新所有你安裝的Gems
gem install -v x.x.x gemname 安裝特定版本
gem uninstall gem_name 反安裝
ref 1
0-2 Require Method
https://kaochenlong.com/2016/05/01/require/
Notice
require 'rubygems'
will adjust the Ruby loadpath
allowing you to successfully require the gems you installed through rubygems, without getting a LoadError: no such file to load -- sinatra
.
In Ruby 1.9 'require "rubygems"' happens automatically. In previous Rubies rubygems is not automatically required and you will get the error. Your best bet is to automatically type it in unless you are sure you are running always in 1.9+.
0-3 Install test
gem install mail
gem install win32-service
1. Ruby totorail
https://railsbook.tw/chapters/02-environment-setup.htmlhttps://ourcodeworld.com/articles/read/270/how-to-create-an-executable-exe-from-a-ruby-script-in-windows-using-ocra
http://ruby-for-beginners.rubymonstas.org/built_in_classes/symbols.html
https://openhome.cc/Gossip/Ruby/index.html
2. Data structure
Array:
["A string", 1, true, :symbol, 2]
Hash
{ "one" => "eins", "two" => "zwei", "three" => "drei" }
3. Class
4. Block
ref 1
block是用來暫存及傳遞程式碼的地方
它本身不是物件(但有方法可以讓它變物件,最後說明)所以必須掛在別人身上(可能是別的方法、別的物件
@users.each do |u|
...
end
def my_times(n) i = 0 while n > i i += 1 yield i*2 #對應到block裡面的|| end endmy_times(3) { |num| #i*2就會yield到這邊 puts "hello, #{num}xRuby" }#輸出 2xRuby 4xRuby 6xRuby
沒有留言:
張貼留言