5 Useful PHP to Ruby methods

When I first started writing in ruby I found myself needing to know the ruby method equivalents to specific PHP functions. These methods are widely used by myself for debugging and day to day checking of data types.

PHP’s die(‘message’) becomes

1
abort 'message'

PHP’s get_class_methods() becomes

1
object.methods.inspect

PHP’s in_array() becomes

1
array.include? 'item'

PHP’s key_exists() becomes

1
array.has_key? :key

PHP’s isset() becomes

1
defined? var
1
hash[:key].present?

Nice and simple conversion. Moving from PHP to ruby takes little effort if you understand the basis of two things:

  1. Object Oriented Programming
  2. How to find out methods available on an object in Ruby

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>