Skip to content

Instantly share code, notes, and snippets.

@jutememo
Created January 13, 2010 20:27
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 jutememo/276550 to your computer and use it in GitHub Desktop.
Save jutememo/276550 to your computer and use it in GitHub Desktop.
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