Skip to content

Instantly share code, notes, and snippets.

@kyuden
Created July 10, 2014 17:22
Show Gist options
  • Save kyuden/9e3474d8fcf99caeee97 to your computer and use it in GitHub Desktop.
Save kyuden/9e3474d8fcf99caeee97 to your computer and use it in GitHub Desktop.
sliceの
# []があるから範囲指定の文字列抽出用途では価値ない
"2012-08-01".slice(0..2)
"2012-08-01"[0..2]
# 正規表現で抽出文字列を絞り込めるはおおきな利点
"2012-08-01".slice(/-(.+)-/) # => "-08-"
# ちなみにdeleteは削除後の文字列を返却するのが違い
"2012-08-01".delete(/-(.+)-/) # => "201201"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment