標籤:1.RubyInstaller在RubyInstaller官網下載window版本安裝,地址:http://rubyinstaller.org/downloads/ 執行安裝程式,勾選Add Ruby executables to your PATH,安裝完成在cmd上測試ruby -v查看 注意安裝路徑中不要有空格,否則會影響rails的安裝 TIPS:如果在控制台(cmd)裡面輸入ruby
標籤:Optional ArgumentsSet default arguments, when we don‘t need to call it, we can simply skip it.def new_game(name, year=nil, system=nil) { name: name, year: year, system: system }endgame = new_game("Street Figher II") Options Hash
標籤:Is there a method in Ruby that takes an array, and counts all unique elements and their occurrences and passes them back as a hash?For example [‘A‘,‘A‘,‘A‘,‘A‘,‘B‘,‘B‘,‘C‘].method> {‘A‘ => 4, ‘B‘ => 2, ‘C‘ => 1}Something like
標籤:需求:給人搭配不同的服飾代碼版本一# -*- encoding: utf-8 -*-class Person attr_accessor :name def initialize(name) @name = name end def wear_t_shirts puts ‘大T恤‘ end def wear_big_trouser puts ‘垮褲‘ end def
標籤:ruby zip 壓縮解壓 在UNIX下的我們怎麼會淪落到用ruby寫壓縮和解壓工具呢?直接上shell啊!但是請允許本貓這次可恥的用ruby來玩玩吧!其實ruby GEM中有很多壓縮解壓包,我選的是Zip,也許是因為名字元合KISS原則吧!不過在編寫中發現Zip中的某些類沒有文檔中所說明的執行個體方法,也許在某個平台上還未實現??