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,protectedandprivate) - 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'}. -
trueundfalseverhalten sich wie in PHP , abernullwird mitnilbezeichnet
Unterschiede
Im Gegensatz zu PHP hat Ruby-
theres strong typing. Youll need to call
to_s,to_ietc. 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
Reflectionclasses like in PHP 5 - variables are references.
-
theres no
abstractclasses orinterfaces - hashes and arrays are not interchangable
-
nur
falseundnilliefern false:0,array()und""ergeben in Bedingungen true. -
fast alles ist Methodenaufruf, sogar
raise(throwin PHP ).
rubyforge.org rubyforge.org rubyforge.org forum.ruby-portal.de rubyforge.org radiantcms.org tryruby.hobix.com rubyforge.org