Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't convert Fixnum to String #23

Closed
benpickles opened this issue Jan 19, 2011 · 2 comments
Closed

Can't convert Fixnum to String #23

benpickles opened this issue Jan 19, 2011 · 2 comments
Labels

Comments

@benpickles
Copy link

Assigning a numeric query values blows up with "Can't convert Fixnum into String" which seems counterintuitive:

uri = Addressable::URI.new
uri.query_values = { :c => 3 }
# => BANG!

Here's the offending code, I obviously need some Ruby education as I can't see why FixNum wouldn't have a to_str method.

@sporkmonger
Copy link
Owner

The #to_str method is an implicit coercion. It means, roughly, "Even though I'm not a String, you can pretend that I am if you like." Numbers don't have a #to_str method because they are not String-like. You should call #to_s on your number before passing it to this method. This method rejects Numeric values to avoid bugs with converting floating-point values to Strings incorrectly in an automatic fashion.

@benpickles
Copy link
Author

Sounds fair enough, thanks for the reply :)

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants