From: FireAphis Date: 2007-07-26T15:05:06+09:00 Subject: Re: how can i use a ruby class in object way On Jul 26, 6:43 am, Guo Yangguang wrote: > hello: > can you help me ?we all know that we can use a class'object in main > method in java,but how can i use a class'object after designing a class > in ruby? i only know i can make an object and use it after having a > class,i can also use a class method in a class to get some result after > designing a class method.But why i can do that? i do not know the > reason? is there an only place like main method of java in which i can > use my classes? is there a rule that can guide me to use my ruby class > correctly? > thank you ! > -- > Posted viahttp://www.ruby-forum.com/. I hope I understand your question correctly. Ruby is in its essence an interpreter. When you type in your command prompt >ruby my_script.rb the interpreter (that by itself is just another application) reads your file line by line and executes every line. Think of every line in Ruby as a command to the interpreter and that the interpreter executes every single line. That means you can use your classes anywhere you like as long as they were defined before. For example, this is absolutely correct in Ruby: a = "I assign even before any declaration" puts "Moreover I can output its value #{a}" (1..10).each {|x| puts "#{x} I can do anything I wish"} class C1 puts "When interpreter will read this he will print. Not very useful but possible" def a() end end c = C1.new # now we can use our class puts "We can do something in between..." class C2 puts "We can define another class" def b end end puts "And so on..." As you can see it's quite different from Java. If you want to feel more comfortable think of your Ruby code written entirely inside one big 'main' Java function. Just remember - every line is executed! FireAphis