Class: Object

Inherits:
BasicObject
Defined in:
lib/judges/to_rel.rb

Overview

Adding method to_rel to all Ruby objects.

Author

Yegor Bugayenko ([email protected])

Copyright

Copyright © 2024-2025 Yegor Bugayenko

License

MIT

Instance Method Summary collapse

Instance Method Details

#to_relString

Generates a relative name of a file (to the current dir).

Returns:

  • (String)

    Relative path to the file with optional quotes if it contains spaces



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/judges/to_rel.rb', line 15

def to_rel
  s = File.absolute_path(to_s)
  p = Pathname.new(s).relative_path_from(Dir.getwd)
  t = p.to_s
  t = s if t.length > s.length
  t = "\"#{t}\"" if t.include?(' ')
  if p.directory?
    "#{t}/"
  else
    t
  end
end