ruby-nuggets 0.1.5.232 → 0.1.6.233

Sign up to get free protection for your applications and to get access to all the features.
data/HEADER ADDED
@@ -0,0 +1,27 @@
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
+
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to ruby-nuggets version 0.1.5
5
+ This documentation refers to ruby-nuggets version 0.1.6
6
6
 
7
7
 
8
8
  == DESCRIPTION
@@ -33,7 +33,7 @@ class Integer
33
33
  # call-seq:
34
34
  # int.factorial => anInteger
35
35
  #
36
- # Calculate the factorial of +int+. To use the memoized version:
36
+ # Calculate the factorial of _int_. To use the memoized version:
37
37
  # <tt>Integer.send(:alias_method, :factorial, :factorial_memoized)</tt>
38
38
  def factorial
39
39
  (1..self).inject { |f, i| f * i }
@@ -42,7 +42,7 @@ class Integer
42
42
  # call-seq:
43
43
  # int.factorial_memoized => anInteger
44
44
  #
45
- # Calculate the factorial of +int+ with the help of memoization (Which gives
45
+ # Calculate the factorial of _int_ with the help of memoization (Which gives
46
46
  # a considerable speedup for repeated calculations -- at the cost of memory).
47
47
  #
48
48
  # WARNING: Don't try to calculate the factorial this way for a too large
@@ -0,0 +1,47 @@
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 Integer
29
+
30
+ # call-seq:
31
+ # int.to_binary_s => aString
32
+ # int.to_binary_s(length) => aString
33
+ #
34
+ # Returns _int_ as binary number string; optionally zero-padded to +length+.
35
+ def to_binary_s(length = nil)
36
+ "%0#{length}d" % to_s(2)
37
+ end
38
+
39
+ end
40
+
41
+ if $0 == __FILE__
42
+ [20000, 800, 300, 700, 130, 480, 9999, 9999, 25000].each { |i|
43
+ p i
44
+ p i.to_binary_s
45
+ p i.to_binary_s(32)
46
+ }
47
+ end
@@ -0,0 +1,47 @@
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.between(min, max) => aNumeric
32
+ #
33
+ # Cuts _num_ to the (inclusive) range of +min+ to +max+.
34
+ def between(min, max)
35
+ min, max = max, min if max < min
36
+
37
+ self < min ? min : self > max ? max : self
38
+ end
39
+
40
+ end
41
+
42
+ if $0 == __FILE__
43
+ [123, -123, 0, 0.001, 1.23, -12.3].each { |n|
44
+ p n
45
+ p n.between(0, 10)
46
+ }
47
+ end
@@ -30,7 +30,7 @@ class Numeric
30
30
  # call-seq:
31
31
  # num.signum => -1, 0, 1
32
32
  #
33
- #
33
+ # Returns the sign of _num_.
34
34
  def signum
35
35
  self > 0 ? 1 : self < 0 ? -1 : 0
36
36
  end
@@ -0,0 +1,66 @@
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
+ require File.join(File.dirname(__FILE__), '..', 'integer', 'to_binary_s')
29
+
30
+ class Integer
31
+
32
+ # call-seq:
33
+ # int.to_dotted_decimal => aString
34
+ #
35
+ # Converts _int_ to dotted-decimal notation.
36
+ def to_dotted_decimal
37
+ to_binary_s(32).unpack('a8' * 4).map { |s| s.to_i(2) }.join('.')
38
+ end
39
+
40
+ end
41
+
42
+ class String
43
+
44
+ # call-seq:
45
+ # str.from_dotted_decimal => anInteger
46
+ #
47
+ # Converts _str_ from dotted-decimal notation to integer.
48
+ def from_dotted_decimal
49
+ split('.').map { |i| i.to_i.to_binary_s(8) }.join.to_i(2)
50
+ end
51
+
52
+ end
53
+
54
+ if $0 == __FILE__
55
+ [2294967042, 4294967040].each { |i|
56
+ p i.to_binary_s(32)
57
+ p i.to_dotted_decimal
58
+ }
59
+
60
+ puts '#' * 34
61
+
62
+ %w[77.47.161.3 196.101.53.1].each { |s|
63
+ p s
64
+ p s.from_dotted_decimal.to_binary_s(32)
65
+ }
66
+ end
@@ -4,7 +4,7 @@ module Nuggets
4
4
 
