单进程:

require 'pidfile'
PidFile.new

多进程:

require 'pidfile'
param = ARGV[0]
PidFile.new(:pidfile => param)

官方文档: https://github.com/samullen/pidfile

定义类方法别名


class Foo
  class << self
    def bar
      puts 'bar'
    end
  end
end

Foo.bar #output: 'bar'

方法别名

class Foo
  def bar
    puts 'bar'
  end
  alias :bar2 :bar
end

Foo.bar2 #outpu: 'bar'

require 'pry'

class A
  def hello() puts "hello world!" end
end

a = A.new

# set x to 10
x = 10
y = rand

# start a REPL session
binding.pry#在这设置断点,然后打印上边的各种变量


# program resumes here (after pry session)
puts "program resumes here. Value of x is: #{x},and Y is #{y}."

https://github.com/pry/pry/wiki/User-Input http://pryrepl.org

myVarArrays #camel caps
my_var_arrays #underscore(snake)
my.var.arrays # dot separated

require 'httparty'
class PZ
  include HTTParty
  debug_output $stderr #开启debug模式, 平时可注释掉

  def run
    self.class.post("https://",
      :body=> {
        "param1" => "value1",
        "param2" => "value2"
    )
  end
end

Pin.new.run