Skip to content

Instantly share code, notes, and snippets.

@pasberth
Created August 17, 2011 13:22
Show Gist options
  • Select an option

  • Save pasberth/1151517 to your computer and use it in GitHub Desktop.

Select an option

Save pasberth/1151517 to your computer and use it in GitHub Desktop.
errNNN というプレフィックスをつけて数字を呼びます。 err351 が 3510000000000 を返します。
# -*- coding: utf-8 -*-
def method_missing(funcname, *args)
if funcname =~ /^err([0-9]+)$/
ret = $1.to_i
if $1.length < 13
ret *= 10 ** (13 - $1.length)
end
ret
else
super
end
end
if __FILE__ == $PROGRAM_NAME
require "test/unit"
class TestErrnum < Test::Unit::TestCase
def test_err351
assert_equal 3510000000000, err351
end
13.times do |n|
class_eval(<<DEFINE)
def test_err#{"0" * n}1
assert_equal 1#{"0" * (12 - n)}, err#{"0" * n}1
end
DEFINE
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment