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

Using Ruby in a Non-Ruby World

Using Ruby in a Non-Ruby World

4d6be90af74894fd132fb06dacec04d7?s=128

Samuel E. Giddins

March 04, 2015
Tweet

More Decks by Samuel E. Giddins

Other Decks in Technology

Transcript

  1. Using Ruby in a Non-Ruby World

  2. Samuel Giddins Realm CocoaPods Bundler

  3. Show of hands: Who writes Ruby for a living?

  4. Show of hands: Who uses something built in Ruby every

    day?
  5. Let’s name some

  6. Those are some great tools! Do you think their utility

    is limited to Ruby developers?
  7. No

  8. I write Ruby every day

  9. I write Ruby every day => I am a Rubyist

  10. Let’s look at some of the tools we use: —

    rvm/rbenv/chruby — Bundler — Native extensions
  11. Version Managers

  12. For me: $ rbenv versions | wc -l 13 $

    ruby -v 2.2.0p0
  13. For others: $ which ruby /usr/bin/ruby $ ruby -v 2.0.0p353

    # And be thankful it's not 1.8.7
  14. Can’t you just update to 2.1.5? Not particularly helpful.

  15. Bundler

  16. Bundler Is wonderful.

  17. But most people want to install a tool once and

    forget about it.
  18. Yeah, they should use a Gemfile. But they won’t.

  19. So your gem will be polluting their global namespace.

  20. Native Extensions

  21. They’re such a pain.

  22. Compilation as part of the CocoaPods gem install process is

    dead. Long live precompiled gems! — CocoaPods 0.27 and improved installation UX
  23. Not everyone needs to have a compiler installed. Or the

    Ruby headers. Or a proper build setup.
  24. Not everyone needs to have a compiler installed. Or the

    Ruby headers. Or a proper build setup. And they shouldn't need to
  25. In this ‘developer bubble’ there is no sane Ruby environment

    unless you at least build your own Ruby, but preferably including one or more of the following tools: homebrew, RVM, rbenv, and many other alternatives.
  26. And Now For The Fun Part

  27. Let’s get positive.

  28. DSLs

  29. Ruby is awesome for building DSLs.

  30. source 'https://github.com/CocoaPods/Specs.git' target 'iOS' do pod 'Realm' pod 'RestKit', git:

    'https://github.com/RestKit/RestKit.git' end
  31. It barely even looks like code!

  32. Pod::Specification.new do |s| s.name = 'Realm' s.version = `sh build.sh

    get-version`.chomp end
  33. That definitely is starting to seem more like code.

  34. The difference?

  35. BasicObject.instance_eval # the first # vs Kernel.eval # the second

  36. If someone doesn’t realize they’re writing Ruby, you’ve done a

    ! job.
  37. — Ruby 1.9 hash syntax - ! — Curly brace

    procs & lambdas - " — do...end blocks - ! — Symbol parameters - " — def f(*args); end - !
  38. Hide the Ruby out back.

  39. NoMethodError - undefined method `[]' for #<Xcodeproj::Project::Object::PBXFileReference:0x007fcf522734a8> /usr/local/lib/ruby/gems/2.1.0/gems/cocoapods-0.36.0.rc.1/lib/cocoapods/project.rb:186:in `block in

    add_file_reference' /usr/local/Cellar/ruby/2.1.3_1/lib/ruby/2.1.0/pathname.rb:266:in `block in each_filename' /usr/local/Cellar/ruby/2.1.3_1/lib/ruby/2.1.0/pathname.rb:266:in `each' /usr/local/Cellar/ruby/2.1.3_1/lib/ruby/2.1.0/pathname.rb:266:in `each_filename' /usr/local/lib/ruby/gems/2.1.0/gems/cocoapods-0.36.0.rc.1/lib/cocoapods/project.rb:184:in `add_file_reference' /usr/local/lib/ruby/gems/2.1.0/gems/cocoapods-0.36.0.rc.1/lib/cocoapods/installer/file_references_installer.rb:168:in `block (2 levels) in add_file_accessors_paths_to_pods_group' /usr/local/lib/ruby/gems/2.1.0/gems/cocoapods-0.36.0.rc.1/lib/cocoapods/installer/file_references_installer.rb:166:in `each' /usr/local/lib/ruby/gems/2.1.0/gems/cocoapods-0.36.0.rc.1/lib/cocoapods/installer/file_references_installer.rb:166:in `block in add_file_accessors_paths_to_pods_group' /usr/local/lib/ruby/gems/2.1.0/gems/cocoapods-0.36.0.rc.1/lib/cocoapods/installer/file_references_installer.rb:162:in `each' /usr/local/lib/ruby/gems/2.1.0/gems/cocoapods-0.36.0.rc.1/lib/cocoapods/installer/file_references_installer.rb:162:in `add_file_accessors_paths_to_pods_group' /usr/local/lib/ruby/gems/2.1.0/gems/cocoapods-0.36.0.rc.1/lib/cocoapods/installer/file_references_installer.rb:103:in `block in add_resources' /usr/local/lib/ruby/gems/2.1.0/gems/cocoapods-0.36.0.rc.1/lib/cocoapods/user_interface.rb:110:in `message' /usr/local/lib/ruby/gems/2.1.0/gems/cocoapods-0.36.0.rc.1/lib/cocoapods/installer/file_references_installer.rb:102:in `add_resources' /usr/local/lib/ruby/gems/2.1.0/gems/cocoapods-0.36.0.rc.1/lib/cocoapods/installer/file_references_installer.rb:38:in `install!' /usr/local/lib/ruby/gems/2.1.0/gems/cocoapods-0.36.0.rc.1/lib/cocoapods/installer.rb:486:in `install_file_references' /usr/local/lib/ruby/gems/2.1.0/gems/cocoapods-0.36.0.rc.1/lib/cocoapods/installer.rb:130:in `block in generate_pods_project' /usr/local/lib/ruby/gems/2.1.0/gems/cocoapods-0.36.0.rc.1/lib/cocoapods/user_interface.rb:49:in `section' /usr/local/lib/ruby/gems/2.1.0/gems/cocoapods-0.36.0.rc.1/lib/cocoapods/installer.rb:128:in `generate_pods_project' /usr/local/lib/ruby/gems/2.1.0/gems/cocoapods-0.36.0.rc.1/lib/cocoapods/installer.rb:96:in `install!' /usr/local/lib/ruby/gems/2.1.0/gems/cocoapods-0.36.0.rc.1/lib/cocoapods/command/project.rb:71:in `run_install_with_update' /usr/local/lib/ruby/gems/2.1.0/gems/cocoapods-0.36.0.rc.1/lib/cocoapods/command/project.rb:101:in `run' /usr/local/lib/ruby/gems/2.1.0/gems/claide-0.8.1/lib/claide/command.rb:312:in `run' /usr/local/lib/ruby/gems/2.1.0/gems/cocoapods-0.36.0.rc.1/lib/cocoapods/command.rb:46:in `run' /usr/local/lib/ruby/gems/2.1.0/gems/cocoapods-0.36.0.rc.1/bin/pod:44:in `<top (required)>' /usr/local/bin/pod:23:in `load' /usr/local/bin/pod:23:in `<main>'
  40. [!] Installation could not proceed because an unexpected object was

    found in your project file.
  41. Be Friendly

  42. Sure, these tips are designed to keeps Ruby newcomers happy.

  43. Sure, these tips are designed to keeps Ruby newcomers happy.

    But they also make your software much friendlier.
  44. Available now on Speaker Deck. https://speakerdeck.com/segiddins/using-ruby-in-a- non-ruby-world

  45. puts Question.all.map(&:ask?).map(&:answer!)

  46. Samuel Giddins Realm @segiddins