SlideShare uma empresa Scribd logo
1 de 24
Baixar para ler offline
Ruby en OSX



Thursday, September 22, 11
Para que sirve Ruby


                    • Rails



Thursday, September 22, 11
Fin


                    • Gracias!
                    • Espero que os haya gustado


Thursday, September 22, 11
Ah, pero hay mas?
                    •        Rspec / Cucumber

                    •        Sinatra

                    •        Capistrano

                    •        Capybara ( webtesting )

                    •        EventMachine

                    •        FFI

                    •        nokogiri (HTML Parsing)

                    •        mocha (Mocking)

                    •        guard (FileSystem watching DSL)

                    •        .... y muchos mas!!




Thursday, September 22, 11
¿Qué es Ruby?
                    • Lenguaje interpretado
                    • Creado por Yukihiro Matsumoto - Matz
                    • Dinamico
                    • “Reflexivo”
                    • Orientado a objetos
                    • Inspirado en Perl con un toque de Smalltalk
Thursday, September 22, 11
¿Qué es Ruby?
                    •        El lenguaje no es estandar, se guia por
                             especificaciones y por la implementación “guia”

                             • MRI
                             • JRuby
                             • Rubinius
                             • IronRuby
                             • MacRuby

Thursday, September 22, 11
¿Qué mola de Ruby?
                    • Bloques
             a = [1,2,3,4,5,6,7,8,9,10]

             evens = a.select do |x|
               x % 2 == 0
             end
                  [2,4,6,8,10]
             doubles = a.map { |x| x + x }
                 [2,4,6,8,10,12,14,16,18,20]



Thursday, September 22, 11
¿Qué mola de Ruby?
                    • Todo es un objeto
             4.class
             >> Fixnum
             nil.class
             >> NilClass
             Fixnum.class
             >> Class




Thursday, September 22, 11
¿Qué mola de Ruby?
                    • Reapertura de clases
             class Fixnum
               def is_even?
                 self % 2 == 0
               end
             end

             4.is_even?
             >> true


Thursday, September 22, 11
¿Qué mola de Ruby?
                    • Envio de mensajes, respond_to?
             4.respond_to? :is_even?
             >> true

             4.send :is_even?
             >> true

             dynamic_method = “is_even?”
             4.send dynamic_method
             >> true

Thursday, September 22, 11
¿Qué mola de Ruby?
                    • Method missing
             class WeirdString < String
               def method_missing m, *args, &block
                 self.send m.to_s.reverse
               end
             end

             t = WeirdString.new “PrUebA”
             t.esacnwod
             >> “prueba”

Thursday, September 22, 11
¿Qué mola de Ruby?

                    • procs / lambdas
                    • eval
                    • DSL
                    • mixins
                    • regexps

Thursday, September 22, 11
Ruby en OSX
                    • Preinstalado desde Leopard
                     • Version 1.8
                    • Scripting Bridge
                    • RubyCocoa => MacRuby
                    • Lenguaje soportado en applicaciones
                             del MacAppStore

Thursday, September 22, 11
Ruby en OSX

                    •        MacRuby es la evolucion de RubyCocoa

                    •        Gracias a RubyCocoa / MacRuby

                             •   TOTAL INTEROPERABILIDAD CON OBJC

                             •   Todo lo de la diapositiva 4, es interoperable con
                                 nuestras clases Objective-C

                    •        Sustituto de AppleScript gracias al Scripting Bridge



Thursday, September 22, 11
MacRuby vs RubyCocoa

                    •        MacRuby es el futuro pero,

                             •   RubyCocoa viene instalado en OSX por defecto

                             •   MacRuby tiene que ser embebido en la
                                 aplicación

                    •        RubyCocoa -> 1.8

                    •        MacRuby -> 1.9

                             •   Mejoras velocidad, Threads, GC


