last_name) @first_name, @last_name = first_name, last_name end end chap = Earth::Person.new('Chandler', 'Bing') chap.first_name # => Chandler Tuesday 27 March 12
end end module Earth class Person include TehForce end end farm_boy = Earth::Person.new('Luke', 'Skywalker') # => '... a disturbance in the force' farm_boy.sense Tuesday 27 March 12
puts and_that_happens puts 'The sun sets' end some_days 'I do some work' other_days 'I skip', 'I read a book' def some_days( something_happens ) puts 'The sun rises' puts something_happens puts 'The sun sets' end Tuesday 27 March 12
puts 'The sun sets' end def some_days puts 'The sun rises' yield puts 'The sun sets' end some_days { puts 'I go to work' } some_days do puts 'I skip' puts 'I read a book' end Tuesday 27 March 12
end context 'Addition' do it 'returns 10 when adding 5 and 5' @calc.add(5,5).should == 10 end it 'returns 0 when adding 5 and -5' do @calc.add(5,-5).should == 0 end end # ... end Tuesday 27 March 12
'brown' end %w(height weight hair).each do |property| define_method("#{property}") do i_var = self.instance_eval("@#{property}") i_var.to_s.upcase end end def method_missing(*args, &block) puts "I dont have #{args[0].to_s.gsub(/_/, ' ')}" end end p = Person.new p.my_height # => 6.2 p.my_weight # => 70KG p.my_hair_color # => BROWN p.your_car_keys # => I dont have your car keys Tuesday 27 March 12
m.zero? return ack(m - 1, 1) if n.zero? ack( m - 1, ack(m, n - 1) ) end end public class Ackermann { public static int ack(int m, int n) { if (m == 0) return n + 1; if (n == 0) return ack(m - 1, 1); return ack(m - 1, ack(m, n - 1)); } } Tuesday 27 March 12
• Ruby interface to legacy code • Use a ruby test framework (Seriously, they’re amazing!) • Utilize java libraries • Sneak ruby into a java shop • Threading Tuesday 27 March 12