How To Use Kagemusha

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    How To Use Kagemusha - Presentation Transcript

    1. How to Use “Kagemusha\" 2007-09-29 Tatsuhiro Ujihisa at Ruby Kansai Workshop#19 1
    2. ✦ Tatsuhiro Ujihisa ✦ ruby, haskell, lisp, javascript ✦ Fuzzy Rough Sets Theory ✦ using ruby and haskell ✦ writer of Kagemusha README 2
    3. sorry for my not-good-English. 3
    4. Kagemusha 4
    5. What ✦ “Kagemusha is a library of helper functions for testing Ruby scripts.\" -- Kagemusha README 5
    6. When ✦ making mock-class for tests ✦ modifying base-class with scoped 6
    7. Who ✦ Yuya Kato ✦ My teacher of Ruby 7
    8. Are you a beginner or an advanced rubyist? 8
    9. Advanced rubyists: ✦ Let's read source codes of Kagemusha, without listening this presentation. ✦ Enjoy Hacking! 9
    10. Beginners: ✦ Here we go. 10
    11. class Fixnum def to_s \"ujihisa\" end end puts 23412 #=> ujihisa Let's try on IRB 11
    12. Open Class ✦ global side-effects \"abc\" :abc #=> #=> 1 nil 3 #=> \"a\" 3 + 5 #=> \"aa\" etc... It's crazy. »Open Class with Scope? 12
    13. Kagemusha require 'rubygems' require 'kagemusha' m = Kagemusha.new Fixnum m.def :to_s do \"ujihisa\" end m.swap do # write what you want to do puts 1 end 13
    14. class Fixnum def to_s \"ujihisa\" end end require 'rubygems' puts 23412 require 'kagemusha' #=> ujihisa m = Kagemusha.new Fixnum m.def :to_s do \"ujihisa\" end m.swap do # write what you want to do puts 1 end 14
    15. Remember these: ๏ requires ๏ Kagemusha.new ๏ Kagemusha#def, defs ๏ Kagemusha#swap That's All. 15
    16. Demonstrate ✦ Kernel#rand, Time.now, etc. ✦ on Mac OSX, zsh, screen, vim, ruby-1.8, Kagemusha-0.0.3 16
    17. Open Class Kagemusha require 'rubygems' require 'kagemusha' class Fixnum m = Kagemusha.new Fixnum def add(i) m.def :to_s do |i| self + i self + i end end def self.add(i, j) m.defs :add do |i, j| i + j end i + j end 17
    18. ✦ You can change/add any methods in the block. ✦ You can write simple, safety and clean code. 18
    19. Other styles Kagemusha.new(A) do |m| m.def(:f) {|c| puts c } m.swap do a = A.new a.f 'blocked style' end end Kagemusha.new(A). def(:f) {|c| puts c }. swap do a = A.new a.f 'chained style' end 19
    20. Default Mushas ✦ date, datetime, rand, time require 'rubygems' require 'kagemusha/rand' You have only to Kagemusha::Rand.always(1) do require these. p rand(100) p rand(100) end 20
    21. Exercise String#to_i returns 0 Fixnum#+ means minus Hash#map returns not array but hash 21
    22. That's all. Thank you! Kagemusha 22

    + ujihisaujihisa, 3 years ago

    custom

    1711 views, 0 favs, 0 embeds more stats

    ruby library kagemusha

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 1711
      • 1711 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 30
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories

    Tags