Learn ruby
目录
ruby_tour
sudo apt-get install ruby-full ruby -v ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux-gnu] evan@myxps:~/lx/ssh/intra$ 交互式 Ruby(IRb) 交互式 Ruby(IRb)为体验提供了一个 shell。在 IRb shell 内,您可以逐行立即查看解释结果。 这个工具会随着 Ruby 的安装自动带有,所以您不需要做其他额外的事情,IRb 即可正常工作。 只需要在命令提示符中键入 irb,一个交互式 Ruby Session 将会开始, intra$ irb irb(main):001:0> puts "hey evan" hey evan => nil * base 20分钟学会Ruby evan@myxps:~$ irb irb(main):001:0> 3+2 => 5 irb(main):002:0> 3*4 => 12 irb(main):003:0> 3**2 => 9 irb(main):004:0> Math.sqrt(9) => 3.0 方法 function rb(main):005:0> def h irb(main):006:1* puts "hey ruby" irb(main):007:0> end => :h irb(main):008:0> h hey ruby => nil irb(main):009:1* def h(name) irb(main):010:1* puts "hello #{name}" irb(main):011:0> end => :h irb(main):012:0> h("eva") hello eva => nil irb(main):014:1* def h(name="world") irb(main):015:1* puts "hello #{name.capitalize}!" irb(main):016:0> end => :h 如果不输入参数,那么就会使用默认参数world。 irb(main):017:0> h "evan" hello Evan! => nil irb(main):018:0> h hello World! => nil irb(main):019:1* class Greeter irb(main):020:2* def initialize(name = "world") irb(main):021:2* @name = name irb(main):022:1* end irb(main):023:2* def say_hi irb(main):024:2* puts "HI #{@name}!" irb(main):025:1* end irb(main):026:2* def say_bye irb(main):027:2* puts "bye #{@name}. come back soon." irb(main):028:1* end irb(main):029:0> end => :say_bye 这里有一个新的关键词class,图中定义了一个名叫Greeter的类,里面有一些方法。注意这里的name,现在是一个实例变量,它对于Greeter中的所有类都是可用的。 irb(main):013:0> g = Greeter.new("pat") irb(main):014:0> g.say_hi HI pat! => nil irb(main):015:0> g.say_bye bye pat. come back soon. => nil irb(main):016:0> g.@name Traceback (most recent call last): 3: from /usr/bin/irb:23:in `<main>' 2: from /usr/bin/irb:23:in `load' 1: from /usr/lib/ruby/gems/2.7.0/gems/irb-1.2.3/exe/irb:11:in `<top (required)>' SyntaxError ((irb):16: syntax error, unexpected instance variable) g.@name ^~~~~ 对象内部 rb(main):017:0> Greeter.instance_methods => [:say_hi, :say_bye, :dup, :itself, :yield_self, :then, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :frozen?, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :instance_variables, :instance_variable_get, :instance_variable_set, :instance_variable_defined?, :remove_instance_variable, :instance_of?, :kind_of?, :is_a?, :tap, :clone, :display, :hash, :class, :singleton_class, :public_send, :method, :public_method, :singleton_method, :define_singleton_method, :extend, :to_enum, :enum_for, :<=>, :===, :=~, :!~, :nil?, :eql?, :respond_to?, :freeze, :inspect, :object_id, :send, :to_s, :__send__, :!, :==, :!=, :equal?, :__id__, :instance_eval, :instance_exec] 这里有好多方法,但我们只定义了两个方法,这里是怎么回事呢?这是对象Greeter的全部方法,一个完整的列表,包含了父类定义的一些方法。如果要列出定义在Greeter中的且不包含父类的方法,那就使用参数false: Greeter.instance_methods(false) => [:say_hi, :say_bye] irb(main):019:0> g.respond_to?("say_hi") => true
ruboo
irb irb(main):001:1* def hello irb(main):002:1* out = "hello world" irb(main):003:1* puts out irb(main):004:0> end => :hello irb(main):005:0> hello hello world => nil
Ruby 范围(Range)here
https://www.runoob.com/ruby/ruby-encoding.html
ruby and devops
ruby rails 做的运维管理系统
Rails 的 CMS 内容管理系统
jenkins and ruby
https://rubygems.org/gems/jenkins_api_client/versions/1.5.3
https://joachim8675309.medium.com/jenkins-ci-pipeline-with-ruby-62017469c7c9
ruby rspec+jenkins+ci_report持续集成生成junit测试报告
Ruby API wrappers
https://www.jenkins.io/doc/book/using/remote-access-api/
https://github.com/arangamani/jenkins_api_client
vim getjobs.rb require 'jenkins_api_client' @client = JenkinsApi::Client.new(:server_url => 'http://192.168.88.108:8080', :username=>'admin', :password=>'xxxdddddd') job = @client.job puts(job.list_all) 运行结果 01_Eureka A-PHP My-freestyle-job My-pipeline-job My-pipeline-job01 @client = JenkinsApi::Client.new(:server_ip => '0.0.0.0', :username => 'somename', :password => 'secret password') # The following call will return all jobs matching 'Testjob' puts @client.job.list("^Testjob")
ruby操作json
Ruby - iterate over parsed JSON
see also
runoob.com ruby-tutorial.html Ruby 教程
https://blog.csdn.net/mmiww/article/details/1363960
https://blog.csdn.net/mmiww/article/details/1355157
https://www.runoob.com/ruby/ruby-installation-unix.html
https://www.cnblogs.com/xuliangxing/p/7132656.html
https://linuxize.com/post/how-to-install-ruby-on-debian-9/
https://flicsdb.com/how-to-install-ruby-on-rails-on-ubuntu-or-kali-linux/
Ruby Introduction to Programming with Ruby - 给 Ruby 新手写的免费电子书