File: example_pathname.rb

package info (click to toggle)
ruby-pathname2 1.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 312 kB
  • sloc: ruby: 2,033; makefile: 2
file content (25 lines) | stat: -rw-r--r-- 720 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
########################################################################
# example_pathname.rb
#
# Some examples to demonstrate the behavior of the pathname2 library.
########################################################################
require 'pathname2'

puts "VERSION: " + Pathname::VERSION

path1 = Pathname.new("foo/bar")
path2 = Pathname.new("baz/blah")

path3 = Pathname.new("foo/../bar")
path4 = Pathname.new("../baz")

p path1 + path2 # foo/bar/baz/blah
p path3 + path4 # baz

# Shortcut syntax
path = pn{ "C:\\Documents and Settings\\snoopy\\My Documents" }

p path[0]    # C:
p path[1]    # Documents and Settings
p path[0,2]  # C:\\Documents and Settings
p path[0..2] # C:\\Documents and Settings\\snoopy