Use sprintf("%08b", num) to convert input to binary number
#!/usr/bin/env ruby module Binary def Binary.to_bin( num ) bin = sprintf("%08b", num) end end p Binary.to_bin( 123 ) # => "01111011"