• ruby 基础笔记


    表格 1.1:简单介绍 Rails 默认文件结构

    文件/文件夹说明
    app/ 程序的核心文件,包含模型、视图、控制器和帮助方法
    app/assets 程序的资源文件,如 CSS、JavaScript 和图片
    bin/ 可执行文件
    config/ 程序的设置
    db/ 数据库文件
    doc/ 程序的文档
    lib/ 代码库文件
    lib/assets 代码库包含的资源文件,如 CSS、JavaScript 和 图片
    log/ 程序的日志文件
    public/ 公共(例如浏览器)可访问的数据,如出错页面
    script/rails 生成代码、打开终端会话或开启本地服务器的脚本
    test/ 程序的测试文件(在 3.2.1 节 中换用 spec/
    tmp/ 临时文件
    vendor/ 第三方代码,如插件和 gem
    vendor/assets 第三方代码包含的资源文件,如 CSS、JavaScript 和图片
    README.rdoc 程序简介
    Rakefile rake 命令包含的任务
    Gemfile 该程序所需的 gem
    Gemfile.lock 一个 gem 的列表,确保本程序的复制版使用相同版本的 gem
    config.ru Rack 中间件的配置文件
    .gitignore git 忽略的文件类型

    变量定义(variables):

    local: time or _time  instance: @time  class: @@time  global $time

    数据类型(data types)

    Numeric  String  Symbol  Boolean  Array  Hash 

    variables tricks(变量应用)

    "hello #{name}"  a,b = b,a  3.times{ puts "hello"}  "hello" * 3

    判断语句

    1.condition if

    质樸的if:

      if(a>5)

         puts a

      end

    一行版:

      if a > 5 then puts a end

    语义不够顺畅:

      puts a if a > 5

    2.condition unless

    • 与if语义相反的unless

      puts "miss it" if !name

      puts "miss it" unless name

      三元不能少:  

      a > 5 ? puts(a) : "oh no"

    3.condition if else

      

    • if elsif else:

    • 
      if name == "jack"
        "i am rose"
      elsif name == "rose"
        "jack i miss u"
      else
        "get out from here"
      end
        
    • 这个肯定是switch的场景啊:

    • 
      case name
      when "jack" then "i am rose"
      when "rose" then "jack i miss u"
      else "get out from here"
      end

    loop(循环)

    • 循环怎么写:

    • 3.times{ puts "hello world" }
    • for呢:

    • 
      for x in [1,2,3]
        puts x
      end
    • while:

    • 
      while i > 5 do
        i -= 1
      end
      i -= 1 while i > 5
      		
    • while的好兄弟until:

    • 
      until i <= 5 do
        i -= 1
      end
      i -= 1 until i<= 5
      • while true太不洋气了:

      • 
        loop do
          puts "我自豪"
        end
        		
      • 打断罪恶的连锁:

      • break
        next
        redo
        retry

      

     

  • 相关阅读:
    Servlet学习总结,为理解SpringMVC底层做准备
    maven笔记
    初识Hadoop
    java8笔记: sorted()之正序倒序
    git push命令
    git clone新项目后如何拉取其他分支代码到本地
    Spring事务
    线程之间的转化状态
    Centos安装RabbitMq
    .net 中的AES加密解密
  • 原文地址:https://www.cnblogs.com/andicu/p/3747270.html
Copyright © 2020-2023  润新知