Created
October 5, 2011 22:22
-
-
Save wulftone/1265920 to your computer and use it in GitHub Desktop.
Extending String and Array with bitmask helpers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Convert a number in a string to a different base (stolen from stackoverflow.com) | |
class String | |
def convert_base(from, to) | |
self.to_i(from).to_s(to) | |
end | |
end | |
# Convert an array to it's maximum value if it were representing binary and filled with 1's | |
class Array | |
def max_bitmask | |
self.map{1}.join().convert_base(2,10).to_i | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment