Last active
August 29, 2015 14:18
-
-
Save satomixx/7294cfc7db46acdc0469 to your computer and use it in GitHub Desktop.
[Ruby] コードを短くする為の論理和と論理積(と排他的論理和)のおさらい ref: http://qiita.com/tsumekoara/items/51b756e3b22ad99cbc4b
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def check | |
true if hoge.present? && fuga.present? | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def check | |
hoge.present? && fuga.present? | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = nil | |
b = 10 | |
a || b # 10 | |
a && b # nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
true ^ true #=> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment