Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ちょっとしたRubyの話

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for t0yohei t0yohei
November 11, 2018

 ちょっとしたRubyの話

Avatar for t0yohei

t0yohei

November 11, 2018
Tweet

More Decks by t0yohei

Other Decks in Technology

Transcript

  1. Rubyとは • 1993年にMatzが開発 • OSS言語 • Ruby on Railsとは切っても切れない縁 •

    Rubyの実装はC言語でされている • そのため、MatzはRubyエンジニアではなくCエンジニア
  2. 動的型付けの特性を生かしたダックタイピング • 引数に渡したobjectが、そのメソッドを持っていたら実行できる • ex) def count_object(object) p object.count end

    object = [1, 2, 3] count_object(object) #結果 => 3 object = “123” count_object(object) #結果 => 3 object = { 1 => “1”, 2 => 2 , 3 => “3” } count_object(object) #結果 => 3 String Array Hash count_objectというメソッドを定義 引数は一つ(型はなんでもいい)
  3. 小話 Q. 次の配列arrayAから配列arrayBの要素を取り除くには?? arrayA = [1, 2, 3] arrayB =

    [1, 2] → 配列arrayAから配列arrayBから、型: Array、要素: 1 の配列を作りたい ex) arrayC = [1] https://twitter.com/bendhalpern/status/1060965181759635456 変数名: arrayA、型: Array 変数名: arrayB、型: Array