Skip to content

Instantly share code, notes, and snippets.

@kastner
Created January 27, 2011 18:01
Show Gist options
  • Save kastner/798901 to your computer and use it in GitHub Desktop.
Save kastner/798901 to your computer and use it in GitHub Desktop.
numberish.rb
class Numberish
def self.convert(input)
if input.to_i > 0 && input.to_i.to_s == input
return input.to_i
else
return input
end
end
end
if $0 == __FILE__
require 'test/unit'
class TestNumberish < Test::Unit::TestCase
def test_1
assert_equal 1, Numberish.convert("1")
end
def test_plus_1
assert_equal "+1", Numberish.convert("+1")
end
def test_auto
assert_equal "auto", Numberish.convert("auto")
end
def test_negative_1
assert_equal "-1", Numberish.convert("-1")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment