module M_公共函数

Public Class Methods

多色显示(字符,颜色,背景,显示控制) click to toggle source
# File lib/wxl_function.rb, line 24
def 多色显示(字符,颜色,背景,显示控制)
  颜色码=''
  case 颜色
  when "黑色"
    颜色码='30'
  when "红色"
    颜色码='31'
  when "绿色"
    颜色码='32'
  when "黄色"
    颜色码='33'
  when "蓝色"
    颜色码='34'
  when "紫色"
    颜色码='35'
  when "青色"
    颜色码='36'
  when "灰色"
    颜色码='37'
  when "白色"
    颜色码='38'
  else
    颜色码='38' #默认白色
  end 
    
  背景码=''
  case 背景
  when "黑色"
    背景码='40'
  when "红色"
    背景码='41'
  when "绿色"
    背景码='42'
  when "黄色"
    背景码='43'
  when "蓝色"
    背景码='44'
  when "紫色"
    背景码='45'
  when "青色"
    背景码='46'
  when "灰色"
    背景码='47'
  else
    背景码='40' #默认黑色
  end

  控制码=''
  case 显示控制
  when "高亮"
    控制码='01'
  when "下划线"
    控制码='04'
  when "闪烁"
    控制码='05'
  else
    控制码='01' #默认黑色
  end
  
  return "\033[#{颜色码};#{背景码}m\33[#{控制码}m#{字符}\033[0m"
end
退出消息(消息) click to toggle source
# File lib/wxl_function.rb, line 6
def 退出消息(消息)
  puts "#{消息}"
  exit
end
随机字符串(长度=3) click to toggle source
# File lib/wxl_function.rb, line 11
def 随机字符串(长度=3)
  arr=("a".."z").to_a
  char=''
  长度.times {
    char += arr[Random.new.rand(26)]
  }
  char
end
随机数字(最大值=100) click to toggle source
# File lib/wxl_function.rb, line 20
def 随机数字(最大值=100)
  Random.new.rand 最大值
end

Private Instance Methods

多色显示(字符,颜色,背景,显示控制) click to toggle source
# File lib/wxl_function.rb, line 24
def 多色显示(字符,颜色,背景,显示控制)
  颜色码=''
  case 颜色
  when "黑色"
    颜色码='30'
  when "红色"
    颜色码='31'
  when "绿色"
    颜色码='32'
  when "黄色"
    颜色码='33'
  when "蓝色"
    颜色码='34'
  when "紫色"
    颜色码='35'
  when "青色"
    颜色码='36'
  when "灰色"
    颜色码='37'
  when "白色"
    颜色码='38'
  else
    颜色码='38' #默认白色
  end 
    
  背景码=''
  case 背景
  when "黑色"
    背景码='40'
  when "红色"
    背景码='41'
  when "绿色"
    背景码='42'
  when "黄色"
    背景码='43'
  when "蓝色"
    背景码='44'
  when "紫色"
    背景码='45'
  when "青色"
    背景码='46'
  when "灰色"
    背景码='47'
  else
    背景码='40' #默认黑色
  end

  控制码=''
  case 显示控制
  when "高亮"
    控制码='01'
  when "下划线"
    控制码='04'
  when "闪烁"
    控制码='05'
  else
    控制码='01' #默认黑色
  end
  
  return "\033[#{颜色码};#{背景码}m\33[#{控制码}m#{字符}\033[0m"
end
退出消息(消息) click to toggle source
# File lib/wxl_function.rb, line 6
def 退出消息(消息)
  puts "#{消息}"
  exit
end
随机字符串(长度=3) click to toggle source
# File lib/wxl_function.rb, line 11
def 随机字符串(长度=3)
  arr=("a".."z").to_a
  char=''
  长度.times {
    char += arr[Random.new.rand(26)]
  }
  char
end
随机数字(最大值=100) click to toggle source
# File lib/wxl_function.rb, line 20
def 随机数字(最大值=100)
  Random.new.rand 最大值
end