From: 7stud -- Date: 2008-02-20T08:27:49+09:00 Subject: Re: Is there any object-oriented File class in ruby ? tom_33 wrote: > I am very new to Ruby and my question is about trying to understand > why Ruby is often described as a "pure object-oriented language", when > the core library seems to be quite procedural. > > For example, the class File seems to have a big bunch of procedural > functions (or static methods, or whatever you want to call them) that > needs the filename to be provided as a parameter. > > The File class in java is a much better OO class for managing files: > http://java.sun.com/j2se/1.5.0/docs/api/java/io/File.html > than the following ruby class: > http://ruby-doc.org/core/classes/File.html > > For example, the ruby method File.basename is documented as only > supporting forward slashes, regardless of the local file system. > File.basename("/home/gumby/work/ruby.rb") #=> "ruby.rb" > Essentially, this seems to be not much more than a string parsing > function with no OO abstraction that represents a file object. > Compare this with doing the same thing with java: > File f = new File("/home/gumby/work/ruby.rb"); // or new File("C:\\home > \\gumby\\work\\ruby.rb"); > f.getName() #=> "ruby.rb" > > Now my question is what have I been missing here ? > I mean, is there any other much better File class somewhere in the > Ruby core that is more pure OO, or otherwise why is a language with a > CORE procedural "class" library described as being a pure oo > language ? > > / Tom Look at this code: class A def hi puts 'hi' end end class B def B.hello puts 'hello' end end a = A.new a.hi B.hello --output:-- hi hello Personally, I do not like the formal nature of class B. I prefer the friendlier, more personable class A. As a result, I do not consider class B to be object oriented. Is that a logical conclusion? Let's try this: def hi puts 'hi' end def hello puts 'hi mate' end hi hello --output:-- hi hi mate I consider that output superior, therefore I believe that code is more object oriented. Is that a logical conclusion? -- Posted via http://www.ruby-forum.com/.