EnglishDeutschFrançaisEspañolPortuguêsIndonesian日本語한국어简体中文繁體中文PolskiTürkçe

Von PHP zu Ruby

PHP ist bei Webapplikationen weit verbreitet, aber wenn du Ruby on Rails verwenden willst oder eine Programmiersprache suchst, die für allgemeinere Fälle ausgelegt ist, ist Ruby sicher einen Blick wert.

Gemeinsamkeiten

Genauso wie in PHP ist Ruby
  • Ruby is dynamically typed, like in PHP , so you dont need to worry about having to declare variables.
  • there are classes, and you can control access to them like in PHP 5 ( public , protected and private )
  • Einige Variablen beginnen mit $, genau wie in PHP (aber nicht alle).
  • theres eval , too.
  • you can use string interpolating. Instead of doing $foo is a $bar, you can do #{foo} is a #{bar}like in PHP , this doesnt apply for single-quoted strings.
  • theres heredocs
  • Ruby has exceptions, like PHP 5
  • theres a fairly large standard library
  • arrays and hashes work like expected, if you exchange array() for { and } : array('a' => 'b') becomes {'a' => 'b'} .
  • true und false verhalten sich wie in PHP , aber null wird mit nil bezeichnet

Unterschiede

Im Gegensatz zu PHP hat Ruby
  • theres strong typing. Youll need to call to_s , to_i etc. to convert between strings, integers and so on, instead of relying on the language to do it
  • strings, numbers, arrays, hashes, etc. are objects. Instead of calling abs(-1) its -1.abs
  • paranthesis are optional in method calls, except to clarify which parametres go to which method calls
  • instead of naming conditions, like underscores, the standard library and extensions are organized in modules and classes
  • reflection is an inherent capatibility of objects, you dont need to use Reflection classes like in PHP 5
  • variables are references.
  • theres no abstract classes or interface s
  • hashes and arrays are not interchangable
  • nur false und nil liefern false: 0 , array() und "" ergeben in Bedingungen true.
  • fast alles ist Methodenaufruf, sogar raise ( throw in PHP ).

rubyforge.org rubyforge.org rubyforge.org forum.ruby-portal.de rubyforge.org radiantcms.org tryruby.hobix.com rubyforge.org