Ruby presentation/Planning

From WhyNotWiki
Jump to: navigation, search

To do

  • done!

Rejected / didn't cover

  • My background
    • on team rewriting [everything] in Ruby
  • no arbitrary restrictions about what you can or cannot do... if you can do it here, you can expect to be able to do the same thing over here too...principle of least surprise
  • Roman numeral class example (p. 376) (coercion)
  • What can it be used for (practically everything)
  • Aspect-oriented programming in Ruby
  • Comparison to other popular languages: PHP, Java
  • Criticism/shortcomings of Ruby (it's not perfect)
    • most common beginner mistakes
    • performance
  • Real-world examples?

[1]

  • to_proc cool example

If something doesn't work the way you want it to in one of the core classes (or in a 3rd arty library), you can easily (some might say too easily) change it... Example:

irb -> {'a' => 1, 'b' => 2} + {1=>2}
NoMethodError: undefined method `+' for {"a"=>1, "b"=>2}:Hash

add Hash+ !!!

You can also monkey patch (double-check semantics) it... alias/override...


Once you taste a real OO language, you'll never want to program in anything else (a sort of OO language) again.


def factory(klass, arg)
  klass.new(arg)
end

factory(String, 'initial value')
=> "initial value"
  • Everything is an object
    • even top-level execution environment (p. 393)
    • classes are objects too (p. 392)
    • methods are objects too (a = A.method(:a); a.call)
Ads
Personal tools