ITeye博客

ruby学习笔记

sharefling · 2014-03-17 15:01 · ruby · 编程语言 · Markdown

学习问题:

ruby多个文件相互引入

ruby field使用

108页书籍

 

源代码:

class Prac 

 

private

def get

print "hello print"

 

end

private

def initialize  

puts "init"

end

 

end

 

 

class Sonprac < Prac

 

def sayson

 

puts "sayson"

 

end

 

def get

 

super

puts "supers prac!!"

 

end

 

def setRate(rate)

@rate=rate

end

 

def getRate()

return @rate

end

 

end

 

prac=Sonprac.new

 

prac.get

prac.sayson

prac.setRate("happy birtyday")

puts prac.getRate

 

puts GC.start

 

 

 

class Rescue

 

@@name="yaoge"

def testrescue

begin 

@s=1/0

rescue

puts "exception"

ensure 

 

share="niam1"

puts "finally"+@@name+share

 

end

puts "end"

end

 

def logincal(a,b)

if a>b

puts "if"

elsif a>b

puts("else")

else 

puts "elsif"

end

 

i=0

while i<3

i=i+1

puts i

end

 

for i in 2..8

i=i+1

 

if i==7

puts "next"

 

end

 

puts "for word test "+String(i)

 

end

 

 

 

end

 

 

def test_block

 

puts "block youmeiyou!a start"

puts "block youmeiyou!a end"

 

end

 

def arraytest

arrays=['2','3','5']

i=0

for i in 0..2

puts arrays[i]

 

end

 

1.upto(9){|a| puts a if a>7 }

(1..9).each{ |x| print x if x<7 }

 

end

 

 

def useobject(o)

o.call

end

 

end

 

re=Rescue.new

 

re.useobject(proc{

puts "object processing"

})

 

re.arraytest

 

class Prac 

 

def get

 

print "hello print"

 

end

 

def initialize

puts "init"

end

 

end

 

 

 

 

class Datacal

def getclass

puts 555000.class

puts 12.039820382.class.to_s

 

puts Math.sin(0)

 

puts "age: #{11+222}"

 

s="string"

puts s[1,1]

puts "a".next!

puts s["in"]="hello"

puts s.capitalize!

 

teststring="dbnlskfh           !!! fdl;f \n"

puts teststring.lstrip.gsub(/d/,'sharefly')

 

end

 

def jingzhi

puts "123".hex

puts "123".oct

 

kon="fhdh dfhehf erh   "

count=kon.rstrip.lstrip

puts count

 

end

 

end

 

data=Datacal.new

 

data.jingzhi

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。