Thursday, September 22, 11
MacRuby vs RubyCocoa
                    •        Sintaxis
                      objc
                      [[NSWindow alloc] initWithContentRect:styleMask:backing:defer:]
                      RubyCocoa
                      NSWindow.alloc.initWithContentRect_styleMask_backing_defer (...)
                      MacRuby
                      NSWindow.alloc.initWithContentRect( ..., styleMask:..., backing:...,
                      defer...

                    •        Integración de clases en MacRuby

                             •   String, Number,... de Ruby -> NSString, NSNumber, ...

                             •   Elimina la necesidad de proxies

                    •        MacRuby compila contra LLVM -> Posibilidad de generar binarios nativos



Thursday, September 22, 11
MacRuby
                                               Objective-C
                     @interface Book

                     @property (retain, nonatomic) NSString *title

                     - (void) addBookToLibrary:(NSString*) theLibrary
                     - (void) insertPage: (Page*) thePage atPosition: (NSUInteger)
                     position

                     @end


                                                  Ruby
                     b = Book.new
                     b.title = “My new book”
                     b.addBookToLibrary “The Great Library”
                     b.insertPage myPage, :atPosition => 4
                     - OR -
                     b.insertPage myPage, atPosition: 4




Thursday, September 22, 11
MacRuby
       framework 'Cocoa'
                                                          win.title = "Hello NSCoder"
       class AppDelegate                                  win.delegate = delegate
         def windowWillClose n
           exit                                           button = NSButton.alloc.initWithFrame
         end                                              [10,10,80,50]
                                                          button.title = "Hello!"
         def hello sender                                 button.target = delegate
           puts "Hello World!"                            button.action = :hello
         end
       end                                                win.contentView.addSubview button

       delegate = AppDelegate.new                         win.display
       app = NSApplication.sharedApplication              win.orderFrontRegardless
       app.delegate = delegate                            app.run

       win = NSWindow.
                 alloc.
                 initWithContentRect [200,300,100,100],
                 :styleMask => NSTitledWindowMask
                 :backing => NSBackingStoreBuffered,
                 :defer => false




Thursday, September 22, 11
MacRuby
                    • XCode (& InterfaceBuilder) compatible




Thursday, September 22, 11
MacRuby
                    •        Aplicaciones subidas al Mac AppStore

                             •   http://www.thumperapp.com/

                             •   http://luckymac.com/ - Music Streaming

                             •   http://redwoodapp.com/ - Spotlight in the cloud




Thursday, September 22, 11
Scripting Bridge

                    •        Interfaz que puede dar un programa para facilitar la comunicación con él

                    •        Basado en Apple Events

                             •   Antes de SB, esos Apple Events se enviaban, o bien con Apple Script o
                                 con un código en Objective-C no muy sencillo

                             •   Con SB, los Apple Events se pueden enviar como un mensaje mas de
                                 Objective-C (Aparte de seguir usando AppleScript)

                                 •   Y por ello, accesible desde Ruby (RubyCocoa) o PyObjC




Thursday, September 22, 11
SB y Ruby
                    • Copiar la ruta del fichero seleccionado en
                             el Finder al clipboard

                require 'osx/cocoa'
                include OSX
                OSX.require_framework 'ScriptingBridge'

                finder = SBApplication.applicationWithBundleIdentifier_ “com.apple.finder”
                fileURL = NSURL.URLWithString_ finder.selection.get[0].URL
                system "echo #{fileURL.path} | pbcopy”




Thursday, September 22, 11
SB y Ruby
                    • Obtener las canciones de tu iTunes
                require 'osx/cocoa'
                include OSX
                OSX.require_framework 'ScriptingBridge'

                iTunes = SBApplication.applicationWithBundleIdentifier_ "com.apple.iTunes"

                iTunes.sources.each do |source|
                  puts source.name
                  source.playlists.each do |playlist|
                    puts "-- #{playlist.name}"
                    playlist.tracks.each do |track|
                      puts "t-- #{track.name}"
                    end
                  end
                end




Thursday, September 22, 11
Fin

                    • Gracias ;)



                    • Use Ruby

Thursday, September 22, 11

Mais conteúdo relacionado

Mais procurados

