Permalink
Browse files

for first release

  • Loading branch information...
1 parent db57cb8 commit f6032daa22a353cbd1ce401b519f94827942d7f2 @kachick committed Jan 15, 2012
Showing with 32 additions and 12 deletions.
  1. +12 −5 README.rdoc
  2. +8 −3 example.rb
  3. +2 −2 lib/integer/base.rb
  4. +10 −2 lib/integer/base/import.rb
View
@@ -10,7 +10,7 @@ use free-format in positional numeral system
== FEATURES
* easy build upper 36 basenumbers
-* original syntax (0 1 2 -> 0 a b, etc)
+* use original syntax (0 1 2 -> 0 a b, etc)
== SYNOPSIS
@@ -20,11 +20,18 @@ use free-format in positional numeral system
* extend
require 'integer/base/import'
-*
- my_base_chars = %w[0 a]
- 'a'.to_i(my_base_chars) #=> 1
- 'a0'.to_i(my_base_chars) #=> 2
+* to_i
+ my_chars = %w[0 a]
+ 'a'.to_i(my_chars) #=> 1
+ 'a0'.to_i(my_chars) #=> 2
+ my_chars = ['0', *'A'..'I']
+ 'a'.to_i(my_chars) #=> 1
+ 'a0'.to_i(my_chars) #=> 10
+ 'aib'.to_i(my_chars) #=> 192
+
+* to_s
+ 192.to_s(my_chars) #=> 'aib'
== REQUIREMENTS
View
@@ -14,7 +14,12 @@
p(Integer::Base.parse '-019', ('0'..'9').to_a)
p Kernel.Integer('19')
-my_base_chars = %w[0 a]
+my_chars_1 = %w[0 a]
+p 'a'.to_i(my_chars_1)
+p 'a0'.to_i(my_chars_1)
-p 'a'.to_i(my_base_chars)
-p 'a0'.to_i(my_base_chars)
+my_chars_2 = ['0', *'A'..'I']
+p 'a'.to_i(my_chars_2)
+p 'a0'.to_i(my_chars_2)
+p 'aib'.to_i(my_chars_2)
+p 192.to_s(my_chars_2)
View
@@ -15,7 +15,7 @@ class << self
def parse(str, chars)
chars = base_chars_for chars
base = chars.length
- str = str.upcase
+ str = str.downcase
if sign = str.slice!(/\A([-+])/, 1)
if sign == '-'
@@ -62,7 +62,7 @@ def convert_to_string(int, chars)
private
def base_chars_for(chars)
- chars = chars.map(&:upcase)
+ chars = chars.map(&:downcase)
case
when chars.length < 2
@@ -34,8 +34,6 @@ def Integer(obj)
end
class Integer
- alias_method :original_to_s, :to_s
-
# @param [Fixnum] base
# @param [Array<String>] base
# @return [String]
@@ -47,4 +45,14 @@ def to_s(base=10)
original_to_s base
end
end
+end
+
+class Fixnum
+ alias_method :original_to_s, :to_s
+ remove_method :to_s
+end
+
+class Bignum
+ alias_method :original_to_s, :to_s
+ remove_method :to_s
end

0 comments on commit f6032da

Please sign in to comment.