From: Sebastian Hungerecker Date: 2007-12-03T23:29:18+09:00 Subject: Re: What are the differences between c++ and Ruby? duddilla's wrote: > And my other question is what are > exact differences between C++ and Ruby? and Ruby and Java? There are a lot of differences. Here are some that come to mind right away: In ruby everthing is an object: 5.class #=> Integer Integer.class #=> Class Ruby has convenient introspection methods: some_object.class # What's some_object's class? some_object.respond_to?("meth") # Does some_object have the method "meth" some_object.methods # Which methods does this object have SomeClass.instance_methods # Which methods do instances of the class have ... In ruby you can reopen classes: 5.double #=> Error: No such method class Integer def double() self * 2 end end 5.double #=> 10 Ruby has dynamic typing: x = 5 x.class #=> Integer x = "lala" x.class #=> String Ruby has blocks and a lot of methods that make good use of them: [1,2,3,4].map {|x| x+3} #=> [4,5,6,7] [5,7,11,8].any? {|x| x>10} #=> true [5,7,11,8].all? {|x| x>10} #=> false 5.times { puts "Hello world" } # Prints "Hello World" five times. In ruby you can easily define methods dynamically: class String (2..10).each do |i| define_method("print_#{i}_times") do i.times {puts self} end end end "hi".print_4_times # Prints "hi" 4 times And a lot of other things. HTH, Sebastian -- Jabber: sepp2k@jabber.org ICQ: 205544826