黑松山资源网 Design By www.paidiu.com
接受用户输入
first_name = gets.chomp
首字母大写
first_name.capitalize!
字母变大写
first_name.upcase!
字母变小写
first_name.downcase!
多行输出
print <<EOF # 多行输出 EOF
注释
# 我是注释
变量获取
#{first_name}
变量
- 全局变量 $
- 类变量 @@
- 方法变量 @
- 局部变量 小写字母或_
if/else
if a < b puts '1' elsif b < a puts '2' end
类
class Classname def functionname(params) puts params end end class1 = Classname.new class1.functionname('1') unless unless false print 'ok' else print 'no' end
是否包含字符
print 'puts' user_input = gets.chomp user_input.downcase! if user_input.include"s" print 'has s' end
替换字符
# s -> th user_input.gsub!(/s/,"th")
在字符串中输出变量值
puts 'okok #{user_input}'
while
counter = 1 while counter < 11 puts counter counter = counter + 1 end
Until
counter = 1 until counter > 10 print counter counter = counter + 1 end
+= 、 -= 、 *=、 /=
Some languages have the increment operators ++ and -- (which also add or subtract 1 from a value), but Ruby does not
for循环
# 如果 1...10 包含1-9,如果 1..10 包含1-10
for num in 1...10 puts num end
Loop Method
An iterator is just a Ruby method that repeatedly invokes a block of code.
i = 20 loop do i -= 1 print "#{ i }" break if i <= 0 end
Next
i = 20 loop do i -= 1 next if i%2 != 0 print "#{i}" break if i <= 0 end
数组
my_array = [1,2,3,4,5]
The .each Iterator迭代器
numbers = [1, 2, 3, 4, 5] # one way to loop numbers.each { |item| puts item } # another way to loop numbers.each do |item| puts item end
The .times Iterator 次数迭代器
10.times { print 'ok'})
Looping with 'While'
num = 1 while num <= 50 do print num num += 1 end
Looping with 'Until'
num = 1 until num > 50 do print num num += 1 end
Loop the Loop with Loop
num = 0 loop do num += 1 print "Ruby!" break if num == 30 end
The .split Method,
text.split(",") puts "Text to search through: " text = gets.chomp puts "Word to redact" redact = gets.chomp words = text.split(" ") words.each do |word| print word end
黑松山资源网 Design By www.paidiu.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
黑松山资源网 Design By www.paidiu.com
暂无评论...
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。
更新日志
2024年10月10日
2024年10月10日
- 群星.1996-各自各精彩【上华】【WAV+CUE】
- 《终极幸运之塔》评测:藏在童年回忆里爬塔佳作
- 《战神5》PC版评测:轻推W缓慢前行
- 《阿瑞亚之旅》评测:更适合佛系玩家体质的跑团
- 黑神话悟空浮屠界紫门怎么开 浮屠界紫门打开方法介绍
- 黑神话悟空龟泪怎么获得 黑神话悟空龟泪获得方法介绍
- 黑神话悟空怎么获得还魂丹 黑神话悟空还魂丹获取方法一览
- HiFi顶级人声天碟《试音齐秦》wav
- 张敬轩.2012-WhyNot(EP)【环球】【WAV+CUE】
- 张小英1988-情愁[新加坡复黑版][WAV+CUE]
- 游民金币礼品补货啦 Steam充值卡等你兑换!
- 《暗喻幻想:ReFantazio》M站均分94分 近年最好的RPG游戏之一
- 今年第一项诺贝尔奖揭幕 生理学或医学奖揭晓
- 《梁静茹 华语乐坛情歌天后 爱久见人心》[WAV/分轨][360MB]
- 《田震 绝版珍藏 依然在飞》[WAV+CUE][600MB]