Movatterモバイル変換


[0]ホーム

URL:


Ruby

A Programmer's Best Friend

HomeDownloadsDocumentationLibrariesCommunityNewsSecurityAbout RubyMenu

To Ruby From Java

Java is mature. It’s tested. And it’s fast (contrary to what theanti-Java crowd may still claim). It’s also quite verbose. Going fromJava to Ruby, expect your code size to shrink down considerably. You canalso expect it to take less time to knock together quick prototypes.

Similarities

As with Java, in Ruby,…

  • Memory is managed for you via a garbage collector.
  • Objects are strongly typed.
  • There are public, private, and protected methods.
  • There are embedded doc tools (Ruby’s is called RDoc). The docsgenerated by rdoc look very similar to those generated by javadoc.

Differences

Unlike Java, in Ruby,…

  • You don’t need to compile your code. You just run it directly.
  • There are several different popular third-party GUI toolkits. Rubyusers can tryWxRuby,FXRuby,Ruby-GNOME2,Qt, orRuby Tk for example.
  • You use theend keyword after defining things like classes, insteadof having to put braces around blocks of code.
  • You haverequire instead ofimport.
  • All member variables are private. From the outside, you accesseverything via methods.
  • Parentheses in method calls are usually optional and often omitted.
  • Everything is an object, including numbers like 2 and 3.14159.
  • There’s no static type checking.
  • Variable names are just labels. They don’t have a type associated withthem.
  • There are no type declarations. You just assign to new variable namesas-needed and they just “spring up” (i.e.a = [1,2,3] rather thanint[] a = {1,2,3};).
  • There’s no casting. Just call the methods. Your unit tests should tellyou before you even run the code if you’re going to see an exception.
  • It’sfoo = Foo.new("hi") instead ofFoo foo = new Foo("hi").
  • The constructor is always named “initialize” instead of the name ofthe class.
  • You have “mixins” instead of interfaces.
  • YAML tends to be favored over XML.
  • It’snil instead ofnull.
  • == andequals() are handled differently in Ruby. Use== when youwant to test equivalence in Ruby (equals() in Java). Useequal?()when you want to know if two objects are the same (== in Java).

Participate in a friendly and growing community.

Syndicate

Recent News (RSS)


HomeDownloadsDocumentationLibrariesCommunityNewsSecurityAbout Ruby

This site in other languages:Български,Deutsch,English,Español,Français,Bahasa Indonesia,Italiano,日本語,한국어,polski,Português,Русский,Türkçe,Tiếng Việt,简体中文,繁體中文.

This website is proudly maintained by members of the Ruby community.


[8]ページ先頭

©2009-2025 Movatter.jp