Sha256: 96eb26029423bb558e152ee5adb5aea1ac877769d1ad61a3271fabef2df39e11

Contents?: true

Size: 471 Bytes

Versions: 1

Compression:

Stored size: 471 Bytes

Contents

require 'tempfile'
require 'socket'

module Dklet::Util
  module_function

  def tmpfile_for(str, prefix: 'dklet-tmp')
    file = Tempfile.new(prefix)
    file.write str
    file.close # save to disk
    # unlink清理问题:引用进程结束时自动删除?👍 
    file.path
  end

  def human_timestamp(t = Time.now)
    t.strftime("%Y%m%d%H%M%S")
  end

  def host_ip
    Socket.ip_address_list.find { |ai| ai.ipv4? && !ai.ipv4_loopback? }.ip_address
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dklet-0.1.4 lib/dklet/util.rb