Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/judges/to_rel.rb
Overview
Adding method to_rel
to all Ruby objects.
- Author
-
Yegor Bugayenko (yegor256@gmail.com)
- Copyright
-
Copyright © 2024 Yegor Bugayenko
- License
-
MIT
Instance Method Summary collapse
-
#to_rel ⇒ Object
Generates a relative name of a file (to the current dir).
Instance Method Details
#to_rel ⇒ Object
Generates a relative name of a file (to the current dir).
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/judges/to_rel.rb', line 31 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 |