Skip to content

Instantly share code, notes, and snippets.

@lasershow
Last active January 27, 2016 01:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lasershow/24f097549a75f72b4e48 to your computer and use it in GitHub Desktop.
Save lasershow/24f097549a75f72b4e48 to your computer and use it in GitHub Desktop.
【Ruby・Rails】三項演算子(条件演算子)を使ってif文をスリムに書こう! ref: http://qiita.com/lasershow/items/160c854e4256ba596ec5
def add_button_name
if controller.action_name == 'show'
"コメントを投稿する"
else
"コメントを更新する"
end
end
if 条件
 式1
else
 式2
end
条件 ? 式1 : 式2
def add_button_name
if controller.action_name == 'show'
"コメントを投稿する"
else
"コメントを更新する"
end
end
def add_button_name
controller.action_name == 'show' ? "コメントを投稿する" : "コメントを更新する"
end
def action_name_show?
controller.action_name == 'show' ? true : false
end
def add_button_name
if controller.action_name == 'show'
"コメントを投稿する"
else
"コメントを更新する"
end
end
def add_button_name
controller.action_name == 'show' ? "コメントを投稿する" : "コメントを更新する"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment