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

RubyMotion 2.0

Watson
May 29, 2013

RubyMotion 2.0

Presentation for RubyKaigi 2013

Watson

May 29, 2013
Tweet

More Decks by Watson

Other Decks in Technology

Transcript

  1. class Member attr_accessor :name def say(message) puts "My name is

    #{name}" puts message end end 13೥5݄30೔໦༵೔
  2. @implementation Kaigi -(void)join:(NSString*)name { id klass = NSClassFromString(@"Member"); id member

    = [[klass alloc] init]; [member setName:name]; [member say:@"Hello, RubyMotion Kaigi!"]; } @end class Member attr_accessor :name def say(message) puts "My name is #{name}" puts message end end 13೥5݄30೔໦༵೔
  3. @implementation Kaigi -(void)join:(NSString*)name { id klass = NSClassFromString(@"Member"); id member

    = [[klass alloc] init]; [member setName:name]; [member say:@"Hello, RubyMotion Kaigi!"]; } @end Kaigi.new.join("Shizuo") class Member attr_accessor :name def say(message) puts "My name is #{name}" puts message end end 13೥5݄30೔໦༵೔
  4. • Ruby͔ΒObjective-CΛɺObjective-C͔ΒRubyΛ ௚઀ݺͼग़͢͜ͱͱ͕Ͱ͖Δ • RubyͱObjective-Cͷ΍ΓͱΓͰσʔλม׵ෆཁ • Ruby == Objective-C •

    ΫϥεɺϝιουɺΦϒδΣΫτ͢΂ͯ Objective-C • Objective-C runtime Λར༻͠RubyΛ࣮૷ 13೥5݄30೔໦༵೔
  5. # [bc, asm].each { |x| File.unlink(x) } arch_objs << arch_obj

    /Library/RubyMotion/lib/motion/project/builder.rb : 119 comment out 13೥5݄30೔໦༵೔
  6. # [bc, asm].each { |x| File.unlink(x) } arch_objs << arch_obj

    /Library/RubyMotion/lib/motion/project/builder.rb : 119 comment out LLVM தؒίʔυ ΞηϯϒϦ ./build/iPhoneXXX/objs/ ΦϒδΣΫτ 13೥5݄30೔໦༵೔
  7. RubyMotion 2.0 • OS X Support • Project Template •

    Command-Line Plugin • Common Build Directory • Weak Reference 13೥5݄30೔໦༵೔
  8. OS X support (RubyMotion vs MacRuby) • ࣄલʹωΠςΟϒʹϑϧίϯύΠϧ • MacRuby

    ͸JITͰ࣮ߦ࣌ʹม׵ɺىಈʹ͕͔࣌ؒΔ • ελςΟοΫϥΠϒϥϦʔ͕࢖͑Δ • MacRuby ͸ίʔυमਖ਼ + OS X ͷ GC Λ༗ޮʹͯ͠ ίϯύΠϧඞཁ͕͋Δ • require ͱ evalɺඪ४ϥΠϒϥϦʔ͕࢖͑ͳ͍ ύϑΥʔϚϯε͕ 2ഒ͘Β͍ྑ͘ͳΔ 13೥5݄30೔໦༵೔
  9. Common Build Directory • rake clean ͢ΔͱશͯϏϧυ͠௚͠ • gem ϥΠϒϥϦ͸खΛՃ͑ͨΓ͠ͳ͍ͷͰɺҰ

    ౓ίϯύΠϧͨ͠Β࢖͍ճ͍ͨ͠ Ϗϧυͨ͠ϑΝΠϧ ֤ΞϓϦͰ࢖͍ճͤΔ΋ͷΛ ~/Library/RubyMotion/build ʹΩϟογϡ 13೥5݄30೔໦༵೔
  10. Weak Reference • ஋Λอ࣋͢Δ or ผͷϝιουͰར༻͢ΔͨΊʹɺ Πϯελϯεม਺ʹΦϒδΣΫτΛ֨ೲ → ڧࢀর •

    RubyMotion 1.xͰ͸ɺ • Πϯελϯεม਺Λհͨ͠ऑࢀর͕Ͱ͖·ͤΜͰͨ͠ 13೥5݄30೔໦༵೔
  11. Weak Reference class MyController def initialize(delegate) @delegate = delegate end

    def do_something # ... @delegate.did_something end end @delegateΛ࢖͍ऴΘͬͨޙɺ@delegateʹผͷΦϒδ ΣΫτ (nil౳) Λ֨ೲ͠ࢀরΛ੾Βͳ͍ͱɺ@delegate ͷࢀরݩΦϒδΣΫτ͕ղ์͞Εͳ͍ (॥؀ࢀর) 13೥5݄30೔໦༵೔
  12. Weak Reference class MyController def initialize(delegate) @delegate = WeakRef.new(delegate) end

    def do_something # ... @delegate.did_something end end WeakRef.new WeakRef.new Λ࢖ͬͯऑࢀরͰ͖ΔΑ͏ͳͬͨ 13೥5݄30೔໦༵೔