0

I am trying to convert a decimal to binary, so I came up with this:

print "Enter decimal here: "
decimal = gets.chomp
puts decimal.to_s(2)
#>> wrong number of arguments (given 1, expected 0)
#>> (repl):3:in 'to_s'

Can someone tell me what I am doing wrong?

1 Answer 1

2

decimal comes from stdin as a string. And String#to_s does not accept arguments. You should do instead:

puts decimal.to_i.to_s(2)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.