ruby基础学习一

上一篇 / 下一篇  2012-12-14 13:09:30 / 个人分类:程序设计

=begin #多行注释开始
class Tests
  puts "ok"
  p "ok"
  print "ok"
  puts "ok".inspect
  puts "ok".class
end
=end #多行注释结尾

=begin
x = 10
y = 20
#练习插入
puts "#{x} + #{y} = #{x + y}"
#另外一种实现效果
puts x.to_s+" + "+y.to_s+" = "+(x+y).to_s
puts "Test".reverse()
puts "it's a #{"bad " *5}world"
puts "footes".sub('foo','tes')
#替换开头tx为he
puts "txllo".sub(/^../,'he')
#替换末尾tx为lo
puts "heltx".sub(/..$/,'lo')
"123f5".scan(/./){|letter|puts letter}
"this is a test".scan(/\w\w/){|x| puts x}
#扫描字符串中的数字
"this is $1000 is $10 multiply 100".scan(/\d+/) do |x|
  puts x
end
puts "hello tom.this is.jake alny".split(/\./).inspect
=end

=begin
#三元运算
x = 10
type = x <18 ? "child":"adult"
puts "you are #{type}"
puts "you are a " + type
puts Time.now
#加和100
sum = 0
1.upto(100){|jumper| sum +=jumper}
puts(sum)
=end

=begin
#watir测试
require 'watir-webdriver'
b = Watir::Browser.new :firefox,:profile => 'default'
b.goto 'www.baidu.com'
b.text_field(:id =>'kw').set 'selenium'
b.button(:id => 'su').click
=end

TAG: Ruby ruby Watir watir 注释

 

评分:0

我来说两句

Open Toolbar