Last active
August 29, 2015 14:09
-
-
Save mustmodify/15812f4756d987a99eeb to your computer and use it in GitHub Desktop.
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
class Numeric | |
def stuff=(value) | |
@stuff=value | |
end | |
end | |
x = 7 | |
x.stuff='hello' | |
# EXPLOSION! |
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
class Numeric | |
attr_accessor :scale | |
# NOTE: Does not affect self | |
def to_scale(digits=2) | |
out = self.round(digits) | |
out.scale = digits | |
out.extend(Formatter) | |
end | |
def scale(atts = {}) | |
max = atts[:max] || 4 | |
num = self | |
scale = 0 | |
while(num != num.to_i && scale < max) | |
scale += 1 | |
num *= 10 | |
end | |
scale | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment