Reputation: 5
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?
Upvotes: 0
Views: 367
Reputation: 121000
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)
Upvotes: 2