Created
August 18, 2015 03:07
-
-
Save rightgo09/7f96be27b0c4009b820f 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
module HogeTrait | |
def h | |
res = super | |
puts "HogeTrait::h() dayo" | |
res['t'] = 'traitdayo' | |
res | |
end | |
end | |
class ParentHoge | |
def h | |
puts "ParentHoge::h() dayo" | |
{h: 'hdayo'} | |
end | |
end | |
class ChildHoge < ParentHoge | |
include HogeTrait | |
def h | |
res = super | |
puts "ChildHoge::h() dayo" | |
res | |
end | |
end | |
h = ChildHoge.new | |
p h.h | |
#ParentHoge::h() dayo | |
#HogeTrait::h() dayo | |
#ChildHoge::h() dayo | |
#{:h=>"hdayo", "t"=>"traitdayo"} |
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
<?php | |
trait HogeTrait { | |
public function h() { | |
$res = parent::h(); | |
echo "HogeTrait::h() dayo\n"; | |
$res['t'] = 'traitdayo'; | |
return $res; | |
} | |
} | |
class ParentHoge { | |
public function h() { | |
echo "ParentHoge::h() dayo\n"; | |
return ['h' => 'hdayo']; | |
} | |
} | |
class ChildHoge extends ParentHoge { | |
use HogeTrait { h as hh; } | |
public function h() { | |
$res = $this->hh(); | |
echo "ChildHoge::h() dayo\n"; | |
return $res; | |
} | |
} | |
$h = new ChildHoge(); | |
var_dump($h->h()); | |
//ParentHoge::h() dayo | |
//HogeTrait::h() dayo | |
//ChildHoge::h() dayo | |
//array(2) { | |
// 'h' => | |
// string(5) "hdayo" | |
// 't' => | |
// string(9) "traitdayo" | |
//} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment