Created
January 17, 2015 05:21
-
-
Save lhside/6f4f4a13473f7717bcb1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# 優先順位は変わらないので、優先順位にそってメッソドを再定義する | |
# メソッドが入れ替わっているので、式内の演算子も置換で入れ替える。 | |
# | |
# ↑優先順位高 | |
# | ビット or | |
# & ビット and | |
# + 加算 | |
# * 乗算 | |
# ↓優先順位低 | |
# | |
class Fixnum | |
alias :"_|" :"|" | |
alias :"_&" :"&" | |
alias :"_+" :"+" | |
alias :"_*" :"*" | |
alias :"|" :"_*" | |
alias :"&" :"_+" | |
alias :"+" :"_&" | |
alias :"*" :"_|" | |
end | |
def myeval(expression) | |
eval(expression | |
.gsub(/\|/, 'or') | |
.gsub(/\&/, 'and') | |
.gsub(/\+/, 'plus') | |
.gsub(/\*/, 'multi') | |
.gsub(/or/, '*') | |
.gsub(/and/, '+') | |
.gsub(/plus/, '&') | |
.gsub(/multi/, '|')) | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment