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

Ruby for Java minds

Ruby for Java minds

My talk in JRubyConf EU 2013

Jano González

August 14, 2013
Tweet

More Decks by Jano González

Other Decks in Programming

Transcript

  1. THE 5 PRINCIPLES • It should be "simple, object-oriented and

    familiar" • It should be "robust and secure" • It should be "architecture-neutral and portable" • It should execute with "high performance" • It should be "interpreted, threaded, and dynamic"
  2. Y2K

  3. EXPRESSIONS def average(a, b) (a + b) / 2 end

    # => nil average(10, 2) # => 6
  4. JAVA public void print(List<Report> reports) { if (reports == null)

    { return; } for (Report r : reports) { ReportFile file = r.generate(); ... } }
  5. DYNAMIC TYPING "Jano in " << "Berlin" # => "Jano

    in Berlin" ["Santiago"] << "Berlin" # => ["Santiago", "Berlin"]
  6. CONVERSIONS 100 + 'cool'.to_i # => 100 100 + Integer('cool')

    # ArgumentError: invalid value for Integer(): "lala"
  7. BLOCKS (1..100).select { |n| n % 3 == 0 }

    .map { |n| n * 2 } .reduce(:+)
  8. BLOCKS words.sort do |a, b| a.length <=> b.length end words.min_by?

    { |w| w.length } words.reject { |w| w.length > 8 } # etc...
  9. BLOCKS class Job def on_finish(&block) @end_callback = block end def

    execute() ... @end_callback.call(self) if @end_callback end end