A ruby gem that adds some missing ::try_convert methods to classes where it could be useful.
The following defensive pattern is quite common:
if obj.respond_to? :to_int
i = obj.to_int
else
die
end
I believe it to be somewhat of an antipattern, compared to:
i = Integer.try_convert(obj) or die
Float.try_convert(obj)
Integer.try_convert(obj)
Proc.try_convert(obj)
We require all contributors to comply with the Developer Certificate of Origin. This ensures that all contributions are properly licensed and attributed.
This repository is subject to a Contributor Code of Conduct adapted from the Contributor Covenant, version 3.0, available at https://www.contributor-covenant.org/version/3/0/
This project is licensed under the ISC licence. See LICENSE for details
Copyright (c) 2014, Matthew Kerwin <matthew@kerwin.net.au> Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.