Skip to content

Instantly share code, notes, and snippets.

@iammerrick
Created January 20, 2011 00:05
Show Gist options
  • Save iammerrick/787151 to your computer and use it in GitHub Desktop.
Save iammerrick/787151 to your computer and use it in GitHub Desktop.
/**
* Ruby
*/
class Person
def initialize(name)
@name = name.capitalize
@loves = [];
end
def love(what)
@loves.push(what)
end
def loves?()
@loves.each do |what|
puts what.upcase!
end
end
end
merrick = Person.new('merrick')
merrick.love('php')
merrick.love('diet coke')
merrick.loves?*/
/**
* PHP
*/
class Person
{
protected $_name;
protected $_loves;
public function __construct($name)
{
$this->_name = ucfirst($name);
$this->_loves = array();
}
public function love($what)
{
array_push($this->_loves, $what);
}
public function loves()
{
foreach($this->_loves as $love)
{
echo strtoupper($love);
}
}
}
$merrick = new Person('merrick');
$merrick->love('php');
$merrick->love('diet coke');
$merrick->loves();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment