Created
June 27, 2023 05:30
-
-
Save pmatsinopoulos/da7246906cc060e4cb6923f58404bca8 to your computer and use it in GitHub Desktop.
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
class IntegerToBinary | |
def initialize(integer) | |
@integer = integer | |
end | |
def binary | |
return integer.to_s if integer <= 1 | |
"#{IntegerToBinary.new(integer / 2).binary}#{integer % 2}" | |
end | |
private | |
attr_reader :integer | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment