Movatterモバイル変換


[0]ホーム

URL:


Ruby

A Programmer's Best Friend

HomeDownloadsDocumentationLibrariesCommunityNewsSecurityAbout RubyMenu

To Ruby From PHP

PHP is in widespread use for web applications, but if you want to useRuby on Rails or just want a language that’s more tailored for generaluse, Ruby is worth a look.

Similarities

As in PHP, in Ruby…

  • Ruby is dynamically typed, like in PHP, so you don’t need to worryabout having to declare variables.
  • There are classes, and you can control access to them like in PHP 5(public,protected andprivate).
  • Some variables start with $, like in PHP (but not all).
  • There’seval, too.
  • You can use string interpolation. Instead of doing"$foo is a $bar",you can do"#{foo} is a #{bar}"—like in PHP, this doesn’t apply forsingle-quoted strings.
  • There’s heredocs.
  • Ruby has exceptions, like PHP 5.
  • There’s a fairly large standard library.
  • Arrays and hashes work like expected, if you exchangearray() for{ and}:array('a' => 'b') becomes{'a' => 'b'}.
  • true andfalse behave like in PHP, butnull is callednil.

Differences

Unlike in PHP, in Ruby…

  • There’s strong typing. You’ll need to callto_s,to_i etc. toconvert between strings, integers and so on, instead of relying on thelanguage to do it.
  • Strings, numbers, arrays, hashes, etc. are objects. Instead of callingabs(-1) it’s -1.abs.
  • Parentheses are optional in method calls, except to clarify whichparameters go to which method calls.
  • The standard library and extensions are organized in modules and classes.
  • Reflection is an inherent capability of objects, you don’t need to useReflection classes like in PHP 5.
  • Variables are references.
  • There’s noabstract classes orinterfaces.
  • Hashes and arrays are not interchangeable.
  • Onlyfalse andnil are false:0,array() and"" are all truein conditionals.
  • Almost everything is a method call, evenraise (throw in PHP).

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