Instantly share code, notes, and snippets.

Embed
What would you like to do?
module Control
def if(e1, e2)
if self.isTrue? then e1 else e2 end
end
def if_(e1, e2)
self.if(e1, e2).call
end
end
module Bool
include Control
def and(other)
self.if(other, self)
end
def or(other)
self.if(self, other)
end
end
# 既存のクラスを拡張
class TrueClass
include Bool
def isTrue?
if self == true then true else false end
end
end
class FalseClass
include Bool
def isTrue?
if self != false then true else false end
end
end
class NilClass
include Bool
def isTrue?
if self != nil then true else false end
end
end
class String
include Bool
def isTrue?
if self != "" then true else false end
end
end
class Integer
include Bool
def isTrue?
if self != 0 then true else false end
end
end
class Array
include Bool
def isTrue?
if not self.empty? then true else false end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment