ruby - How do I keep track of the iteration number while using each_char? -
I am learning Ruby and the idea of making a binary -> Decimal converter it becomes a binary string and the decimal equivalent Converts to. Is there a way to keep track of the current recurrence phase in Ruby so that the variable 'x' can be removed?
def convert (binary_string) decimal_equival = 0x = 0 binary_string.reverse. Do every_chitch | Binary | Decimal_form = + binary.t_i * (2 ** x) x + = 1 end return decimal decimal par value
Comments
Post a Comment