class MyInfo
def initialize(id,name,addr)
@id=id
@name=name
@addr=addr
end
def printInfo
puts "id "+ @id.to_s
puts "name ="+@name
puts "addr ="+@addr
end
end
obj=MyInfo.new(1,"srini","hyd")
puts "this is simple prog"
obj.printInfo
puts "outside of class"
def f1
puts "this is f1"
end
END {
puts "this is end of the prog"
f1
}
BEGIN {
puts "this is the start of the prog"
}
============
$ruby main.rb
this is the start of the prog
this is simple prog
id 1
name =srini
addr =hyd
outside of class
this is end of the prog
this is f1
==========
No comments:
Post a Comment