5
5
  MAJOR = 0
6
6
  MINOR = 1
7
- TINY = 5
7
+ TINY = 6
8
8
 
9
9
  class << self
10
10
 
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.5.232
4
+ version: 0.1.6.233
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-09 00:00:00 +02:00
12
+ date: 2008-04-22 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -24,54 +24,58 @@ extra_rdoc_files:
24
24
  - ChangeLog
25
25
  - README
26
26
  files:
27
- - lib/nuggets/all.rb
28
- - lib/nuggets/version.rb
29
- - lib/nuggets/file/which.rb
27
+ - lib/nuggets/integer/to_binary_s.rb
30
28
  - lib/nuggets/integer/factorial.rb
31
- - lib/nuggets/array/to_hash.rb
32
- - lib/nuggets/array/shuffle.rb
33
- - lib/nuggets/array/format.rb
34
- - lib/nuggets/array/in_order.rb
35
- - lib/nuggets/array/combination.rb
36
- - lib/nuggets/array/flatten_once.rb
37
- - lib/nuggets/array/rand.rb
38
- - lib/nuggets/array/monotone.rb
39
- - lib/nuggets/uri/exist.rb
40
- - lib/nuggets/uri/content_type.rb
41
- - lib/nuggets/proc/bind.rb
42
- - lib/nuggets/string/word_wrap.rb
29
+ - lib/nuggets/version.rb
30
+ - lib/nuggets/object/singleton_class.rb
31
+ - lib/nuggets/object/blank.rb
32
+ - lib/nuggets/enumerable/minmax.rb
33
+ - lib/nuggets/all.rb
34
+ - lib/nuggets/string/sub_with_md.rb
43
35
  - lib/nuggets/string/msub.rb
44
36
  - lib/nuggets/string/case.rb
45
- - lib/nuggets/string/sub_with_md.rb
46
37
  - lib/nuggets/string/evaluate.rb
38
+ - lib/nuggets/string/word_wrap.rb
47
39
  - lib/nuggets/string/nsub.rb
48
40
  - lib/nuggets/string/capitalize_first.rb
49
- - lib/nuggets/object/blank.rb
50
- - lib/nuggets/object/singleton_class.rb
41
+ - lib/nuggets/hash/in_order.rb
42
+ - lib/nuggets/hash/insert.rb
43
+ - lib/nuggets/proc/bind.rb
44
+ - lib/nuggets/array/rand.rb
45
+ - lib/nuggets/array/to_hash.rb
46
+ - lib/nuggets/array/flatten_once.rb
47
+ - lib/nuggets/array/in_order.rb
48
+ - lib/nuggets/array/shuffle.rb
49
+ - lib/nuggets/array/monotone.rb
50
+ - lib/nuggets/array/format.rb
51
+ - lib/nuggets/array/combination.rb
52
+ - lib/nuggets/numeric/between.rb
51
53
  - lib/nuggets/numeric/signum.rb
52
- - lib/nuggets/util/i18n.rb
53
54
  - lib/nuggets/util/ansicolor2css.rb
54
55
  - lib/nuggets/util/content_type.rb
55
- - lib/nuggets/enumerable/minmax.rb
56
- - lib/nuggets/hash/in_order.rb
57
- - lib/nuggets/hash/insert.rb
56
+ - lib/nuggets/util/dotted_decimal.rb
57
+ - lib/nuggets/util/i18n.rb
58
+ - lib/nuggets/file/which.rb
59
+ - lib/nuggets/uri/content_type.rb
60
+ - lib/nuggets/uri/exist.rb
58
61
  - COPYING
59
- - Rakefile
62
+ - HEADER
60
63
  - README
61
64
  - ChangeLog
65
+ - Rakefile
62
66
  has_rdoc: true
63
67
  homepage: http://prometheus.rubyforge.org/ruby-nuggets
64
68
  post_install_message:
65
69
  rdoc_options:
70
+ - --line-numbers
66
71
  - --inline-source
67
72
  - --title
68
73
  - ruby-nuggets Application documentation
69
- - --main
70
- - README
71
74
  - --charset
72
75
  - UTF-8
76
+ - --main
77
+ - README
73
78
  - --all
74
- - --line-numbers
75
79
  require_paths:
76
80
  - lib
77
81
  required_ruby_version: !ruby/object:Gem::Requirement