Tag: filesize

Ruby中的漂亮文件大小?

我正在尝试创建一个方法,将表示字节的整数转换为具有’prettied up’格式的字符串。 这是我的半工作尝试: class Integer def to_filesize { ‘B’ => 1024, ‘KB’ => 1024 * 1024, ‘MB’ => 1024 * 1024 * 1024, ‘GB’ => 1024 * 1024 * 1024 * 1024, ‘TB’ => 1024 * 1024 * 1024 * 1024 * 1024 }.each_pair { |e, s| return “#{s / self}#{e}” if self < s […]