Hi,
I’d like to propose Fixnum#to_a:
class Fixnum
def to_a(base=10,min_length=0)
self.to_s(base).rjust(min_length).split(//).map { |c| c.to_i(base)
}
end
end
12345.to_a #=> [1,2,3,4,5]
42.to_a(2) #=> [1,0,1,0,1,0]
23.to_a(4,5) #=> [0,0,1,1,3]
-10.to_a #=> ???
This relies on to_s and therefore does not work with a base > 36. I
don’t know how this should word for negative numbers.
Maybe the default base should be 2 to be consistent with Fixnum#[]
Thoughts?
Viele Grü�e,
Levin