ruby语法课1
来源:互联网 发布:DRGS网络上报 编辑:程序博客网 时间:2024/04/28 06:55
puts "hello word"=begintest about string=endputs "----------------------------------------"a="hello"b="ruby"c=:"we are going to say #{a} to #{b}"puts c.classputs cputs "#{c}" *3puts c[16]puts c[16,10]puts c[-4,4]puts "#{c}"=="we are going to say #{a} to #{b}"puts %("hello ruby")puts %("")=begintest for array=endputs "----------------------------------------"d=["we","are"]e=d+["going","to"]puts e[1]print e[1,2]puts "\n#{e[1,2].class}"print e[0..4]f=e.join(",")puts "\n"+fg=f.split(",")print "#{g}\n"puts g==earray_test=%w{aaa bbb ccc}puts array_test.classprint array_testputs "\n"print array_test.reverseputs "\n"test_array=[]test_array=test_array+['q']test_array=test_array+['p']print test_array=begintest for hash可以把哈希表看成一个由大括号{}中所包含的多个键值对构成的相关联的数组=endputs "\n----------------------------------------"h={"one"=>"we","two"=>"are","three"=>"going","four"=>"to","five"=>"say"}puts h["three"]h["six"]="hello"print "#{h}\n"h.delete("six")print "#{h}\n"i={:a=>"we",:b=>"are",:c=>"going",:d=>"to",:e=>"say"}print "#{i}\n"=begintest for rang=endputs "----------------------------------------"j='a'..'f'puts j.classputs j === 'x'puts j === 'b'=begintest about variables=endputs "----------------------------------------"k="hello"puts defined?(k)class TestHello def test_a l="hello" puts "test_a #{defined?(l)}" end def test_b puts "test_b #{defined?(l)}" endendm=TestHello.newm.test_am.test_bclass TestHello1 def test_a @l="hello" puts "test_a #{defined?(@l)}" end def test_b puts "test_b #{defined?(@l)}" endendn=TestHello1.newn.test_an.test_b@@class_test="ruby"class C_class def test puts @@class_test end def test_set(a) @@class_test=a endendc_a=C_class.newc_b=C_class.newc_a.testc_b.testc_a.test_set("fffffuck")c_b.test=begintest about operator=endvar = nilvar ||= "fuck"puts varvar ||= "test"puts var
运行结果
hello word
----------------------------------------
Symbol
we are going to say hello to ruby
we are going to say hello to rubywe are going to say hello to rubywe are going to say hello to ruby
s
say hello
ruby
true
"hello ruby"
""
----------------------------------------
are
["are", "going"]
Array
["we", "are", "going", "to"]
we,are,going,to
["we", "are", "going", "to"]
true
Array
["aaa", "bbb", "ccc"]
["ccc", "bbb", "aaa"]
["q", "p"]
----------------------------------------
going
{"one"=>"we", "two"=>"are", "three"=>"going", "four"=>"to", "five"=>"say", "six"=>"hello"}
{"one"=>"we", "two"=>"are", "three"=>"going", "four"=>"to", "five"=>"say"}
{:a=>"we", :b=>"are", :c=>"going", :d=>"to", :e=>"say"}
----------------------------------------
Range
false
true
----------------------------------------
local-variable
test_a local-variable
test_b
test_a instance-variable
test_b instance-variable
test_1.rb:124: warning: class variable access from toplevel
ruby
ruby
fffffuck
fuck
fuck
- ruby语法课1
- ruby语法课2
- ruby语法课3
- ruby语法
- ruby-语法
- ruby语法
- [ruby] 语法
- Ruby语法
- ruby语法
- Ruby 语法
- ruby 语法
- ruby on rails 【语法大全1】
- 学习一下Ruby的基本语法(1)
- Ruby七天入门(1 基本语法入门)
- Ruby和Python的语法差异(1)
- ruby 语法的总结
- Ruby语法学习笔记
- ruby的基本语法
- 树梅派应用34:树莓派安装DLNA实现流媒体服务器
- 使用BeanUtils时,Date类型值为空的解决方法
- Mysql数据库,使用命令行备份
- 将Yii2和Workerman结合
- java8中的Lambda表达式
- ruby语法课1
- lod详解
- Android 默认暗码
- oracle 实现不同字段显示成一行数据
- Progress实践
- 取消Win10系统Alt+Tab中的缩略图预览功能
- storyboard tableview section
- jQuery 性能优化
- 程序员面试金典第一章:数组与字符串(1) 确定字符互异