try_convert 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/try_convert.rb +19 -0
  2. metadata +47 -0
@@ -0,0 +1,19 @@
1
+
2
+ #
3
+ # Try to convert _obj_ into an Float, using Kernel::Float method.
4
+ # Returns converted float or nil if _obj_ cannot be converted for any
5
+ # reason.
6
+ #
7
+ def Float.try_convert obj
8
+ Float(obj) rescue nil
9
+ end
10
+
11
+ #
12
+ # Try to convert _obj_ into an Integer, using Kernel::Integer method.
13
+ # Returns converted integer or nil if _obj_ cannot be converted for
14
+ # any reason.
15
+ #
16
+ def Integer.try_convert obj
17
+ Integer(obj) rescue nil
18
+ end
19
+
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: try_convert
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Matthew Kerwin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-05-14 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Provides an equivalent to Regexp::try_convert fo several other core classes.
15
+ email:
16
+ - matthew@kerwin.net.au
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/try_convert.rb
22
+ homepage: http://rubygems.org/gems/try_convert
23
+ licenses:
24
+ - ISC License
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 1.8.23.2
44
+ signing_key:
45
+ specification_version: 3
46
+ summary: A less violent alternative to Integer(o)
47
+ test_files: []