summaryrefslogtreecommitdiff
path: root/code/snippets/multiple_filenos.rb
diff options
context:
space:
mode:
Diffstat (limited to 'code/snippets/multiple_filenos.rb')
-rw-r--r--code/snippets/multiple_filenos.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/code/snippets/multiple_filenos.rb b/code/snippets/multiple_filenos.rb
new file mode 100644
index 0000000..aca4caf
--- /dev/null
+++ b/code/snippets/multiple_filenos.rb
@@ -0,0 +1,13 @@
+passwd = File.open('/etc/passwd')
+puts passwd.fileno
+
+hosts = File.open('/etc/hosts')
+puts hosts.fileno
+
+# Close the open passwd file. The frees up its file descriptor
+# number to be used by the next opened resource.
+passwd.close
+
+null = File.open('/dev/null')
+puts null.fileno
+