Your SlideShare is downloading. ×
0
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Mangling Ruby with TracePoint
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Mangling Ruby with TracePoint

1,212

Published on

Presented at RubyConf 11/10/2013 …

Presented at RubyConf 11/10/2013

Introduced in Ruby 2.0, TracePoint is meant to help developers better instrument their code for debugging and performance reasons, but there's more to TracePoint than that!

In this talk we'll learn about TracePoint while building several example projects. Once we know the basics we'll use TracePoint to do things to Ruby that we couldn't have done otherwise.

By the end of this talk you'll be able to frighten and amaze your friends when you show them things like true abstract classes and interfaces in Ruby, just like Java! Yikes!

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,212
On Slideshare
0
From Embeds
0
Number of Embeds
9
Actions
Shares
0
Downloads
6
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. @markbates
  • 2. http://mo.markbates.com
  • 3. RUBYCONF13 http://www.metacasts.tv
  • 4. Mangling Ruby with TracePoint
  • 5. TracePoint
  • 6. trace = TracePoint.new(:raise) do |tp| p [tp.lineno, tp.event, tp.raised_exception] end #=> #<TracePoint:0x007f786a452448> ! trace.enable #=> #<TracePoint:0x007f786a452448> ! 0 / 0 #=> [5, :raise, #<ZeroDivisionError: divided by 0>]
  • 7. Events
  • 8. TracePoint.new(:class) TracePoint.new(:end)
  • 9. TracePoint.new(:call) TracePoint.new(:return) TracePoint.new(:c_call) TracePoint.new(:c_return)
  • 10. TracePoint.new(:raise)
  • 11. TracePoint.new(:b_call) TracePoint.new(:b_return)
  • 12. TracePoint.new(:thread_begin) TracePoint.new(:thread_end)
  • 13. Demo
  • 14. Method Call Collector
  • 15. TracePoint: disable enable 1 1 Object: puts at_exit 1 1 ! ! Class: new method_added inherited 1 1 1 Foo: bar initialize 1 1 IO: write puts 2 1 Symbol: to_proc 1 Array: map 1 ! ! ! ! ------------Totals: Class 3 IO 3 Object 2 TracePoint 2 Foo 2 Symbol 1 Array 1 ! ! Total Method Calls: 14
  • 16. Total Method Calls: 122538
  • 17. Class Rails::Initializable::Initializer Symbol Module String Array Hash Fixnum Object ActionDispatch::Journey::Visitors::Each File Rails::Paths::Path Regexp ThreadSafe::Cache 25888 16502 14136 12727 11379 6080 4479 3108 2499 2276 1888 1655 1190 1026
  • 18. HelloController: class process_action lookup_context initialize instance_variable_defined? method_for_action respond_to? render _normalize_options render_to_body _process_options block_given? dispatch view_renderer _render_template process append_info_to_payload _prefixes response_body= config instance_variable_get _normalize_args cleanup_view_runtime 13 7 4 4 4 3 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2 2 2
  • 19. Demo
  • 20. jRuby
  • 21. Abstract Interfaces IN RUBY!
  • 22. Please Don’t! Actually Do This!
  • 23. interface Bicycle { void changeGear(int newValue); void speedUp(int increment); void applyBrakes(int decrement); } ! public class ACMEBicycle implements Bicycle { public void changeGear(int newValue) { // do some work here } public void speedUp(int increment) { // do some work here } public void applyBrakes(int decrement) { // do some work here } }
  • 24. module ApiInterface include AbstractInterface abstract_method :get, :put end ! class HttpLibrary include ApiInterface end
  • 25. module ApiInterface include AbstractInterface abstract_method :get, :put end ! class HttpLibrary include ApiInterface end
  • 26. module ApiInterface include AbstractInterface abstract_method :get, :put end ! class HttpLibrary include ApiInterface def get end def put end end
  • 27. module ApiInterface include AbstractInterface abstract_method :get, :put end ! class HttpLibrary include ApiInterface end
  • 28. @markbates http://www.metacasts.tv

×