try_convert 0.2 → 1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/try_convert.rb +23 -5
  3. metadata +11 -14
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 295a77533a94baaa07b4cf12beeb030f66122ee5ede92ef2f5f17a73155f748d
4
+ data.tar.gz: e8887b62a661ae449c52af3f9e62aff85e9f5e9f6826ad0ce78d0eae5a6dd43b
5
+ SHA512:
6
+ metadata.gz: ae2735848a41cd1b5b5c951cd86ef9c5d259d28984dd3cd59c74b1029d6769960b1f5c4b47f81fbaa9099bd39426e4d3476d5ec2c15bbcd47141c21ad271a4a7
7
+ data.tar.gz: b5fa56a30f802f65796f60a045211bb02cf7c8f88a5a81567f3896a551413c6b63d17b215ecf159452540612471d9841d44baf3395f745232914f235301c0ff2
@@ -1,28 +1,46 @@
1
1
 
2
- #
2
+ ##
3
3
  # Try to convert _obj_ into an Float, using Kernel::Float method.
4
4
  # Returns converted float or nil if _obj_ cannot be converted for any
5
5
  # reason.
6
6
  #
7
7
  def Float.try_convert obj
8
- Float(obj) rescue nil
8
+ Float(obj) rescue nil
9
9
  end
10
10
 
11
- #
11
+ ##
12
12
  # Try to convert _obj_ into an Integer, using Kernel::Integer method.
13
13
  # Returns converted integer or nil if _obj_ cannot be converted for
14
14
  # any reason.
15
15
  #
16
16
  def Integer.try_convert obj
17
- Integer(obj) rescue nil
17
+ Integer(obj) rescue nil
18
18
  end
19
19
 
20
+ ##
21
+ # Try to convert _obj_ into an Rational, using Kernel::Rational method.
22
+ # Returns converted Rational or nil if _obj_ cannot be converted for
23
+ # any reason.
20
24
  #
25
+ def Rational.try_convert obj
26
+ Rational(obj) rescue nil
27
+ end
28
+
29
+ ##
30
+ # Try to convert _obj_ into an Complex, using Kernel::Complex method.
31
+ # Returns converted Complex or nil if _obj_ cannot be converted for
32
+ # any reason.
33
+ #
34
+ def Complex.try_convert obj
35
+ Complex(obj) rescue nil
36
+ end
37
+
38
+ ##
21
39
  # Try to convert _obj_ into a Proc, using to_proc method.
22
40
  # Returns converted proc or nil if _obj_ cannot be converted for any
23
41
  # reason.
24
42
  #
25
43
  def Proc.try_convert obj
26
- obj.to_proc rescue nil
44
+ obj.to_proc rescue nil
27
45
  end
28
46
 
metadata CHANGED
@@ -1,17 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: try_convert
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
5
- prerelease:
4
+ version: '1.0'
6
5
  platform: ruby
7
6
  authors:
8
7
  - Matthew Kerwin
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-05-14 00:00:00.000000000 Z
11
+ date: 2019-12-06 00:00:00.000000000 Z
13
12
  dependencies: []
14
- description: Provides an equivalent to Regexp::try_convert fo several other core classes.
13
+ description: Provides ::try_convert to several core classes.
15
14
  email:
16
15
  - matthew@kerwin.net.au
17
16
  executables: []
@@ -19,29 +18,27 @@ extensions: []
19
18
  extra_rdoc_files: []
20
19
  files:
21
20
  - lib/try_convert.rb
22
- homepage: http://rubygems.org/gems/try_convert
21
+ homepage: https://rubygems.org/gems/try_convert
23
22
  licenses:
24
- - ISC License
23
+ - ISC
24
+ metadata: {}
25
25
  post_install_message:
26
26
  rdoc_options: []
27
27
  require_paths:
28
28
  - lib
29
29
  required_ruby_version: !ruby/object:Gem::Requirement
30
- none: false
31
30
  requirements:
32
- - - ! '>='
31
+ - - ">="
33
32
  - !ruby/object:Gem::Version
34
33
  version: '0'
35
34
  required_rubygems_version: !ruby/object:Gem::Requirement
36
- none: false
37
35
  requirements:
38
- - - ! '>='
36
+ - - ">="
39
37
  - !ruby/object:Gem::Version
40
38
  version: '0'
41
39
  requirements: []
42
- rubyforge_project:
43
- rubygems_version: 1.8.23.2
40
+ rubygems_version: 3.0.6
44
41
  signing_key:
45
- specification_version: 3
46
- summary: A less violent alternative to Integer(o)
42
+ specification_version: 4
43
+ summary: A ruby gem that adds some missing try_convert methods.
47
44
  test_files: []