ruby-nuggets 0.1.6.233 → 0.1.7.234
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 +1 -1
- data/lib/nuggets/numeric/signum.rb +13 -1
- data/lib/nuggets/numeric/to_multiple.rb +68 -0
- data/lib/nuggets/version.rb +1 -1
- metadata +7 -6
data/README
CHANGED
@@ -27,12 +27,24 @@
|
|
27
27
|
|
28
28
|
class Numeric
|
29
29
|
|
30
|
+
def positive?
|
31
|
+
self > 0
|
32
|
+
end
|
33
|
+
|
34
|
+
def negative?
|
35
|
+
self < 0
|
36
|
+
end
|
37
|
+
|
38
|
+
def non_negative?
|
39
|
+
!negative?
|
40
|
+
end
|
41
|
+
|
30
42
|
# call-seq:
|
31
43
|
# num.signum => -1, 0, 1
|
32
44
|
#
|
33
45
|
# Returns the sign of _num_.
|
34
46
|
def signum
|
35
|
-
|
47
|
+
positive? ? 1 : negative? ? -1 : 0
|
36
48
|
end
|
37
49
|
|
38
50
|
alias_method :sign, :signum
|
@@ -0,0 +1,68 @@
|
|
1
|
+
#--
|
2
|
+
###############################################################################
|
3
|
+
# #
|
4
|
+
# A component of ruby-nuggets, some extensions to the Ruby programming #
|
5
|
+
# language. #
|
6
|
+
# #
|
7
|
+
# Copyright (C) 2007-2008 Jens Wille #
|
8
|
+
# #
|
9
|
+
# Authors: #
|
10
|
+
# Jens Wille <jens.wille@uni-koeln.de> #
|
11
|
+
# #
|
12
|
+
# ruby-nuggets is free software; you can redistribute it and/or modify it #
|
13
|
+
# under the terms of the GNU General Public License as published by the Free #
|
14
|
+
# Software Foundation; either version 3 of the License, or (at your option) #
|
15
|
+
# any later version. #
|
16
|
+
# #
|
17
|
+
# ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT #
|
18
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
20
|
+
# more details. #
|
21
|
+
# #
|
22
|
+
# You should have received a copy of the GNU General Public License along #
|
23
|
+
# with ruby-nuggets. If not, see <http://www.gnu.org/licenses/>. #
|
24
|
+
# #
|
25
|
+
###############################################################################
|
26
|
+
#++
|
27
|
+
|
28
|
+
class Numeric
|
29
|
+
|
30
|
+
# call-seq:
|
31
|
+
# num.to_multiple_of(target, what) => aNumeric
|
32
|
+
#
|
33
|
+
# Returns the nearest multiple of +target+ according to +what+.
|
34
|
+
def to_multiple_of(target, what = :round)
|
35
|
+
(to_f / target).send(what) * target
|
36
|
+
end
|
37
|
+
|
38
|
+
# call-seq:
|
39
|
+
# num.round_to(target) => aNumeric
|
40
|
+
#
|
41
|
+
# Rounds _num_ to the nearest multiple of +target+.
|
42
|
+
def round_to(target)
|
43
|
+
to_multiple_of(target, :round)
|
44
|
+
end
|
45
|
+
|
46
|
+
# call-seq:
|
47
|
+
# num.floor_to(target) => aNumeric
|
48
|
+
#
|
49
|
+
# Returns the largest multiple of +target+ less than or equal to _num_.
|
50
|
+
def floor_to(target)
|
51
|
+
to_multiple_of(target, :floor)
|
52
|
+
end
|
53
|
+
|
54
|
+
# call-seq:
|
55
|
+
# num.ceil_to(target) => aNumeric
|
56
|
+
#
|
57
|
+
# Returns the smallest multiple of +target+ greater than or equal to _num_.
|
58
|
+
def ceil_to(target)
|
59
|
+
to_multiple_of(target, :ceil)
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
if $0 == __FILE__
|
65
|
+
[123, -123, 0, 0.001, 5.67, -12.3].each { |n|
|
66
|
+
p [n, n.round_to(10), n.floor_to(10), n.ceil_to(10)]
|
67
|
+
}
|
68
|
+
end
|
data/lib/nuggets/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-nuggets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7.234
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jens Wille
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-04-
|
12
|
+
date: 2008-04-25 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -51,6 +51,7 @@ files:
|
|
51
51
|
- lib/nuggets/array/combination.rb
|
52
52
|
- lib/nuggets/numeric/between.rb
|
53
53
|
- lib/nuggets/numeric/signum.rb
|
54
|
+
- lib/nuggets/numeric/to_multiple.rb
|
54
55
|
- lib/nuggets/util/ansicolor2css.rb
|
55
56
|
- lib/nuggets/util/content_type.rb
|
56
57
|
- lib/nuggets/util/dotted_decimal.rb
|
@@ -68,14 +69,14 @@ homepage: http://prometheus.rubyforge.org/ruby-nuggets
|
|
68
69
|
post_install_message:
|
69
70
|
rdoc_options:
|
70
71
|
- --line-numbers
|
72
|
+
- --all
|
71
73
|
- --inline-source
|
72
74
|
- --title
|
73
75
|
- ruby-nuggets Application documentation
|
74
|
-
- --charset
|
75
|
-
- UTF-8
|
76
76
|
- --main
|
77
77
|
- README
|
78
|
-
- --
|
78
|
+
- --charset
|
79
|
+
- UTF-8
|
79
80
|
require_paths:
|
80
81
|
- lib
|
81
82
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -93,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
94
|
requirements: []
|
94
95
|
|
95
96
|
rubyforge_project: prometheus
|
96
|
-
rubygems_version: 1.1.
|
97
|
+
rubygems_version: 1.1.1
|
97
98
|
signing_key:
|
98
99
|
specification_version: 2
|
99
100
|
summary: Some extensions to the Ruby programming language.
|