Ruby基本数据类型操作

元数据:数据的数据
元编程:编程的编程

puts "hello world"
puts("hello world")

a = "hehh"
puts a
a

b = 3
c=2
b+c
b-c
a+b:error
自动推导出类型,像女生那么就是推导为女生类型

查看一个类型所对应有哪些方法
1.methods
"aa".methods
在ruby中万物结对象,所以ruby中没有基本的数据类型
将数字转为字符串1.to_s
1.2
1.2.to_s

4-3
4-1.5
0.4-0.3 ??
'2'
"2"

进行插值操作
a=2
b=3
"hello #{a+b}"

一个值满足>=1 and <=2
1..2
一个值满足>=1 and <3
1...3

字符串*3
irb(main):034:0> "hello" 3
=> "hellohellohello"
为什么字符串可以有
,查看对象所有方法:"hello".methods

修改字符串中某一个字符的值
a = "hello"
a[0] = "1"
a

2 ==2
3==1
true.methods

"hello".nil?
"".nil?

"".methods

判断对象是否为空

"".empty?

你可能感兴趣的:(Ruby基本数据类型操作)