phuby

ruby ported to php

This project is maintained by shuber

phuby

A port of ruby 2.0 to native php 5.4+

features

installation

If you're using Composer simply require the shuber-phuby package.

Otherwise you can download the phuby tar/zip or git clone this repository somewhere in your php include path.

Then inside of your php files you can require 'phuby/phuby.php' to load the library.

usage

You can integrate Phuby with your code in 3 ways:

1) class inheritance

class Blog extends Phuby\Object { }

2) traits

This is useful when your class needs to inherit from an existing library and can't extend Phuby\Object.

class Blog extends ActiveRecord\Base {
    use Phuby;
}

3) the Phuby function

This allows you to inject Phuby features into any object.

echo Phuby('this is a sentence.')->upcase;

Phuby([1,2,3])->each(function($number) {
  echo $number;
});

echo Phuby(7)->days->from_now;

todo

general

errors

hooks

lib

Array

Base64

BasicObject

Comparable

Date

Dir

Encoding

Enumerable

Enumerator

File

Fixnum

Float

Hash

IO

Integer

Kernel

Marshal

MatchData

Math

Module

Numeric

Object

ObjectSpace

Proc

Random

Range

Regexp

RegexpError

StopIteration

String

Struct

Time

notes

Usually I try to structure methods so that they have as few return statements or endpoints as possible (1 ideally). In this project I'm using guard style conditions at the beginning of methods and I'm starting to see the beauty of how readable and simple the source code reads. I'm using many if and return statements in favor of else and if else. if expressions are never written inline and the statements are separated by newlines. Brackets { } are only added to if and foreach loops if necessary. It makes source code files longer but everything is condensed horizontally and naturally less than 80 characters most of the time. It makes me appreciate the enforced whitespace in python more.