0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【自分用】rubyリファレンス

Last updated at Posted at 2017-05-29

#インデックス

  • 文字列
  • 設定

###️文字列

文字列内にある空白の操作

strip.rb
#例)
str = "  Hello World   "
str.gsub(" ", "")   # => "HelloWorld"
str.strip           # => "Hello World"

#補足: lstrip, rstrip

参考:http://qiita.com/ntakuya/items/1153940f3e9c6282b4c5
 

文字列の数字を0埋めする

zero-ume.rb
#例)
puts format('%02d', 7)  #=> 07
puts format('%02d', 12) #=> 12

puts printf('%02d', 7)  #=> 07
puts printf('%02d', 12) #=> 12

puts '%02d' % 7  #=> 07
puts '%02d' % 12 #=> 12

#例)
str = "7"
str.rjust(2, "0") #=> "07"
str = "12"
str.rjust(2, "0") #=> "12"

#補足: ljust, center

参考:
http://ref.xaio.jp/ruby/classes/string/rjust
http://qiita.com/tksmaru/items/0f9283d0c5f0ee716f2f 

引数で指定した文字を文字列から削除する

deleteメソッド
str = "hello world"
puts str.delete('l') # => "heo word"

参考:http://ref.xaio.jp/ruby/classes/string/delete


###設定
rbenvの切り替え

使用中のrubyのバージョン確認

rbenv version

インストールしているrubyのバージョン一覧

rbenv versions

rubyの切り替え

rbenv gloval バージョン

切り替え確定

rbenv rehash

カレントディレクトリのみrubyのバージョンを変更したい場合は

rbenv local バージョン

参考:http://qiita.com/a_ishidaaa/items/8cc14453289dba1413dd

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?