Skip to content

A ruby gem that adds some missing ::try_convert methods to classes where it could be useful.

License

Notifications You must be signed in to change notification settings

phluid61/try_convert

Repository files navigation

Try Convert

A ruby gem that adds some missing ::try_convert methods to classes where it could be useful.

Rationale

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

New Methods

Float.try_convert(obj)

Integer.try_convert(obj)

Proc.try_convert(obj)

About

A ruby gem that adds some missing ::try_convert methods to classes where it could be useful.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages