rb_ext 0.4.0 → 0.5.0

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.5.0
data/lib/rb_ext/array.rb CHANGED
@@ -157,6 +157,8 @@ module RbExt
157
157
  def arithmetic_mean
158
158
  inject(0) { |sum, val| sum + val.to_f } / length.to_f
159
159
  end
160
+ alias_method :average, :arithmetic_mean
161
+ alias_method :avg, :arithmetic_mean
160
162
 
161
163
  # Calculates the geographical mean of the values in the array
162
164
  # [http://en.wikipedia.org/wiki/Average#Geometric_mean]
@@ -189,8 +191,7 @@ module RbExt
189
191
  (inject(0) { |sum, val| sum + (val.to_f * val.to_f) } / length.to_f) ** (1.0 / 2.0)
190
192
  end
191
193
 
192
- # Calculates the mid range of the values in the array
193
- # by (max + min) / 2.0
194
+ # Calculates the mid range of the values in the array by (max + min) / 2.0
194
195
  # [http://en.wikipedia.org/wiki/Midrange]
195
196
  #
196
197
  # Example:
@@ -0,0 +1,46 @@
1
+ module RbExt
2
+ module Integer
3
+
4
+ # Returns an array with this Fixnum calculated as minutes (the first element)
5
+ # and seconds (the second element)
6
+ #
7
+ # Example:
8
+ # 3601.to_minutes_and_seconds # => [60, 1] meaning: 3601 seconds are 60 minutes and 1 second
9
+ #
10
+ def to_minutes_and_seconds
11
+ [self / 60, self % 60]
12
+ end
13
+
14
+ # Calculates the cross sum of this integer
15
+ #
16
+ # Example:
17
+ # 123.cross_sum # => 6
18
+ #
19
+ def cross_sum
20
+ _self = self; sum = 0
21
+
22
+ while _self > 0
23
+ sum += _self % 10
24
+ _self /= 10
25
+ end
26
+
27
+ return sum
28
+ end
29
+
30
+ # Calculates the cross product of this integer
31
+ #
32
+ # Example:
33
+ # 12345.cross_product # => 120
34
+ #
35
+ def cross_product
36
+ _self = self; product = 1
37
+
38
+ while _self > 0
39
+ product *= _self % 10
40
+ _self /= 10
41
+ end
42
+
43
+ return product
44
+ end
45
+ end
46
+ end
data/lib/rb_ext.rb CHANGED
@@ -2,6 +2,8 @@ $:.unshift(File.dirname(__FILE__))
2
2
 
3
3
  require "rb_ext/array"
4
4
  require "rb_ext/hash"
5
+ require "rb_ext/integer"
5
6
 
6
7
  Array.send :include, RbExt::Array
7
- Hash.send :include, RbExt::Hash
8
+ Hash.send :include, RbExt::Hash
9
+ Integer.send :include, RbExt::Integer
data/rb_ext.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rb_ext}
8
- s.version = "0.4.0"
8
+ s.version = "0.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Robert Neumayr"]
12
- s.date = %q{2011-04-28}
12
+ s.date = %q{2011-05-01}
13
13
  s.description = %q{Adds a bunch of methods to Ruby's Core Library, like Array#split or Hash#pick}
14
14
  s.email = %q{kontakt@icatcher.at}
15
15
  s.extra_rdoc_files = [
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
26
26
  "lib/rb_ext.rb",
27
27
  "lib/rb_ext/array.rb",
28
28
  "lib/rb_ext/hash.rb",
29
+ "lib/rb_ext/integer.rb",
29
30
  "rb_ext.gemspec",
30
31
  "test/helper.rb",
31
32
  "test/test_rb_ext_array.rb"
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 4
7
+ - 5
8
8
  - 0
9
- version: 0.4.0
9
+ version: 0.5.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Robert Neumayr
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-04-28 00:00:00 +02:00
17
+ date: 2011-05-01 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -79,6 +79,7 @@ files:
79
79
  - lib/rb_ext.rb
80
80
  - lib/rb_ext/array.rb
81
81
  - lib/rb_ext/hash.rb
82
+ - lib/rb_ext/integer.rb
82
83
  - rb_ext.gemspec
83
84
  - test/helper.rb
84
85
  - test/test_rb_ext_array.rb
@@ -96,7 +97,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
96
97
  requirements:
97
98
  - - ">="
98
99
  - !ruby/object:Gem::Version
99
- hash: -934454225
100
+ hash: -891889955
100
101
  segments:
101
102
  - 0
102
103
  version: "0"