Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Commit

Permalink
modify base method name
Browse files Browse the repository at this point in the history
  • Loading branch information
kachick committed Aug 21, 2012
1 parent 011ee81 commit aa35e4f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/integer/base/singleton_class.rb
Expand Up @@ -26,14 +26,16 @@ def parse(str, chars)
# @param [#to_int] num # @param [#to_int] num
# @param [Array<#to_sym>] chars # @param [Array<#to_sym>] chars
# @return [String] # @return [String]
def convert_to_string(num, chars) def string_for(num, chars)
case chars.length case chars.length
when 1 when 1
convert_to_string_unary num, chars.first convert_to_string_unary num, chars.first
else else
convert_to_string_positional num, chars convert_to_string_positional num, chars
end end
end end

alias_method :convert_to_string, :string_for


private private


Expand Down Expand Up @@ -118,7 +120,7 @@ def parse_unary_abs(str, char)
end end


# @return [String] # @return [String]
def convert_to_string_positional(num, chars) def string_positional_for(num, chars)
chars = base_chars_for chars chars = base_chars_for chars
int = num.to_int int = num.to_int
base = chars.length base = chars.length
Expand All @@ -136,16 +138,20 @@ def convert_to_string_positional(num, chars)
s.insert 0, '-' if int < 0 s.insert 0, '-' if int < 0
} }
end end

alias_method :convert_to_string_positional, :string_positional_for


# @return [String] # @return [String]
def convert_to_string_unary(num, char) def string_unary_for(num, char)
char = unary_char_for char char = unary_char_for char
int = num.to_int int = num.to_int


(char.to_s * int.abs).tap {|s| (char.to_s * int.abs).tap {|s|
s.insert 0, '-' if int < 0 s.insert 0, '-' if int < 0
} }
end end

alias_method :convert_to_string_unary, :string_unary_for


end end


Expand Down

0 comments on commit aa35e4f

Please sign in to comment.