29
Ruby 比較と (PHP ) 2012/12/08 RejectTokyoRubyKaigi10 do_aki

Ruby and comparison_and...php

  • Upload
    doaki

  • View
    1.809

  • Download
    1

Embed Size (px)

DESCRIPTION

RejectTokyoRubyKaigi10

Citation preview

Page 1: Ruby and comparison_and...php

Ruby と 比較と (PHP と)

2012/12/08 RejectTokyoRubyKaigi10

do_aki

Page 2: Ruby and comparison_and...php

@do_aki

http://do-aki.net/

Page 3: Ruby and comparison_and...php

I’m a PHPer

Page 4: Ruby and comparison_and...php
Page 5: Ruby and comparison_and...php
Page 6: Ruby and comparison_and...php

Comparison

比較

Page 7: Ruby and comparison_and...php
Page 8: Ruby and comparison_and...php

conditional expression

if expr

unless expr

while expr

until expr

Page 9: Ruby and comparison_and...php

Ruby’s Conditional Branches

TRUE

FALSE false nil

other

Page 10: Ruby and comparison_and...php

if 文 => 評価 => 結果

if false => false => FALSE

if true => true => TRUE

if 0 => true => TRUE

if ‘0’ => true => TRUE

if [] => true => TRUE

Page 11: Ruby and comparison_and...php

if 文 => 解釈 =>評価 => 結果

if false == ‘0’

=> false.==(‘0’) => false => FALSE

if nil == false

=> nil.==(false)

=> false => FALSE

Page 12: Ruby and comparison_and...php

の場合は……

Page 13: Ruby and comparison_and...php

ture => TRUE

false => FALSE

cast to bool

PHP’s Conditional Branches

Page 14: Ruby and comparison_and...php

if 文 => 解釈=>評価 => 結果

if(false)=> (bool)false => false =>FALSE

if(true)=> (bool)true => true => FALSE

if(0) => (bool)0 => false => FALSE

if(‘0’)=> (bool) ‘0’ => false => FALSE

if([])=> (bool)[] => false => FALSE

Page 15: Ruby and comparison_and...php

if 文 => 評価 => 結果

if (‘0’ == false) => true => TRUE

if (null == false)

=> true => TRUE

Page 16: Ruby and comparison_and...php

PHP の ==

Page 17: Ruby and comparison_and...php

Ruby’s Conditional Branches

TRUE

FALSE false nil

other

Page 18: Ruby and comparison_and...php

ture => TRUE

false => FALSE

cast to bool

PHP’s Conditional Branches

Page 19: Ruby and comparison_and...php

ここまでのまとめ

• Ruby の条件分岐は nil/false か否か

• nil が特別扱い気持ち悪い(主観)

• PHP の条件分岐は bool へのキャストの結果 false か true か

• PHP には PHP なりの一貫性がある

Page 20: Ruby and comparison_and...php

と、いろいろ言ってきたけど これ全部前振り

Page 21: Ruby and comparison_and...php

本題

Page 22: Ruby and comparison_and...php

Ruby にも PHP の柔軟性を!

Page 23: Ruby and comparison_and...php
Page 24: Ruby and comparison_and...php

Ruby に PHP の 比較を導入

require ‘pebbles-php_cond’

incldue Pebbles

PhpCond::bool(0) # false

PhpCond::equal?(nil, false) # true

Page 25: Ruby and comparison_and...php
Page 26: Ruby and comparison_and...php

Ruby の比較を PHP に

require ‘pebbles-php_cond-infected’

if nil == false

put “It’s php world!!!”

end

Page 27: Ruby and comparison_and...php

Let’s PHP life! (in Ruby)

Page 28: Ruby and comparison_and...php

ありがとうございました

Page 29: Ruby and comparison_and...php

Question?