Created
January 20, 2011 00:05
-
-
Save iammerrick/787151 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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