class PPZ::Func

Public Class Methods

class_has_const?(instance, const_name) click to toggle source

检查某实例的类有没有某常量

# File lib/func/util.rb, line 17
def class_has_const? instance, const_name
  has_const? instance.class, const_name
end
has_const?(klass, const_name) click to toggle source

检查某类有没有某常量

# File lib/func/util.rb, line 13
def has_const? klass, const_name
  klass.constants.include? const_name
end
write_to_file(filepath, data) click to toggle source
# File lib/func/util.rb, line 3
def write_to_file filepath, data
  if File.exist? filepath
    throw '文件已存在'
  end
  file = File.new filepath, mode: 'w:UTF-8'
  file.print data
  file.close
end