Skip to content

Instantly share code, notes, and snippets.

@mustmodify
Last active August 29, 2015 14:09
Show Gist options
  • Save mustmodify/15812f4756d987a99eeb to your computer and use it in GitHub Desktop.
Save mustmodify/15812f4756d987a99eeb to your computer and use it in GitHub Desktop.
class Numeric
def stuff=(value)
@stuff=value
end
end
x = 7
x.stuff='hello'
# EXPLOSION!
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