3 ms·
This is quite a cool idea: >>> path('a') / 'b' / 'c' path('a/b/c') It would be fun to have that in Ruby!
by nathan_f77 14y ago
This is quite a cool idea:
>>> path('a') / 'b' / 'c'
path('a/b/c')
It would be fun to have that in Ruby!
- mattdeboard 14y agoAlright, let me say that I do not like this part of path. Operator overloading is fine, I mean the + is overloaded all to hell. But seeing the division symbol in weird places in a project I took over was distracting first, then irritating, and by the time I figured out what was going on I did not want it despite seeing some benefit.
- draegtun 14y agoI agree. It reminds me of FancyRoutes which I also found off putting - http://news.ycombinator.com/item?id=1100248 http://news.ycombinator.com/item?id=1100248 Path.py may already do it (docs are limited so I'm not sure) but something like below would be better: my $foo = dir('a', 'b', 'c'); This is how Path::Class works in Perl (https://metacpan.org/module/Path::Class https://metacpan.org/module/Path::Class). This way the path is a filesystem agnostic directory object. NB. Twisting operator overloading isn't all bad though. For eg. IO:All nearly gets it all right and being a little mad I will sometimes use it :) https://metacpan.org/module/IO::All https://metacpan.org/module/IO::All
- ekimekim 14y agoI actually wrote up a module a while ago, what it did was in ways similar to path: >>> print SimpleFS('a').b.c a/b/c The bigger thing (and original purpose) was uses like this: >>> root = SimpleFS("/") >>> sda_size = root.sys.block.sda.size >>> for fd in root.proc.self.fd: ... os.close(int(fd)) >>> root.var.log[sys.argv[0] + ".log"] += "Size of disk: %d" % sda_size