zoukankan      html  css  js  c++  java
  • 备忘---ruby


    1, Ubuntu安装git
    sudo apt-get install git-core

    2, Redhat安装git
    sudo yum install git-all

    3, ruby和SHELL沟通

    ifconfig = `/sbin/ifconfig` #``为反引号,1旁边的那个键,用来引用SHELL下的指令,非常方便,返回命令执行后的response给ifconfig
    ip = /[d{2}.]{4}/.match(ifconfig)
    

    4, 数组赋值

    array = %w{it is like you are back from the dead}
    => ["it", "is", "like", "you", "are", "back", "from", "the", "dead"]
    
    newline = [1,2,3,4,5,6,7]
    => [1, 2, 3, 4, 5, 6, 7]
    
    a = Array.new(5){|i| i*4}
    => [0, 4, 8, 12, 16]
    
    o = Array.new
    => []
    
    a.clear 删除整个数组
    a.delete(8) 删除数组里的第8个元素。
    

     5,HASH    KEY唯一, 数组是HASH的特例。

    a, 以Hash关键字头,以[]包起来。
    pry(main)> h = Hash["a", 10,"b",11,"c",12, "d",13]
    => {"a"=>10, "b"=>11, "c"=>12, "d"=>13}
    
    b, 或者: h = Hash["a"=>10,"b"=>11,"c"=>12, "d"=>13]
    
    c, 直接以{}包起来,并以=>赋值
    pry(main)> h = {"a"=>10,"b"=>3,"c"=>4}
    => {"a"=>10, "b"=>3, "c"=>4}
    
    d, 赋值也可以这样: 
    h = Hash.new
    
    e, 可以分别显示hash的key, value.
    h.keys
    h.values
    

     6, 类方法与实例方法要区分,还末找到很切实的规律。

  • 相关阅读:
    [BZOJ] 2054 疯狂的馒头
    day33(sql)
    day32(表单校验js和jquery表单校验)
    day31(正则表达式)
    day30(对象转json(java))
    day29(对象转xml(使用java))
    day28(ajax之js原生代码实现)
    day27(反射之内省机制实现BeanUtils)
    day27(反射之内省机制)
    day26(分页查询)
  • 原文地址:https://www.cnblogs.com/mover/p/3521346.html
Copyright © 2011-2022 走看看