I have this function from github or whatever:
class String
def to_bytes
(0...self.length/2).map {|i|self[i*2,2].to_i(16)}
end
end
and my point is, that I am not really sure what is the whole thing doing, especially the self[something] part and please can somebody help me to reverse this procedure? I am not experienced and I kind of desperately need to get those numbers back into string.
Thanks a lot
(0...self.length/2)returns a number that is half the string's length. (selfis a keyword that means, in the context of a method liketo_bytes, the string upon whichto_bytesis being requested.)maptakes the number (half the string's length), takes two characters from the string at a time, and converts each pair to hex, and places the result in an array.