Ruby学习资源汇总


把复制一个文件到另一个文件,瞎折腾的,不知道不关闭有没有问题

File.open(ARGV[1],'w').write(File.open(ARGV[0]).read())

网上查询了, File.open 会在代码块结束后自动close


加载模块

require './Ex25' #这个不能切换目录
require File.expand_path("../Ex25",__FILE__) #这个可以切换目录


文件操作


NET-SSH 和 NET-SCP


Ruby代码规范


vim-ruby

#ubuntu
echo 'map <F5> :!ruby % <CR>'| sudo tee -a /usr/share/vim/vim[0-9][0-9]/ftplugin/ruby.vim
#other
echo 'map <F5> :!ruby % <CR>'>>/usr/share/vim/vim[0-9][0-9]/ftplugin/ruby.vim


.vimrc

" 设置编码
 set enc=utf-8
" 设置文件编码
set fenc=utf-8
" 设置文件编码检测类型及支持格式
set fencs=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
" 设置开启语法高亮
syntax on
"显示行号
set number
" 查找结果高亮度显示
set hlsearch
" tab宽度
set tabstop=4
set cindent shiftwidth=4
set autoindent shiftwidth=4
filetype plugin indent on


编译安装ruby

sudo apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev
cd /tmp
wget http://cache.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p353.tar.gz
tar -xvzf ruby-2.0.0-p353.tar.gz
cd ruby-2.0.0-p353/
./configure --prefix=/usr/local
make
sudo make install


安装rails

sudo gem install rails
#install node.js
#sudo apt-get install python-software-properties python g++ make
#sudo add-apt-repository ppa:chris-lea/node.js
#sudo apt-get update
sudo apt-get install nodejs