nairda-ruby-util 0.1.0 → 0.1.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.
data/README CHANGED
@@ -10,3 +10,5 @@ So far the following functions are implemented:
10
10
  * Converting to percent with given decimal places.
11
11
  * Math
12
12
  * Calculating roots.
13
+ * Object
14
+ * Method for calling other methods that may not exist.
@@ -0,0 +1,6 @@
1
+ class Object
2
+ # Neat method for calling methods that might be undefined.
3
+ def try(method, *args)
4
+ send(method, *args) if respond_to?(method)
5
+ end
6
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
2
+
3
+ describe Object do
4
+ it 'should try to call existing method and return its result' do
5
+ 'Hai!'.try(:upcase).should eql('HAI!')
6
+ -666.try(:abs).should equal(666)
7
+ end
8
+
9
+ it 'should try to call non-existent method and return nil' do
10
+ 'Kitteh!'.try(:cheezburger).should be_nil
11
+ -666.try(:satanize).should be_nil
12
+ end
13
+
14
+ it 'should chain all methods and return the last result' do
15
+ ' oh hai '.try(:strip).try(:upcase).try(:<<, '!').should eql('OH HAI!')
16
+ -666.try(:abs).try(:+, 334).try(:*, 2).should equal(2000)
17
+ end
18
+
19
+ it 'should return nil when chaining non-existent methods' do
20
+ 'Kitteh!'.try(:downcase).try(:cheezburger).try(:squeeze).should be_nil
21
+ 1009.try(:+, 508).try(:blow_the_universe).try(:*, 666).should be_nil
22
+ end
23
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nairda-ruby-util
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Adrian Paca\xC5\x82a"
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-05-13 00:00:00 -07:00
12
+ date: 2008-05-14 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -27,17 +27,22 @@ files:
27
27
  - LICENSE
28
28
  - lib/ruby-util.rb
29
29
  - lib/ruby-util/math.rb
30
+ - lib/ruby-util/object.rb
30
31
  - lib/ruby-util/float.rb
31
32
  - lib/ruby-util/enumerable.rb
32
33
  - spec/unit/enumerable_spec.rb
33
34
  - spec/unit/math_spec.rb
34
35
  - spec/unit/float_spec.rb
36
+ - spec/unit/object_spec.rb
35
37
  - spec/spec_helper.rb
36
38
  has_rdoc: true
37
39
  homepage: http://github.com/nairda/ruby-util
38
40
  post_install_message:
39
41
  rdoc_options:
40
- - --line-numbers--inline-source--charsetutf-8
42
+ - --line-numbers
43
+ - --inline-source
44
+ - - --charset
45
+ - utf-8
41
46
  require_paths:
42
47
  - lib
43
48
  required_ruby_version: !ruby/object:Gem::Requirement