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

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -