File tree 2 files changed +21
-12
lines changed
spec/truffle/tags/core/kernel
truffle/src/main/ruby/core/rubinius/common
2 files changed +21
-12
lines changed Original file line number Diff line number Diff line change 1
- fails:Kernel#open is a private method
2
- fails:Kernel#open opens a file when given a valid filename
3
- fails:Kernel#open opens a file when called with a block
4
1
fails:Kernel#open opens an io when path starts with a pipe
5
2
fails:Kernel#open opens an io when called with a block
6
3
fails:Kernel#open opens an io for writing
7
- fails:Kernel#open raises an ArgumentError if not passed one argument
8
- fails:Kernel#open raises a TypeError if passed a non-String that does not respond to #to_open
9
- fails:Kernel#open accepts nil for mode and permission
10
- fails:Kernel#open when given an object that responds to to_open calls #to_path to covert the argument to a String before calling #to_str
11
- fails:Kernel#open when given an object that responds to to_open calls #to_str to convert the argument to a String
12
- fails:Kernel#open when given an object that responds to to_open calls #to_open on argument
13
- fails:Kernel#open when given an object that responds to to_open returns the value from #to_open
14
- fails:Kernel#open when given an object that responds to to_open passes its arguments onto #to_open
15
- fails:Kernel#open when given an object that responds to to_open passes the return value from #to_open to a block
Original file line number Diff line number Diff line change @@ -228,6 +228,27 @@ def tap
228
228
self
229
229
end
230
230
231
+ def open ( obj , *rest , &block )
232
+ if obj . respond_to? ( :to_open )
233
+ obj = obj . to_open ( *rest )
234
+
235
+ if block_given?
236
+ return yield ( obj )
237
+ else
238
+ return obj
239
+ end
240
+ end
241
+
242
+ path = Rubinius ::Type . coerce_to_path obj
243
+
244
+ if path . kind_of? String and path . prefix? '|'
245
+ return IO . popen ( path [ 1 ..-1 ] , *rest , &block )
246
+ end
247
+
248
+ File . open ( path , *rest , &block )
249
+ end
250
+ module_function :open
251
+
231
252
def p ( *a )
232
253
return nil if a . empty?
233
254
a . each { |obj | $stdout. puts obj . inspect }
You can’t perform that action at this time.
0 commit comments