State of the art: server-side javaScript - NantesJS
State of the art: server-side javaScript - NantesJSState of the art: server-side javaScript - NantesJS
State of the art: server-side javaScript - NantesJS
Alexandre Morgaut
 

Mais procurados (20)

The Enterprise Strikes Back
The Enterprise Strikes BackThe Enterprise Strikes Back
The Enterprise Strikes Back
 
Invokedynamic in 45 Minutes
Invokedynamic in 45 MinutesInvokedynamic in 45 Minutes
Invokedynamic in 45 Minutes
 
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
 
MacRuby: What is it? and why should you care?
MacRuby: What is it? and why should you care?MacRuby: What is it? and why should you care?
MacRuby: What is it? and why should you care?
 
Devignition 2011
Devignition 2011Devignition 2011
Devignition 2011
 
Complex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBoxComplex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBox
 
TorqueBox for Rubyists
TorqueBox for RubyistsTorqueBox for Rubyists
TorqueBox for Rubyists
 
Invokedynamic: Tales from the Trenches
Invokedynamic: Tales from the TrenchesInvokedynamic: Tales from the Trenches
Invokedynamic: Tales from the Trenches
 
Ruby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developerRuby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developer
 
Using Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRBUsing Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRB
 
JUDCon 2010 Boston : TorqueBox
JUDCon 2010 Boston : TorqueBoxJUDCon 2010 Boston : TorqueBox
JUDCon 2010 Boston : TorqueBox
 
Testing Ember Apps
Testing Ember AppsTesting Ember Apps
Testing Ember Apps
 
An introduction and future of Ruby coverage library
An introduction and future of Ruby coverage libraryAn introduction and future of Ruby coverage library
An introduction and future of Ruby coverage library
 
Rake: Not Your Father's Build Tool
Rake: Not Your Father's Build ToolRake: Not Your Father's Build Tool
Rake: Not Your Father's Build Tool
 
JRuby in Java Projects
JRuby in Java ProjectsJRuby in Java Projects
JRuby in Java Projects
 
Type script, for dummies
Type script, for dummiesType script, for dummies
Type script, for dummies
 
Vert.x
Vert.xVert.x
Vert.x
 
Connecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRubyConnecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRuby
 
How to distribute Ruby to the world
How to distribute Ruby to the worldHow to distribute Ruby to the world
How to distribute Ruby to the world
 
State of the art: server-side javaScript - NantesJS
State of the art: server-side javaScript - NantesJSState of the art: server-side javaScript - NantesJS
State of the art: server-side javaScript - NantesJS
 

Semelhante a Charla ruby nscodermad

JRuby - The Best of Java and Ruby
JRuby - The Best of Java and RubyJRuby - The Best of Java and Ruby
JRuby - The Best of Java and Ruby
Evgeny Rahman
 
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Nilesh Panchal
 
Ruby :: Training 1
Ruby :: Training 1Ruby :: Training 1
Ruby :: Training 1
Pavel Tyk
 
Adventures of java developer in ruby world
Adventures of java developer in ruby worldAdventures of java developer in ruby world
Adventures of java developer in ruby world
Orest Ivasiv
 

Semelhante a Charla ruby nscodermad (20)

Developing Cocoa Applications with macRuby
Developing Cocoa Applications with macRubyDeveloping Cocoa Applications with macRuby
Developing Cocoa Applications with macRuby
 
JRuby - The Best of Java and Ruby
JRuby - The Best of Java and RubyJRuby - The Best of Java and Ruby
JRuby - The Best of Java and Ruby
 
ruby-cocoa
ruby-cocoaruby-cocoa
ruby-cocoa
 
ruby-cocoa
ruby-cocoaruby-cocoa
ruby-cocoa
 
10 Things you should know about Ruby
10 Things you should know about Ruby10 Things you should know about Ruby
10 Things you should know about Ruby
 
Initiation à Ruby on Rails
Initiation à Ruby on RailsInitiation à Ruby on Rails
Initiation à Ruby on Rails
 
Ruby On Rails pizza training
Ruby On Rails pizza trainingRuby On Rails pizza training
Ruby On Rails pizza training
 
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLExploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQL
 
Setup ruby
Setup rubySetup ruby
Setup ruby
 
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
 
RubyConf 2009
RubyConf 2009RubyConf 2009
RubyConf 2009
 
Why ruby
Why rubyWhy ruby
Why ruby
 
Week6
Week6Week6
Week6
 
JRubyConf 2009
JRubyConf 2009JRubyConf 2009
JRubyConf 2009
 
Ruby for C#-ers (ScanDevConf 2010)
Ruby for C#-ers (ScanDevConf 2010)Ruby for C#-ers (ScanDevConf 2010)
Ruby for C#-ers (ScanDevConf 2010)
 
cassandra
cassandracassandra
cassandra
 
Ruby :: Training 1
Ruby :: Training 1Ruby :: Training 1
Ruby :: Training 1
 
Adventures of java developer in ruby world
Adventures of java developer in ruby worldAdventures of java developer in ruby world
Adventures of java developer in ruby world
 
Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1
 
RubyConfBD 2013 decouple, bundle and share with ruby gems
RubyConfBD 2013   decouple, bundle and share with ruby gems RubyConfBD 2013   decouple, bundle and share with ruby gems
RubyConfBD 2013 decouple, bundle and share with ruby gems
 

Último

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Último (20)

DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 

Charla ruby nscodermad

  • 1. Ruby en OSX Thursday, September 22, 11
  • 2. Para que sirve Ruby • Rails Thursday, September 22, 11
  • 3. Fin • Gracias! • Espero que os haya gustado Thursday, September 22, 11
  • 4. Ah, pero hay mas? • Rspec / Cucumber • Sinatra • Capistrano • Capybara ( webtesting ) • EventMachine • FFI • nokogiri (HTML Parsing) • mocha (Mocking) • guard (FileSystem watching DSL) • .... y muchos mas!! Thursday, September 22, 11
  • 5. ¿Qué es Ruby? • Lenguaje interpretado • Creado por Yukihiro Matsumoto - Matz • Dinamico • “Reflexivo” • Orientado a objetos • Inspirado en Perl con un toque de Smalltalk Thursday, September 22, 11
  • 6. ¿Qué es Ruby? • El lenguaje no es estandar, se guia por especificaciones y por la implementación “guia” • MRI • JRuby • Rubinius • IronRuby • MacRuby Thursday, September 22, 11
  • 7. ¿Qué mola de Ruby? • Bloques a = [1,2,3,4,5,6,7,8,9,10] evens = a.select do |x| x % 2 == 0 end [2,4,6,8,10] doubles = a.map { |x| x + x } [2,4,6,8,10,12,14,16,18,20] Thursday, September 22, 11
  • 8. ¿Qué mola de Ruby? • Todo es un objeto 4.class >> Fixnum nil.class >> NilClass Fixnum.class >> Class Thursday, September 22, 11
  • 9. ¿Qué mola de Ruby? • Reapertura de clases class Fixnum def is_even? self % 2 == 0 end end 4.is_even? >> true Thursday, September 22, 11
  • 10. ¿Qué mola de Ruby? • Envio de mensajes, respond_to? 4.respond_to? :is_even? >> true 4.send :is_even? >> true dynamic_method = “is_even?” 4.send dynamic_method >> true Thursday, September 22, 11
  • 11. ¿Qué mola de Ruby? • Method missing class WeirdString < String def method_missing m, *args, &block self.send m.to_s.reverse end end t = WeirdString.new “PrUebA” t.esacnwod >> “prueba” Thursday, September 22, 11
  • 12. ¿Qué mola de Ruby? • procs / lambdas • eval • DSL • mixins • regexps Thursday, September 22, 11
  • 13. Ruby en OSX • Preinstalado desde Leopard • Version 1.8 • Scripting Bridge • RubyCocoa => MacRuby • Lenguaje soportado en applicaciones del MacAppStore Thursday, September 22, 11
  • 14. Ruby en OSX • MacRuby es la evolucion de RubyCocoa • Gracias a RubyCocoa / MacRuby • TOTAL INTEROPERABILIDAD CON OBJC • Todo lo de la diapositiva 4, es interoperable con nuestras clases Objective-C • Sustituto de AppleScript gracias al Scripting Bridge Thursday, September 22, 11
  • 15. MacRuby vs RubyCocoa • MacRuby es el futuro pero, • RubyCocoa viene instalado en OSX por defecto • MacRuby tiene que ser embebido en la aplicación • RubyCocoa -> 1.8 • MacRuby -> 1.9 • Mejoras velocidad, Threads, GC Thursday, September 22, 11
  • 16. MacRuby vs RubyCocoa • Sintaxis objc [[NSWindow alloc] initWithContentRect:styleMask:backing:defer:] RubyCocoa NSWindow.alloc.initWithContentRect_styleMask_backing_defer (...) MacRuby NSWindow.alloc.initWithContentRect( ..., styleMask:..., backing:..., defer... • Integración de clases en MacRuby • String, Number,... de Ruby -> NSString, NSNumber, ... • Elimina la necesidad de proxies • MacRuby compila contra LLVM -> Posibilidad de generar binarios nativos Thursday, September 22, 11
  • 17. MacRuby Objective-C @interface Book @property (retain, nonatomic) NSString *title - (void) addBookToLibrary:(NSString*) theLibrary - (void) insertPage: (Page*) thePage atPosition: (NSUInteger) position @end Ruby b = Book.new b.title = “My new book” b.addBookToLibrary “The Great Library” b.insertPage myPage, :atPosition => 4 - OR - b.insertPage myPage, atPosition: 4 Thursday, September 22, 11
  • 18. MacRuby framework 'Cocoa' win.title = "Hello NSCoder" class AppDelegate win.delegate = delegate def windowWillClose n exit button = NSButton.alloc.initWithFrame end [10,10,80,50] button.title = "Hello!" def hello sender button.target = delegate puts "Hello World!" button.action = :hello end end win.contentView.addSubview button delegate = AppDelegate.new win.display app = NSApplication.sharedApplication win.orderFrontRegardless app.delegate = delegate app.run win = NSWindow. alloc. initWithContentRect [200,300,100,100], :styleMask => NSTitledWindowMask :backing => NSBackingStoreBuffered, :defer => false Thursday, September 22, 11
  • 19. MacRuby • XCode (& InterfaceBuilder) compatible Thursday, September 22, 11
  • 20. MacRuby • Aplicaciones subidas al Mac AppStore • http://www.thumperapp.com/ • http://luckymac.com/ - Music Streaming • http://redwoodapp.com/ - Spotlight in the cloud Thursday, September 22, 11
  • 21. Scripting Bridge • Interfaz que puede dar un programa para facilitar la comunicación con él • Basado en Apple Events • Antes de SB, esos Apple Events se enviaban, o bien con Apple Script o con un código en Objective-C no muy sencillo • Con SB, los Apple Events se pueden enviar como un mensaje mas de Objective-C (Aparte de seguir usando AppleScript) • Y por ello, accesible desde Ruby (RubyCocoa) o PyObjC Thursday, September 22, 11
  • 22. SB y Ruby • Copiar la ruta del fichero seleccionado en el Finder al clipboard require 'osx/cocoa' include OSX OSX.require_framework 'ScriptingBridge' finder = SBApplication.applicationWithBundleIdentifier_ “com.apple.finder” fileURL = NSURL.URLWithString_ finder.selection.get[0].URL system "echo #{fileURL.path} | pbcopy” Thursday, September 22, 11
  • 23. SB y Ruby • Obtener las canciones de tu iTunes require 'osx/cocoa' include OSX OSX.require_framework 'ScriptingBridge' iTunes = SBApplication.applicationWithBundleIdentifier_ "com.apple.iTunes" iTunes.sources.each do |source| puts source.name source.playlists.each do |playlist| puts "-- #{playlist.name}" playlist.tracks.each do |track| puts "t-- #{track.name}" end end end Thursday, September 22, 11
  • 24. Fin • Gracias ;) • Use Ruby Thursday, September 22, 11