On May 21, 2007, at 7:05 PM, Morton Goldberg wrote: > On May 20, 2007, at 2:25 PM, anoosh wrote: > >> Hi all >> I have 2 questions? >> 1)What are the meaning of symbols(:var) and Instance variables(@x) >> Ruby?(I know Java and C.If it is possible for you tell me the >> synonyms in these languages,please) >> >> 2)How can I define my own exception handling in Ruby? > > That's really three questions, but who's counting? :) > > 1a. There is nothing like Ruby symbols in Java or C. The usage of symbols is very similar to Java strings though. In Java strings are inmutable and the JVM stores them once[*], quite close. I'd say Java strings are kind of synonym for Ruby symbols, and StringBuffer the synonym for Ruby strings (seen just as data types, of course APIs are different in both cases). I think that they are not exact synonyms nonetheless, because the semantics are not exactly the same. I mean, people use Ruby strings where you'd use a string in Java. Symbols are often used for stuff that is somehow "specific" (a :width option), while strings are used to represent "data". In Java you don't have the choice. -- fxn [*] http://java.sun.com/docs/books/jvms/second_edition/html/ ConstantPool.doc.html