ruby-nuggets 0.2.1.246 → 0.2.2.247
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -1
- data/lib/nuggets/io/modes.rb +123 -0
- data/lib/nuggets/version.rb +1 -1
- metadata +6 -5
data/README
CHANGED
@@ -0,0 +1,123 @@
|
|
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 IO
|
29
|
+
|
30
|
+
# Inspired by Martin DeMello, [ruby-talk:307782] -- thx ;-)
|
31
|
+
|
32
|
+
class << self
|
33
|
+
|
34
|
+
alias_method :original_read, :read
|
35
|
+
|
36
|
+
# call-seq:
|
37
|
+
# IO.read(name, [length [, offset]]) => aString
|
38
|
+
# IO.read(name, binary = false) { |io| ... } => anObject
|
39
|
+
#
|
40
|
+
# Opens +name+ with mode +r+. NOTE: With no associated block,
|
41
|
+
# acts like the original IO::read, not like IO::new.
|
42
|
+
def read(name, *args, &block)
|
43
|
+
return original_read(name, *args) unless block
|
44
|
+
|
45
|
+
case args.size
|
46
|
+
when 0
|
47
|
+
# ok
|
48
|
+
when 1
|
49
|
+
case binary = args.first
|
50
|
+
when true, false, nil
|
51
|
+
# ok
|
52
|
+
else
|
53
|
+
raise TypeError, "wrong argument type #{binary.class} (expected boolean)"
|
54
|
+
end
|
55
|
+
else
|
56
|
+
raise ArgumentError, "wrong number of arguments (#{args.size + 1} for 1-2)"
|
57
|
+
end
|
58
|
+
|
59
|
+
open_with_mode(name, 'r', binary, &block)
|
60
|
+
end
|
61
|
+
|
62
|
+
# call-seq:
|
63
|
+
# IO.write(name, binary = false) => anIO
|
64
|
+
# IO.write(name, binary = false) { |io| ... } => anObject
|
65
|
+
#
|
66
|
+
# Opens +name+ with mode +w+.
|
67
|
+
def write(name, binary = false, &block)
|
68
|
+
open_with_mode(name, 'w', binary, &block)
|
69
|
+
end
|
70
|
+
|
71
|
+
# call-seq:
|
72
|
+
# IO.append(name, binary = false) => anIO
|
73
|
+
# IO.append(name, binary = false) { |io| ... } => anObject
|
74
|
+
#
|
75
|
+
# Opens +name+ with mode +a+.
|
76
|
+
def append(name, binary = false, &block)
|
77
|
+
open_with_mode(name, 'a', binary, &block)
|
78
|
+
end
|
79
|
+
|
80
|
+
# call-seq:
|
81
|
+
# IO.read_write(name, binary = false) => anIO
|
82
|
+
# IO.read_write(name, binary = false) { |io| ... } => anObject
|
83
|
+
#
|
84
|
+
# Opens +name+ with mode <tt>r+</tt>.
|
85
|
+
def read_write(name, binary = false, &block)
|
86
|
+
open_with_mode(name, 'r+', binary, &block)
|
87
|
+
end
|
88
|
+
|
89
|
+
# call-seq:
|
90
|
+
# IO.write_read(name, binary = false) => anIO
|
91
|
+
# IO.write_read(name, binary = false) { |io| ... } => anObject
|
92
|
+
#
|
93
|
+
# Opens +name+ with mode <tt>w+</tt>.
|
94
|
+
def write_read(name, binary = false, &block)
|
95
|
+
open_with_mode(name, 'w+', binary, &block)
|
96
|
+
end
|
97
|
+
|
98
|
+
# call-seq:
|
99
|
+
# IO.append_read(name, binary = false) => anIO
|
100
|
+
# IO.append_read(name, binary = false) { |io| ... } => anObject
|
101
|
+
#
|
102
|
+
# Opens +name+ with mode <tt>a+</tt>.
|
103
|
+
def append_read(name, binary = false, &block)
|
104
|
+
open_with_mode(name, 'a+', binary, &block)
|
105
|
+
end
|
106
|
+
|
107
|
+
private
|
108
|
+
|
109
|
+
# Just a helper to DRY things up.
|
110
|
+
def open_with_mode(name, mode, binary = false, &block)
|
111
|
+
mode << 'b' if binary
|
112
|
+
open(name, mode, &block)
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
if $0 == __FILE__
|
120
|
+
# File.read(__FILE__) { |f| ... }
|
121
|
+
# File.write(__FILE__) { |f| ... }
|
122
|
+
# File.append(__FILE__) { |f| ... }
|
123
|
+
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.2.
|
4
|
+
version: 0.2.2.247
|
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-
|
12
|
+
date: 2008-07-10 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -27,6 +27,7 @@ files:
|
|
27
27
|
- lib/nuggets/all.rb
|
28
28
|
- lib/nuggets/version.rb
|
29
29
|
- lib/nuggets/io/agrep.rb
|
30
|
+
- lib/nuggets/io/modes.rb
|
30
31
|
- lib/nuggets/file/which.rb
|
31
32
|
- lib/nuggets/integer/factorial.rb
|
32
33
|
- lib/nuggets/integer/to_binary_s.rb
|
@@ -70,15 +71,15 @@ has_rdoc: true
|
|
70
71
|
homepage: http://prometheus.rubyforge.org/ruby-nuggets
|
71
72
|
post_install_message:
|
72
73
|
rdoc_options:
|
73
|
-
- --
|
74
|
+
- --all
|
74
75
|
- --main
|
75
76
|
- README
|
77
|
+
- --line-numbers
|
76
78
|
- --inline-source
|
77
79
|
- --title
|
78
80
|
- ruby-nuggets Application documentation
|
79
81
|
- --charset
|
80
82
|
- UTF-8
|
81
|
-
- --all
|
82
83
|
require_paths:
|
83
84
|
- lib
|
84
85
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -96,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
97
|
requirements: []
|
97
98
|
|
98
99
|
rubyforge_project: prometheus
|
99
|
-
rubygems_version: 1.
|
100
|
+
rubygems_version: 1.2.0
|
100
101
|
signing_key:
|
101
102
|
specification_version: 2
|
102
103
|
summary: Some extensions to the Ruby programming language.
|