Save 37% off PRO during our Black Friday Sale! »

RailsはRubyだ

Ad6c3628aba9c357f42e412468e39732?s=47 yoppi
December 13, 2012

 RailsはRubyだ

Railsアプリを作るときにlibを意識しようという話を社内でしました。

Ad6c3628aba9c357f42e412468e39732?s=128

yoppi

December 13, 2012
Tweet

Transcript

  1. Rails͸Rubyͩ @yoppiblog Aktsuki.inc 12೥5݄30೔ਫ༵೔

  2. 001 12೥5݄30೔ਫ༵೔

  3. Input Output ここ! 12೥5݄30೔ਫ༵೔

  4. Input Output 12೥5݄30೔ਫ༵೔

  5. Object Oriented Programming w ϞδϡʔϧੑΛҙࣝ͢Δ w ֦ுੑ w ࠶ར༻ੑ w

    ͢΂ͯ͸඼࣭޲্ͱӡ༻อकͷͨΊ 12೥5݄30೔ਫ༵೔
  6. )PX 12೥5݄30೔ਫ༵೔

  7. Testable Code • ςετΛॻ͘͜ͱͰڧ੍తʹϞδϡʔϧ Λҙࣝ͢Δ͜ͱʹͳΔ • ΠϯλϑΣʔεઃܭྗΛ਎ʹ͚ͭΔ 12೥5݄30೔ਫ༵೔

  8. Rails͸Ruby 12೥5݄30೔ਫ༵೔

  9. Ruby application • bin/ • lib/ • spec/ • Rakefile

    • Gemfile • ... 12೥5݄30೔ਫ༵೔
  10. Rails Application • app/ • lib/ • config/ • db/

    • spec/ • Rakefile • Gemfile 12೥5݄30೔ਫ༵೔
  11. lib/ 12೥5݄30೔ਫ༵೔

  12. • RubyΞϓϦͷࠜװͱͳΔ෦෼ • RailsΞϓϦͰ͸monkey patchίʔυ΍ gemͷ֦ுίʔυɺϩδοΫϞδϡʔϧ Λઃஔ͢Δ lib/ 12೥5݄30೔ਫ༵೔

  13. case study 12೥5݄30೔ਫ༵೔

  14. KingΠϕϯτ • Ϙεότϧ • ใु • ϙΠϯτ෇༩ 12೥5݄30೔ਫ༵೔

  15. event_king • lib/event_king.rb • lib/event_king/ • battle.rb • gift.rb •

    point.rb • spec/lib/event_king/ 12೥5݄30೔ਫ༵೔
  16. # lib/event_king.rb module EventKing require 'event_king/battle' require 'event_king/gift' require 'event_king/point'

    end module loader 12೥5݄30೔ਫ༵೔
  17. ότϧ # lib/event_king/battle.rb module EventKing class Battle def initialize(deck, boss)

    ... end def battle! ... end end end 12೥5݄30೔ਫ༵೔
  18. ใु # lib/event_king/gift.rb module EventKing class Gift def initialize(status) ...

    end def distribute ... end end end 12೥5݄30೔ਫ༵೔
  19. ϙΠϯτ෇༩ # lib/event_king/point.rb module EventKing class Point def initialize(status) ...

    end def distribute ... end end end 12೥5݄30೔ਫ༵೔
  20. Controller # app/controller/ user_event_king_boss_battle_logs.rb require ‘event_king’ class UserEventKingBossBattleLogsController def create

    ... battle = EventKing::Battle.new(deck, boss) battle.battle! log = Log.create(battle) ... end end 12೥5݄30೔ਫ༵೔
  21. ·ͱΊ • Rails͸RubyΞϓϦέʔγϣϯͷͻͱͭ • testableͳίʔυΛॻ͘͜ͱͰશମͷ඼ ࣭Λอͪͭͭӡ༻ָ͕ʹͳΔ • ϦϑΝΫλϦϯάΛڪΕͳ͍ • ςετॻ͖·͠ΐ͏

    12೥5݄30೔ਫ༵೔
  22. ࢀߟจݙ • ΦϒδΣΫτࢦ޲ೖ໳ ্/Լ • ॳΊͯͷRuby • Ruby ϕετϓϥΫςΟε •

    ਺ଟ͋ΔΦʔϓϯιʔεͷίʔυ 12೥5݄30೔ਫ༵೔