Skip to content

Instantly share code, notes, and snippets.

@satomixx
Last active August 29, 2015 14:18
Show Gist options
  • Save satomixx/7294cfc7db46acdc0469 to your computer and use it in GitHub Desktop.
Save satomixx/7294cfc7db46acdc0469 to your computer and use it in GitHub Desktop.
[Ruby] コードを短くする為の論理和と論理積(と排他的論理和)のおさらい ref: http://qiita.com/tsumekoara/items/51b756e3b22ad99cbc4b
def check
true if hoge.present? && fuga.present?
end
def check
hoge.present? && fuga.present?
end
def hoge
# 論理積 AND
false && false #=> false
false && true #=> false
true && false #=> false
true && true #=> true
# 論理和 OR
false || false #=> false
false || true #=> true
true || false #=> true
true || true #=> true
# 排他的論理和 XOR ^
false ^ false #=> false
false ^ true #=> true
true ^ false #=> true
true ^ true #=> false
end
a = nil
b = 10
a || b # 10
a && b # nil
true ^ true #=>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment