数字、文本、范围、符合、True、False、Nil

1为什么是一个类的对象,使用methods方法可以查看一个对象的所有函数(方法)

$ irb
irb(main)::>
=>
irb(main)::> .methods
=> [:to_s, :inspect, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===, :<=>, :>, :>=, :<, :<=, :~, :&, :|, :^, :[], :<<, :>>, :to_f, :size, :bit_length, :zero?, :odd?, :even?, :succ, :integer?, :upto, :downto, :times, :next, :pred, :chr, :ord, :to_i, :to_int, :floor, :ceil, :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, :singleton_method_added, :coerce, :i, :+@, :eql?, :remainder, :real?, :nonzero?, :step, :quo, :to_c, :real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :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, :send, :public_send, :respond_to?, :extend, :display, :method, :public_method, :singleton_method, :define_singleton_method, :object_id, :to_enum, :enum_for, :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]
irb(main)::>

在Ruby中万物皆对象,没有基本的数据类型

通过to_s这个方法 将 1 变成了字符串,这就是Ruby奇妙的地方

irb(main)::> .to_s
=> ""
irb(main)::>

为什么 0.4-0.3 不等于 0.1

irb(main)::> -
=>
irb(main)::> -3.5
=> 0.5
irb(main)::> 0.4-0.3
=> 0.10000000000000003
irb(main)::>

插值操作

irb(main)::> a =
=>
irb(main)::> b =
=>
irb(main)::> "hello #(a+b)"
=> "hello #(a+b)"
irb(main)::> "hello #{a+b}"
=> "hello 5"

范围

大于等于1 小于等于2                   1<=   <=2

大于等于1 小于3          1<=   <3

irb(main)::> ..
=> ..
irb(main)::> ...
=> ...
irb(main)::> "hello"*
=> "hellohellohello"
irb(main)::>
irb(main)::> "hello".methods
=> [:<=>, :==, :===, :eql?, :hash, :casecmp, :+, :*, :%, :[], :[]=, :insert, :length, :size, :bytesize, :empty?, :=~, :match, :succ, :succ!, :next, :next!, :upto, :index, :rindex, :replace, :clear, :chr, :getbyte, :setbyte, :byteslice, :scrub, :scrub!, :freeze, :to_i, :to_f, :to_s, :to_str, :inspect, :dump, :upcase, :downcase, :capitalize, :swapcase, :upcase!, :downcase!, :capitalize!, :swapcase!, :hex, :oct, :split, :lines, :bytes, :chars, :codepoints, :reverse, :reverse!, :concat, :<<, :prepend, :crypt, :intern, :to_sym, :ord, :include?, :start_with?, :end_with?, :scan, :ljust, :rjust, :center, :sub, :gsub, :chop, :chomp, :strip, :lstrip, :rstrip, :sub!, :gsub!, :chop!, :chomp!, :strip!, :lstrip!, :rstrip!, :tr, :tr_s, :delete, :squeeze, :count, :tr!, :tr_s!, :delete!, :squeeze!, :each_line, :each_byte, :each_char, :each_codepoint, :sum, :slice, :slice!, :partition, :rpartition, :encoding, :force_encoding, :b, :valid_encoding?, :ascii_only?, :unpack, :encode, :encode!, :to_r, :to_c, :>, :>=, :<, :<=, :between?, :nil?, :!~, :class, :singleton_class, :clone, :dup, :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, :send, :public_send, :respond_to?, :extend, :display, :method, :public_method, :singleton_method, :define_singleton_method, :object_id, :to_enum, :enum_for, :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]
irb(main)::>
irb(main)::> a = "hello"
=> "hello"
irb(main)::> a[]=""
=> ""
irb(main)::> a
=> "1ello"
irb(main)::>

bool类型

irb(main)::>  ==
=> true
irb(main)::> ==
=> false
irb(main)::> true.methods
=> [:to_s, :inspect, :&, :|, :^, :nil?, :===, :=~, :!~, :eql?, :hash, :<=>, :class, :singleton_class, :clone, :dup, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :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, :send, :public_send, :respond_to?, :extend, :display, :method, :public_method, :singleton_method, :define_singleton_method, :object_id, :to_enum, :enum_for, :==, :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]
irb(main)::>

Nil

irb(main)::> "hello".nil?
=> false
irb(main)::> "".nil?
=> false
irb(main)::>

empty

irb(main)::> "".methods
=> [:<=>, :==, :===, :eql?, :hash, :casecmp, :+, :*, :%, :[], :[]=, :insert, :length, :size, :bytesize, :empty?, :=~, :match, :succ, :succ!, :next, :next!, :upto, :index, :rindex, :replace, :clear, :chr, :getbyte, :setbyte, :byteslice, :scrub, :scrub!, :freeze, :to_i, :to_f, :to_s, :to_str, :inspect, :dump, :upcase, :downcase, :capitalize, :swapcase, :upcase!, :downcase!, :capitalize!, :swapcase!, :hex, :oct, :split, :lines, :bytes, :chars, :codepoints, :reverse, :reverse!, :concat, :<<, :prepend, :crypt, :intern, :to_sym, :ord, :include?, :start_with?, :end_with?, :scan, :ljust, :rjust, :center, :sub, :gsub, :chop, :chomp, :strip, :lstrip, :rstrip, :sub!, :gsub!, :chop!, :chomp!, :strip!, :lstrip!, :rstrip!, :tr, :tr_s, :delete, :squeeze, :count, :tr!, :tr_s!, :delete!, :squeeze!, :each_line, :each_byte, :each_char, :each_codepoint, :sum, :slice, :slice!, :partition, :rpartition, :encoding, :force_encoding, :b, :valid_encoding?, :ascii_only?, :unpack, :encode, :encode!, :to_r, :to_c, :>, :>=, :<, :<=, :between?, :nil?, :!~, :class, :singleton_class, :clone, :dup, :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, :send, :public_send, :respond_to?, :extend, :display, :method, :public_method, :singleton_method, :define_singleton_method, :object_id, :to_enum, :enum_for, :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]
irb(main)::> "".empty?
=> true
irb(main)::>

chomp

irb(main)::> a = gets

=> "100\n"
irb(main)::> puts a => nil
irb(main)::> a.chomp
=> ""
irb(main)::> a.chomp.to_i
=>
irb(main)::>

while循环的控制语句break和next

  1 input = gets.chomp.to_i
2 while input!= 0
3 puts "break if input ==2,try try"
4 break if input == 2
5 next if input == 3
6 puts "跳过这个循环控制语句,跳出或者略过"
7 end

【Ruby on Rails 学习三】Ruby 基本数据类型(类、类的实例、对象)的更多相关文章

  1. 【Ruby on Rails学习二】在线学习资料的整理

    由于工作任务重,时间紧,没有太多学习的时间,大致找了些在线学习资料,这里做个整理,希望对同样准备学习的朋友有帮助 在线文档类: Ruby on Rails 实战圣经  使用 Rails 4.2 及 R ...

  2. 【Ruby on Rails 学习一】ubuntu14.04配置rvm与ruby

    要安装ruby,首先要安装rvm,借助rvm安装ruby rvm 的全称是 Ruby Version Manager ,是一款由 Wayne E. Seguin  开发的一款命令行工具.rvm 能够让 ...

  3. Ruby on rails学习笔记——安装环境

    出现问题: C:\Users\len>gem install rails ERROR: While executing gem ... (Gem::RemoteFetcher::FetchErr ...

  4. 【Ruby on Rails 学习四】简单的代码快和错误处理

    第一个例子: 1 ... 5000的加法运算 1 sum = 0 2 i = 1 3 while true 4 sum += i 5 i += 1 6 break if i == 5001 7 end ...

  5. 【Ruby on Rails 学习五】Ruby语言的方法

    1.方法的调用 2.自定义方法 3.带默认值的自定义方法 4.带返回值的自定义方法 方法或者说是函数,实际上是包含了一段代码,去执行某一个特定的过程. def add(a=3,b=2) return ...

  6. 【Ruby on Rails 学习六】Ruby 类 的入门

    1.什么是类 2.类与实例的区别 3.自定义简单的类 生活中的垃圾分类,是集合上的概念 比如数学上的   1  a  2  b  c  4  5分类为数字1 2 4 5 ,字母  a  b  c ir ...

  7. [ruby on rails] 深入(2) ruby基本语法

    1. 调试&注释&打印输出 1.1 调试 ruby属于解释型语言,即脚本,在linux上,脚本的执行无非三种: 1. 用解释器运行脚本 解释器 脚本文件 即:ruby  脚本文件 2. ...

  8. Redis学习三:Redis数据类型

    一.Redis的五大数据类型 1.String(字符串) string是redis最基本的类型,你可以理解成与Memcached一模一样的类型,一个key对应一个value.string类型是二进制安 ...

  9. Android JNI 学习(三):JNI 数据类型和数据结构

    本文我们来讨论一下JNI如何将Java类型映射到本机C类型. 一.基本数据类型 如下图表整理了Java基本类型和native对应的关系: Java类型 Native类型 描述 boolean jboo ...

随机推荐

  1. keep-alive实现返回保留筛选条件及筛选结果

    实现页面返回时,保留筛选条件和筛选结果 说明 . keep-alive 是Vue的内置组件,能在组件切换过程中将状态保留在内存中,防止重复渲染DOM 实现 结合router实现部分页面缓存 模板应用 ...

  2. 命令方式 搭建 (简易)Maven项目

    原料:1.配好的Maven环境变量    2.c m d命令 win  + r  输入 cmd 切换到此项目所要存在的位置 使用命令创建文件夹 切换 到 maven_demo中  输入 cd mave ...

  3. CNN简略总结

    https://blog.csdn.net/real_myth/article/details/51824193 池化层的作用: 感受野变化...?? 1*1卷积核的作用 1. 实现跨通道的交互和信息 ...

  4. 表空间及段区块的一些sql语句和视图

    查询段情况的语句 select segment_name,blocks,extents,bytes,segment_type,tablespace_namefrom dba_segments wher ...

  5. 计算机网络(六),UDP报文段详解

    目录 1.UDP作用 2.UDP报文段详解 六.UDP报文段详解 1.UDP作用 (1)面向非连接 (2)不维护连接状态,支持同时向多个客户端传送相同的消息 (3)报文段报头只有8个字节,格外开销较小 ...

  6. FFT用于高效大数乘法(当模板用)

    转载来源:https://blog.csdn.net/zj_whu/article/details/72954766 #include <cstdio> #include <cmat ...

  7. cogs2039树的统计 x

    2039. 树的统计 ★★   输入文件:counttree.in   输出文件:counttree.out   简单对比 时间限制:1 s   内存限制:128 MB [题目描述] 关于树的统计问题 ...

  8. select和FD_SET等

    转自:http://blog.csdn.net/cstarbl/article/details/7645298 select函数用于在非阻塞中,当一个套接字或一组套接字有信号时通知你,系统提供sele ...

  9. oracle 获取时间

    1.获取当前时间的前24小时的各小时时间段 select to_char(to_date(to_char(sysdate ) ,'yyyy-mm-dd hh24') || ':00:00','yyyy ...

  10. getFieldDecorator用法(一)——登录表单

    之前使用antd的ui表单,却没发现这么好用的用法,推荐给大家 import React from "react"; import { Card, Form, Input, But ...