SlideShare a Scribd company logo
1 of 106
Download to read offline
Code Diving in Ruby
Evan Dorn
Founder, Logical Reality Design
http://lrdesign.com
evan@lrdesign.com
@idahoev
Friday, August 9, 13
SO YOU’RE CODING
ALONG WHEN...
Friday, August 9, 13
1) InvoicesController as an admin GET index should paginate all unpaid invoices as
@unpaid_invoices
Failure/Error: get :index
NoMethodError:
undefined method `unpayed' for #<Class:0x007fd8cfe9ee18>
# /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
activerecord-3.2.12/lib/active_record/dynamic_matchers.rb:55:in `method_missing'
# ./app/controllers/invoices_controller.rb:7:in `index'
# /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
actionpack-3.2.12/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
# /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
actionpack-3.2.12/lib/abstract_controller/base.rb:167:in `process_action'
# /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
actionpack-3.2.12/lib/action_controller/metal/rendering.rb:10:in `process_action'
# /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
actionpack-3.2.12/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
# /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
activesupport-3.2.12/lib/active_support/callbacks.rb:447:in
`_run__3859364058582123788__process_action__4176185741589430016__callbacks'
# /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
activesupport-3.2.12/lib/active_support/callbacks.rb:405:in `__run_callback'
# /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
activesupport-3.2.12/lib/active_support/callbacks.rb:385:in
`_run_process_action_callbacks'
# /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
activesupport-3.2.12/lib/active_support/callbacks.rb:81:in `run_callbacks'
# /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
actionpack-3.2.12/lib/abstract_controller/callbacks.rb:17:in `process_action'
# /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
actionpack-3.2.12/lib/action_controller/metal/rescue.rb:29:in `process_action'
# /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
actionpack-3.2.12/lib/action_controller/metal/instrumentation.rb:30:in `block in
process_action'
Friday, August 9, 13
AND YOU’RE LIKE
Friday, August 9, 13
BUT THEN YOU NOTICE
THIS...
Friday, August 9, 13
1) InvoicesController as an admin GET index should paginate all unpaid invoices as
@unpaid_invoices
Failure/Error: get :index
NoMethodError:
undefined method `unpayed' for #<Class:0x007fd8cfe9ee18>
# /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
activerecord-3.2.12/lib/active_record/dynamic_matchers.rb:55:in `method_missing'
# ./app/controllers/invoices_controller.rb:7:in `index'
# /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
actionpack-3.2.12/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
# /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
actionpack-3.2.12/lib/abstract_controller/base.rb:167:in `process_action'
# /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
actionpack-3.2.12/lib/action_controller/metal/rendering.rb:10:in `process_action'
# /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
actionpack-3.2.12/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
# /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
activesupport-3.2.12/lib/active_support/callbacks.rb:447:in
`_run__3859364058582123788__process_action__4176185741589430016__callbacks'
# /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
activesupport-3.2.12/lib/active_support/callbacks.rb:405:in `__run_callback'
# /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
activesupport-3.2.12/lib/active_support/callbacks.rb:385:in
`_run_process_action_callbacks'
# /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
activesupport-3.2.12/lib/active_support/callbacks.rb:81:in `run_callbacks'
# /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
actionpack-3.2.12/lib/abstract_controller/callbacks.rb:17:in `process_action'
# /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
actionpack-3.2.12/lib/action_controller/metal/rescue.rb:29:in `process_action'
# /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
actionpack-3.2.12/lib/action_controller/metal/instrumentation.rb:30:in `block in
process_action'
Friday, August 9, 13
1) InvoicesController as an admin GET index should paginate all unpaid invoices as
@unpaid_invoices
Failure/Error: get :index
NoMethodError:
undefined method `unpayed' for #<Class:0x007fd8cfe9ee18>
# /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
activerecord-3.2.12/lib/active_record/dynamic_matchers.rb:55:in `method_missing'
# ./app/controllers/invoices_controller.rb:7:in `index'
# /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
actionpack-3.2.12/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
# /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
actionpack-3.2.12/lib/abstract_controller/base.rb:167:in `process_action'
# /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
actionpack-3.2.12/lib/action_controller/metal/rendering.rb:10:in `process_action'
# /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
actionpack-3.2.12/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
# /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
activesupport-3.2.12/lib/active_support/callbacks.rb:447:in
`_run__3859364058582123788__process_action__4176185741589430016__callbacks'
# /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
activesupport-3.2.12/lib/active_support/callbacks.rb:405:in `__run_callback'
# /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
activesupport-3.2.12/lib/active_support/callbacks.rb:385:in
`_run_process_action_callbacks'
# /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
activesupport-3.2.12/lib/active_support/callbacks.rb:81:in `run_callbacks'
# /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
actionpack-3.2.12/lib/abstract_controller/callbacks.rb:17:in `process_action'
# /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
actionpack-3.2.12/lib/action_controller/metal/rescue.rb:29:in `process_action'
# /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
actionpack-3.2.12/lib/action_controller/metal/instrumentation.rb:30:in `block in
process_action'
Friday, August 9, 13
BUT WHAT ABOUT
WHEN...
Friday, August 9, 13
/Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/active_support/
core_ext/hash/keys.rb:25:in `symbolize_keys': You blew it, dumbass (RuntimeError)
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/
active_record/connection_adapters/abstract/connection_specification.rb:45:in `resolve_hash_connection'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/
active_record/connection_adapters/abstract/connection_specification.rb:41:in `resolve_string_connection'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/
active_record/connection_adapters/abstract/connection_specification.rb:25:in `spec'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/
active_record/connection_adapters/abstract/connection_specification.rb:130:in `establish_connection'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/
active_record/railtie.rb:82:in `block (2 levels) in <class:Railtie>'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/
active_support/lazy_load_hooks.rb:36:in `instance_eval'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/
active_support/lazy_load_hooks.rb:36:in `execute_hook'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/
active_support/lazy_load_hooks.rb:26:in `block in on_load'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/
active_support/lazy_load_hooks.rb:25:in `each'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/
active_support/lazy_load_hooks.rb:25:in `on_load'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/
active_record/railtie.rb:74:in `block in <class:Railtie>'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/
initializable.rb:30:in `instance_exec'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/
initializable.rb:30:in `run'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/
initializable.rb:55:in `block in run_initializers'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/
initializable.rb:54:in `each'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/
initializable.rb:54:in `run_initializers'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/
application.rb:136:in `initialize!'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/
railtie/configurable.rb:30:in `method_missing'
from /Volumes/Valinor/Users/evan/Development/Ruby/apps/tracks/config/environment.rb:5:in `<top
(required)>'
from /Volumes/Valinor/Users/evan/Development/Ruby/apps/tracks/spec/spec_helper.rb:3:in `require'
from /Volumes/Valinor/Users/evan/Development/Ruby/apps/tracks/spec/spec_helper.rb:3:in `<top
Friday, August 9, 13
/Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/active_support/
core_ext/hash/keys.rb:25:in `symbolize_keys': You blew it, dumbass (RuntimeError)
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/
active_record/connection_adapters/abstract/connection_specification.rb:45:in `resolve_hash_connection'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/
active_record/connection_adapters/abstract/connection_specification.rb:41:in `resolve_string_connection'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/
active_record/connection_adapters/abstract/connection_specification.rb:25:in `spec'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/
active_record/connection_adapters/abstract/connection_specification.rb:130:in `establish_connection'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/
active_record/railtie.rb:82:in `block (2 levels) in <class:Railtie>'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/
active_support/lazy_load_hooks.rb:36:in `instance_eval'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/
active_support/lazy_load_hooks.rb:36:in `execute_hook'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/
active_support/lazy_load_hooks.rb:26:in `block in on_load'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/
active_support/lazy_load_hooks.rb:25:in `each'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/
active_support/lazy_load_hooks.rb:25:in `on_load'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/
active_record/railtie.rb:74:in `block in <class:Railtie>'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/
initializable.rb:30:in `instance_exec'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/
initializable.rb:30:in `run'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/
initializable.rb:55:in `block in run_initializers'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/
initializable.rb:54:in `each'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/
initializable.rb:54:in `run_initializers'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/
application.rb:136:in `initialize!'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/
railtie/configurable.rb:30:in `method_missing'
from /Volumes/Valinor/Users/evan/Development/Ruby/apps/tracks/config/environment.rb:5:in `<top
(required)>'
from /Volumes/Valinor/Users/evan/Development/Ruby/apps/tracks/spec/spec_helper.rb:3:in `require'
from /Volumes/Valinor/Users/evan/Development/Ruby/apps/tracks/spec/spec_helper.rb:3:in `<top
Friday, August 9, 13
/Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/active_support/
core_ext/hash/keys.rb:25:in `symbolize_keys': You blew it, dumbass (RuntimeError)
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/
active_record/connection_adapters/abstract/connection_specification.rb:45:in `resolve_hash_connection'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/
active_record/connection_adapters/abstract/connection_specification.rb:41:in `resolve_string_connection'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/
active_record/connection_adapters/abstract/connection_specification.rb:25:in `spec'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/
active_record/connection_adapters/abstract/connection_specification.rb:130:in `establish_connection'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/
active_record/railtie.rb:82:in `block (2 levels) in <class:Railtie>'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/
active_support/lazy_load_hooks.rb:36:in `instance_eval'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/
active_support/lazy_load_hooks.rb:36:in `execute_hook'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/
active_support/lazy_load_hooks.rb:26:in `block in on_load'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/
active_support/lazy_load_hooks.rb:25:in `each'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/
active_support/lazy_load_hooks.rb:25:in `on_load'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/
active_record/railtie.rb:74:in `block in <class:Railtie>'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/
initializable.rb:30:in `instance_exec'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/
initializable.rb:30:in `run'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/
initializable.rb:55:in `block in run_initializers'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/
initializable.rb:54:in `each'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/
initializable.rb:54:in `run_initializers'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/
application.rb:136:in `initialize!'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/
railtie/configurable.rb:30:in `method_missing'
from /Volumes/Valinor/Users/evan/Development/Ruby/apps/tracks/config/environment.rb:5:in `<top
(required)>'
from /Volumes/Valinor/Users/evan/Development/Ruby/apps/tracks/spec/spec_helper.rb:3:in `require'
from /Volumes/Valinor/Users/evan/Development/Ruby/apps/tracks/spec/spec_helper.rb:3:in `<top
Friday, August 9, 13
/Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/active_support/
core_ext/hash/keys.rb:25:in `symbolize_keys': You blew it, dumbass (RuntimeError)
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/
active_record/connection_adapters/abstract/connection_specification.rb:45:in `resolve_hash_connection'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/
active_record/connection_adapters/abstract/connection_specification.rb:41:in `resolve_string_connection'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/
active_record/connection_adapters/abstract/connection_specification.rb:25:in `spec'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/
active_record/connection_adapters/abstract/connection_specification.rb:130:in `establish_connection'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/
active_record/railtie.rb:82:in `block (2 levels) in <class:Railtie>'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/
active_support/lazy_load_hooks.rb:36:in `instance_eval'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/
active_support/lazy_load_hooks.rb:36:in `execute_hook'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/
active_support/lazy_load_hooks.rb:26:in `block in on_load'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/
active_support/lazy_load_hooks.rb:25:in `each'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/
active_support/lazy_load_hooks.rb:25:in `on_load'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/
active_record/railtie.rb:74:in `block in <class:Railtie>'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/
initializable.rb:30:in `instance_exec'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/
initializable.rb:30:in `run'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/
initializable.rb:55:in `block in run_initializers'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/
initializable.rb:54:in `each'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/
initializable.rb:54:in `run_initializers'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/
application.rb:136:in `initialize!'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/
railtie/configurable.rb:30:in `method_missing'
from /Volumes/Valinor/Users/evan/Development/Ruby/apps/tracks/config/environment.rb:5:in `<top
(required)>'
from /Volumes/Valinor/Users/evan/Development/Ruby/apps/tracks/spec/spec_helper.rb:3:in `require'
from /Volumes/Valinor/Users/evan/Development/Ruby/apps/tracks/spec/spec_helper.rb:3:in `<top
Friday, August 9, 13
IT’S PROBABLY
SOMETHING YOU DID.
Friday, August 9, 13
IT’S PROBABLY
SOMETHING YOU DID.
(but the error’s not in
your code)
Friday, August 9, 13
RAILS’ CODE IS
HARD TO UNDERSTAND
Friday, August 9, 13
RAILS’ CODE IS
HARD TO UNDERSTAND
But that doesn’t matter!
Dive in anyway.
Friday, August 9, 13
RUBY IS A RUN-TIME
LANGUAGE
Friday, August 9, 13
RUBY IS A RUN-TIME
LANGUAGE
•This makes it hard to find stuff!
Friday, August 9, 13
RUBY IS A RUN-TIME
LANGUAGE
•This makes it hard to find stuff!
•Your IDE isn’t much help
Friday, August 9, 13
RUBY IS A RUN-TIME
LANGUAGE
•This makes it hard to find stuff!
•Your IDE isn’t much help
•So find stuff AT RUN TIME
Friday, August 9, 13
JUST OPEN THAT FILE
Friday, August 9, 13
JUST OPEN THAT FILE
Don’t be intimidated ... it’s all just Ruby
Friday, August 9, 13
JUST OPEN THAT FILE
~/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/active_support/
core_ext/hash/keys.rb:25:in `symbolize_keys': You blew it, dumbass (RuntimeError)
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
activerecord-3.2.12/lib/active_record/connection_adapters/abstract/
connection_specification.rb:45:in `resolve_hash_connection'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
activerecord-3.2.12/lib/active_record/connection_adapters/abstract/
connection_specification.rb:41:in `resolve_string_connection'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
Don’t be intimidated ... it’s all just Ruby
Friday, August 9, 13
JUST OPEN THAT FILE
~/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/active_support/
core_ext/hash/keys.rb:25:in `symbolize_keys': You blew it, dumbass (RuntimeError)
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
activerecord-3.2.12/lib/active_record/connection_adapters/abstract/
connection_specification.rb:45:in `resolve_hash_connection'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
activerecord-3.2.12/lib/active_record/connection_adapters/abstract/
connection_specification.rb:41:in `resolve_string_connection'
from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
$ vim ~evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12
Don’t be intimidated ... it’s all just Ruby
Friday, August 9, 13
USE GEM...
Friday, August 9, 13
USE GEM...
$ gem env
Friday, August 9, 13
USE GEM...
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.25
- RUBY VERSION: 1.9.3 (2012-11-10 patchlevel 327) [x86_64-darwin11.4.2]
- INSTALLATION DIRECTORY: /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fas
- RUBY EXECUTABLE: /Volumes/Valinor/Users/evan/.rvm/rubies/ruby-1.9.3-p327-fast/bin/
- EXECUTABLE DIRECTORY: /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-
fast@tracks/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-11
- GEM PATHS:
- /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks
- /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@global
- GEM CONFIGURATION:
$ gem env
Friday, August 9, 13
USE GEM...
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.25
- RUBY VERSION: 1.9.3 (2012-11-10 patchlevel 327) [x86_64-darwin11.4.2]
- INSTALLATION DIRECTORY: /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fas
- RUBY EXECUTABLE: /Volumes/Valinor/Users/evan/.rvm/rubies/ruby-1.9.3-p327-fast/bin/
- EXECUTABLE DIRECTORY: /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-
fast@tracks/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-11
- GEM PATHS:
- /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks
- /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@global
- GEM CONFIGURATION:
$ gem env
Friday, August 9, 13
USE GEM...
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.25
- RUBY VERSION: 1.9.3 (2012-11-10 patchlevel 327) [x86_64-darwin11.4.2]
- INSTALLATION DIRECTORY: /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fas
- RUBY EXECUTABLE: /Volumes/Valinor/Users/evan/.rvm/rubies/ruby-1.9.3-p327-fast/bin/
- EXECUTABLE DIRECTORY: /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-
fast@tracks/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-11
- GEM PATHS:
- /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks
- /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@global
- GEM CONFIGURATION:
$ gem env
$ cd /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks
Friday, August 9, 13
ASK RUBY YOUR
QUESTIONS!
Friday, August 9, 13
WHAT’S THIS VALUE?
#activesupport-3.2.12/lib/active_support/core_ext/hash
class Hash
# Return a new hash with all keys converted to symbols, as
# long as they respond to +to_sym+.
#
# { 'name' => 'Rob', 'years' => '28' }.symbolize_keys
# #=> { :name => "Rob", :years => "28" }
def symbolize_keys
dup.symbolize_keys!
end
alias_method :to_options, :symbolize_keys
alias_method :to_options!, :symbolize_keys!
# Validate all keys in a hash match *valid keys, raising
ArgumentError on a mismatch.
# Note that keys are NOT treated indifferently, meaning if you
use strings for keys but assert symbols
Friday, August 9, 13
WHAT’S THIS VALUE?
#activesupport-3.2.12/lib/active_support/core_ext/hash
class Hash
# Return a new hash with all keys converted to symbols, as
# long as they respond to +to_sym+.
#
# { 'name' => 'Rob', 'years' => '28' }.symbolize_keys
# #=> { :name => "Rob", :years => "28" }
def symbolize_keys
dup.symbolize_keys!
end
alias_method :to_options, :symbolize_keys
alias_method :to_options!, :symbolize_keys!
# Validate all keys in a hash match *valid keys, raising
ArgumentError on a mismatch.
# Note that keys are NOT treated indifferently, meaning if you
use strings for keys but assert symbols
Friday, August 9, 13
WHAT’S THIS VALUE?
#activesupport-3.2.12/lib/active_support/core_ext/hash
class Hash
# Return a new hash with all keys converted to symbols, as
# long as they respond to +to_sym+.
#
# { 'name' => 'Rob', 'years' => '28' }.symbolize_keys
# #=> { :name => "Rob", :years => "28" }
def symbolize_keys
p self
dup.symbolize_keys!
end
alias_method :to_options, :symbolize_keys
alias_method :to_options!, :symbolize_keys!
# Validate all keys in a hash match *valid keys, raising
ArgumentError on a mismatch.
# Note that keys are NOT treated indifferently, meaning if you
Friday, August 9, 13
TOO MUCH OUTPUT!
.{:client_id=>"24"}
{"controller"=>"invoices", "action"=>"new"}
.{:client_id=>"27"}
{"controller"=>"invoices", "action"=>"new"}
.{:client_id=>"30"}
{"controller"=>"invoices", "action"=>"new"}
.{:client_id=>"33"}
{"controller"=>"invoices", "action"=>"new"}
.{:client_id=>"37"}
{"controller"=>"invoices", "action"=>"new"}
.{:id=>"19"}
{"id"=>"19", "controller"=>"invoices", "action"=>"edit"}
.{:id=>"20"}
{"id"=>"20", "controller"=>"invoices", "action"=>"edit"}
{:controller=>"devise/
sessions", :action=>"new", :use_route=>"login", :only_path=>true}
.
{:invoice=>{:due_on=>"2013-05-14", :client_id=>"42",
:notes=>"value for notes"}}
Friday, August 9, 13
OUTPUT AND STOP
#activesupport-3.2.12/lib/active_support/core_ext/hash
class Hash
# Return a new hash with all keys converted to symbols, as
# long as they respond to +to_sym+.
#
# { 'name' => 'Rob', 'years' => '28' }.symbolize_keys
# #=> { :name => "Rob", :years => "28" }
def symbolize_keys
raise self # stop running!
dup.symbolize_keys!
end
alias_method :to_options, :symbolize_keys
alias_method :to_options!, :symbolize_keys!
# Validate all keys in a hash match *valid keys, raising
ArgumentError on a mismatch.
# Note that keys are NOT treated indifferently, meaning if you
Friday, August 9, 13
ADD A CONDITION
#activesupport-3.2.12/lib/active_support/core_ext/hash
class Hash
# Return a new hash with all keys converted to symbols, as
# long as they respond to +to_sym+.
#
# { 'name' => 'Rob', 'years' => '28' }.symbolize_keys
# #=> { :name => "Rob", :years => "28" }
def symbolize_keys
raise self if <some condition>
dup.symbolize_keys!
end
alias_method :to_options, :symbolize_keys
alias_method :to_options!, :symbolize_keys!
# Validate all keys in a hash match *valid keys, raising
ArgumentError on a mismatch.
# Note that keys are NOT treated indifferently, meaning if you
Friday, August 9, 13
KEEP TRACK OF LOCATION
#activesupport-3.2.12/lib/active_support/core_ext/hash
class Hash
# Return a new hash with all keys converted to symbols, as
# long as they respond to +to_sym+.
#
# { 'name' => 'Rob', 'years' => '28' }.symbolize_keys
# #=> { :name => "Rob", :years => "28" }
def symbolize_keys
p __FILE__, __LINE__
dup.symbolize_keys!
end
alias_method :to_options, :symbolize_keys
alias_method :to_options!, :symbolize_keys!
# Validate all keys in a hash match *valid keys, raising
ArgumentError on a mismatch.
# Note that keys are NOT treated indifferently, meaning if you
Friday, August 9, 13
LABEL WITH LOCATION
#activesupport-3.2.12/lib/active_support/core_ext/hash
class Hash
# Return a new hash with all keys converted to symbols, as
# long as they respond to +to_sym+.
#
# { 'name' => 'Rob', 'years' => '28' }.symbolize_keys
# #=> { :name => "Rob", :years => "28" }
def symbolize_keys
p “#{__FILE__}:#{__LINE__}” => self
dup.symbolize_keys!
end
alias_method :to_options, :symbolize_keys
alias_method :to_options!, :symbolize_keys!
# Validate all keys in a hash match *valid keys, raising
ArgumentError on a mismatch.
# Note that keys are NOT treated indifferently, meaning if you
Friday, August 9, 13
TAG WITH A NAME
#activesupport-3.2.12/lib/active_support/core_ext/hash
class Hash
# Return a new hash with all keys converted to symbols, as
# long as they respond to +to_sym+.
#
# { 'name' => 'Rob', 'years' => '28' }.symbolize_keys
# #=> { :name => "Rob", :years => "28" }
def symbolize_keys
p :broken_hash => self
dup.symbolize_keys!
end
alias_method :to_options, :symbolize_keys
alias_method :to_options!, :symbolize_keys!
# Validate all keys in a hash match *valid keys, raising
ArgumentError on a mismatch.
# Note that keys are NOT treated indifferently, meaning if you
Friday, August 9, 13
CLEAN IT UP
#activesupport-3.2.12/lib/active_support/core_ext/hash
class Hash
# Return a new hash with all keys converted to symbols, as
# long as they respond to +to_sym+.
#
# { 'name' => 'Rob', 'years' => '28' }.symbolize_keys
# #=> { :name => "Rob", :years => "28" }
def symbolize_keys
require ‘pp’
pp self
dup.symbolize_keys!
end
alias_method :to_options, :symbolize_keys
alias_method :to_options!, :symbolize_keys!
# Validate all keys in a hash match *valid keys, raising
ArgumentError on a mismatch.
Friday, August 9, 13
OTHER USEFUL
QUESTIONS
Friday, August 9, 13
HOW DID I GET HERE?
Friday, August 9, 13
HOW DID I GET HERE?
#activesupport-3.2.12/lib/active_support/core_ext/hash
class Hash
# Return a new hash with all keys converted to symbols, as
# long as they respond to +to_sym+.
#
# { 'name' => 'Rob', 'years' => '28' }.symbolize_keys
# #=> { :name => "Rob", :years => "28" }
def symbolize_keys
require ‘pp’
pp caller[0..10]
dup.symbolize_keys!
end
alias_method :to_options, :symbolize_keys
alias_method :to_options!, :symbolize_keys!
# Validate all keys in a hash match *valid keys, raising
ArgumentError on a mismatch.
Friday, August 9, 13
“DOES THIS FILE LOAD?”
module SomePossiblyIncludedMonkeyPatch
def change_important_class_behavior
# ...
# ...
end
def obscure_some_key_method
# ...
# ...
end
end
Friday, August 9, 13
“DOES THIS FILE LOAD?”
raise “Yes, somebody required me”
module SomePossiblyIncludedMonkeyPatch
def change_important_class_behavior
# ...
# ...
end
def obscure_some_key_method
# ...
# ...
end
end
Friday, August 9, 13
“WHY DIDN’T THIS FILE LOAD?”
Friday, August 9, 13
“WHY DIDN’T THIS FILE LOAD?”
require ‘some_library/some_junk’
module MyNiftyBehavior
def stuff
Friday, August 9, 13
“WHY DIDN’T THIS FILE LOAD?”
require ‘some_library/some_junk’
module MyNiftyBehavior
def stuff
$ rspec spec/
No such file to load -- some_library/some_junk (LoadError)
Friday, August 9, 13
“WHY DIDN’T THIS FILE LOAD?”
require ‘some_library/some_junk’
module MyNiftyBehavior
def stuff
$ rspec spec/
No such file to load -- some_library/some_junk (LoadError)
... pretty print the search path
Friday, August 9, 13
“WHY DIDN’T THIS FILE LOAD?”
require ‘some_library/some_junk’
module MyNiftyBehavior
def stuff
$ rspec spec/
No such file to load -- some_library/some_junk (LoadError)
... pretty print the search path
require ‘pp’
pp $:
require ‘some_library/some_junk’
module MyNiftyBehavior
def stuff
Friday, August 9, 13
“WHO REQUIRED ME?”
module SomePossiblyIncludedMonkeyPatch
def change_important_class_behavior
# ...
# ...
end
def obscure_some_key_method
# ...
# ...
end
end
Friday, August 9, 13
“WHO REQUIRED ME?”
p “Required By” => caller[0]
module SomePossiblyIncludedMonkeyPatch
def change_important_class_behavior
# ...
# ...
end
def obscure_some_key_method
# ...
# ...
end
end
Friday, August 9, 13
WHAT IF YOU DON’T
KNOW THE RIGHT
QUESTION YET?
Friday, August 9, 13
USE DEBUGGER!
Friday, August 9, 13
YOUR GEMFILE
source 'http://rubygems.org'
gem 'rails', '3.2.12'
gem 'rack', '~> 1.4.0'
gem 'rake'
gem "will_paginate"
gem 'devise'
group :development, :test do
gem 'rspec'
gem 'rspec-rails'
gem 'factory_girl_rails'
gem 'debugger'
end
Friday, August 9, 13
IN THE CODE
class Hash
# Return a new hash with all keys converted to symbols, as
# long as they respond to +to_sym+.
#
# { 'name' => 'Rob', 'years' => '28' }.symbolize_keys
# #=> { :name => "Rob", :years => "28" }
def symbolize_keys
debugger
dup.symbolize_keys!
end
alias_method :to_options, :symbolize_keys
alias_method :to_options!, :symbolize_keys!
# Validate all keys in a hash match *valid keys, raising
ArgumentError on a mismatch.
# Note that keys are NOT treated indifferently, meaning if you
use strings for keys but assert symbols
Friday, August 9, 13
RUNNING IT
Friday, August 9, 13
RUNNING IT
$ rails server -u
Development Server:
Friday, August 9, 13
RUNNING IT
$ rails server -u
Development Server:
$ rspec -d spec/
rSpec:
Friday, August 9, 13
RUNNING IT
Arbitrary Ruby script:
$ rdebug <command>
$ rdebug rake db:seed
Friday, August 9, 13
WHO ARE YOU?
#activesupport-3.2.12/lib/active_support/core_ext/hash
class Hash
def symbolize_keys
debugger
dup.symbolize_keys!
end
Friday, August 9, 13
WHO ARE YOU?
(rdb:1) eval dup.class
#activesupport-3.2.12/lib/active_support/core_ext/hash
class Hash
def symbolize_keys
debugger
dup.symbolize_keys!
end
Friday, August 9, 13
WHO ARE YOU?
(rdb:1) eval dup.class
Hash
#activesupport-3.2.12/lib/active_support/core_ext/hash
class Hash
def symbolize_keys
debugger
dup.symbolize_keys!
end
Friday, August 9, 13
WHO AM I?
(rdb:1) eval self.class
Friday, August 9, 13
WHO AM I?
(rdb:1) eval self.class
Hash
Friday, August 9, 13
WHO CAN I CALL?
(rdb:1) eval self.methods
Friday, August 9, 13
WHO CAN I CALL?
(rdb:1) eval self.methods
[:specify, :class_variable_defined?, :public_class_method,
:methods, :use_instantiated_fixtures=, :filtered_examples,
:before_all_ivars, :should, :const_defined?, :untrust,
:local_constant_names, :should_not, :capture, :module_eval,
:instance_methods, :clone, :load_dependency, :to_json, :run_hook,
:all_apply?, :share_examples_for, :include?, :redefine_method,
:to_yaml, :respond_to?, :examples, :fail_fast?, :unloadable,
:it_should_behave_like, :<=>, :instance_variable_defined?,
:register, :acts_like?, :psych_yaml_as, :debug_method,
:fixture_class_names, :let!, :render_views, :focus,
:private_class_method, :delegate, :public_constant,
:singleton_methods, :pretty_print_instance_variables,
:attr_internal_writer, :use_instantiated_fixtures?, :matcher,
:try, :tests, :as_json, :gem, :untrusted?, :controller_class,
:pending, :parent, :silence, :class_eval,
Friday, August 9, 13
WHO CAN I CALL?
(rdb:1) eval self.methods.sort
Friday, August 9, 13
WHO CAN I CALL?
(rdb:1) eval self.methods.sort
[:!, :!=, :!~, :<=>, :==, :===, :=~, :[], :
[]=, :__id__, :__send__, :`, :acts_like?, :all?, :any?, :as_json,
:assert_valid_keys, :assoc, :binding_n, :blank?, :breakpoint,
:capture, :chunk, :class, :class_eval, :clear, :clone, :collect,
:collect_concat, :compare_by_identity, :compare_by_identity?,
:count, :cycle, :dbg_print, :dbg_puts, :debugger, :deep_dup,
:deep_merge, :deep_merge!, :deep_symbolize_keys, :default,
:default=, :default_proc, :default_proc=,
:define_singleton_method, :delete, :delete_if, :detect, :diff,
:display, :drop, :drop_while, :dup, :duplicable?, :each,
:each_cons, :each_entry, :each_key, :each_pair, :each_slice,
:each_value, :each_with_index, :each_with_object, :empty?,
:enable_warnings, :encode_json, :entries, :enum_for, :eql?,
:equal?, :except, :except!, :exclude?, :extend, :extract!,
:extractable_options?, :fetch, :find, :find_all, :find_index,
Friday, August 9, 13
WHO CAN I CALL?
(rdb:1) eval self.methods.grep(/merge/)
Friday, August 9, 13
WHO CAN I CALL?
(rdb:1) eval self.methods.grep(/merge/)
[:deep_merge!, :reverse_merge!, :merge!, :merge, :deep_merge,
:reverse_merge, :merge_resultset]
Friday, August 9, 13
DEBUGGER HAS ‘PP’
BY DEFAULT
Friday, August 9, 13
WHO DO YOU INCLUDE?
(rdb:1) pp dup.class.included_modules
Friday, August 9, 13
WHO DO YOU INCLUDE?
(rdb:1) pp dup.class.included_modules
[SimpleCov::HashMergeHelper,
JSON::Ext::Generator::GeneratorMethods::Hash,
Enumerable,
RSpec::Steps::ClassMethods,
JSON::Ext::Generator::GeneratorMethods::Object,
ActiveSupport::Dependencies::Loadable,
PP::ObjectMixin,
Kernel]
Friday, August 9, 13
FINDING
METHODS
Friday, August 9, 13
AT THE COMMAND-LINE
-H (show filename)
-n (show line number)
-r (recurse directories)
-i (ignore case -- use carefully)
$ grep -Hnir <pattern> <path>
Friday, August 9, 13
USEFUL PATTERNS
Friday, August 9, 13
USEFUL PATTERNS
$ grep -Hnr “def *my_method” *
Method definitions:
Friday, August 9, 13
USEFUL PATTERNS
$ grep -Hnr “def *my_method” *
Method definitions:
$ grep <stuff> | grep -v “ *#”
Ignore comments:
Friday, August 9, 13
ACK > GREP
$ ack <pattern>
Friday, August 9, 13
ACK > GREP
Friday, August 9, 13
ACK > GREP
•Looks only in programming files (ignores
logs!)
Friday, August 9, 13
ACK > GREP
•Looks only in programming files (ignores
logs!)
•brew install ack
Friday, August 9, 13
ACK > GREP
•Looks only in programming files (ignores
logs!)
•brew install ack
•Configurable via .ackrc
Friday, August 9, 13
ACK > GREP
•Looks only in programming files (ignores
logs!)
•brew install ack
•Configurable via .ackrc
•https://gist.github.com/IdahoEv/5580770
Friday, August 9, 13
BUT THEN THIS...
Friday, August 9, 13
BUT THEN THIS...
$ ack “def *my_method”
Friday, August 9, 13
BUT THEN THIS...
$ ack “def *my_method”
$
Friday, August 9, 13
BUT THEN THIS...
$ ack “def *my_method”
$
... it doesn’t exist
Friday, August 9, 13
BUT THEN THIS...
$ ack “def *my_method”
$
... it doesn’t exist
Friday, August 9, 13
BECAUSE RUBY LETS
YOU DO THIS...
Friday, August 9, 13
module RSpec
module Core
class ExampleGroup
class << self
delegate_to_metadata :described_class, :file_path
alias_method :display_name, :description
alias_method :describes, :described_class
# @private
# @macro [attach] define_example_method
# @param [String] name
# @param [Hash] extra_options
# @param [Block] implementation
def self.define_example_method(name, extra_options={})
module_eval(<<-END_RUBY, __FILE__, __LINE__)
def #{name}(desc=nil, *args, &block)
options = build_metadata_hash_from(args)
options.update(:pending => RSpec::Core::Pending::) unless block
options.update(#{extra_options.inspect})
examples << RSpec::Core::Example.new(self, desc, options, block)
examples.last
end
END_RUBY
end
define_example_method :example
define_example_method :it
define_example_method :specify
define_example_method :focus, :focused => true, :focus => true
Friday, August 9, 13
module RSpec
module Core
class ExampleGroup
class << self
delegate_to_metadata :described_class, :file_path
alias_method :display_name, :description
alias_method :describes, :described_class
# @private
# @macro [attach] define_example_method
# @param [String] name
# @param [Hash] extra_options
# @param [Block] implementation
def self.define_example_method(name, extra_options={})
module_eval(<<-END_RUBY, __FILE__, __LINE__)
def #{name}(desc=nil, *args, &block)
options = build_metadata_hash_from(args)
options.update(:pending => RSpec::Core::Pending::) unless block
options.update(#{extra_options.inspect})
examples << RSpec::Core::Example.new(self, desc, options, block)
examples.last
end
END_RUBY
end
define_example_method :example
define_example_method :it
define_example_method :specify
define_example_method :focus, :focused => true, :focus => true
Friday, August 9, 13
ADVANCED
INTROSPECTION
Friday, August 9, 13
WHO DO YOU INCLUDE?
#activesupport-3.2.12/lib/active_support/core_ext/hash
class Hash
# ... snip ...
def symbolize_keys
debugger
dup.symbolize_keys!
end
# ... snip ...
end
Friday, August 9, 13
WHO DO YOU INCLUDE?
(rdb:1) pp self.class.included_modules
[SimpleCov::HashMergeHelper,
JSON::Ext::Generator::GeneratorMethods::Hash,
Enumerable,
RSpec::Steps::ClassMethods,
JSON::Ext::Generator::GeneratorMethods::Object,
ActiveSupport::Dependencies::Loadable,
PP::ObjectMixin,
Kernel]
Friday, August 9, 13
WHO DEFINED THAT METHOD?
(rdb:1) eval self.method(:merge_resultset).owner
Friday, August 9, 13
WHO DEFINED THAT METHOD?
(rdb:1) eval self.method(:merge_resultset).owner
SimpleCov::HashMergeHelper
Friday, August 9, 13
BUT DEFINED WHERE?
(rdb:1) pp self.method(:merge_resultset).source_location
Friday, August 9, 13
BUT DEFINED WHERE?
(rdb:1) pp self.method(:merge_resultset).source_location
["~/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/
simplecov-0.5.4/lib/simplecov/merge_helpers.rb", 25]
Friday, August 9, 13
EVEN WORKS ON
DYNAMIC METHODS!
Friday, August 9, 13
EVEN WORKS ON
DYNAMIC METHODS!
#/spec/controllers/invoices_controller_spec.rb
require 'spec_helper'
describe InvoicesController do
debugger
describe "as an admin" do
before(:each) do
authenticate(:admin)
Friday, August 9, 13
EVEN WORKS ON
DYNAMIC METHODS!
(rdb:1) eval method(:example).source_location
Friday, August 9, 13
EVEN WORKS ON
DYNAMIC METHODS!
(rdb:1) eval method(:example).source_location
["/Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-
fast@tracks/gems/rspec-core-2.13.1/lib/rspec/core/
example_group.rb", 61]
Friday, August 9, 13
WHERE TO LOOK NEXT
•Pry (https://github.com/pry/pry)
•API Docs: http://www.ruby-doc.org/core-2.0
• Kernel
• Module
• Method
Friday, August 9, 13
Thanks!
Evan Dorn
Founder, Logical Reality Design
http://lrdesign.com
evan@lrdesign.com
@idahoev
Text
Friday, August 9, 13

More Related Content

What's hot

Writing Software not Code with Cucumber
Writing Software not Code with CucumberWriting Software not Code with Cucumber
Writing Software not Code with CucumberBen Mabey
 
Magento - a Zend Framework Application
Magento - a Zend Framework ApplicationMagento - a Zend Framework Application
Magento - a Zend Framework ApplicationZendCon
 
Ajax Applications with RichFaces and JSF 2
Ajax Applications with RichFaces and JSF 2Ajax Applications with RichFaces and JSF 2
Ajax Applications with RichFaces and JSF 2Max Katz
 
Application Diagnosis with Zend Server Tracing
Application Diagnosis with Zend Server TracingApplication Diagnosis with Zend Server Tracing
Application Diagnosis with Zend Server TracingZendCon
 
Story Driven Development With Cucumber
Story Driven Development With CucumberStory Driven Development With Cucumber
Story Driven Development With CucumberSean Cribbs
 
End-to-end web-testing in ruby ecosystem
End-to-end web-testing in ruby ecosystemEnd-to-end web-testing in ruby ecosystem
End-to-end web-testing in ruby ecosystemAlex Mikitenko
 
A Debugging Adventure: Journey through Ember.js Glue
A Debugging Adventure: Journey through Ember.js GlueA Debugging Adventure: Journey through Ember.js Glue
A Debugging Adventure: Journey through Ember.js GlueMike North
 
"Managing API Complexity". Matthew Flaming, Temboo
"Managing API Complexity". Matthew Flaming, Temboo"Managing API Complexity". Matthew Flaming, Temboo
"Managing API Complexity". Matthew Flaming, TembooYandex
 
Outside-in Development with Cucumber and Rspec
Outside-in Development with Cucumber and RspecOutside-in Development with Cucumber and Rspec
Outside-in Development with Cucumber and RspecJoseph Wilk
 
How do speed up web pages? CSS & HTML Tricks
How do speed up web pages? CSS & HTML TricksHow do speed up web pages? CSS & HTML Tricks
How do speed up web pages? CSS & HTML TricksCompare Infobase Limited
 
Optaros Surf Code Camp Walkthrough 2
Optaros Surf Code Camp Walkthrough 2Optaros Surf Code Camp Walkthrough 2
Optaros Surf Code Camp Walkthrough 2Jeff Potts
 
Streamlining Your Applications with Web Frameworks
Streamlining Your Applications with Web FrameworksStreamlining Your Applications with Web Frameworks
Streamlining Your Applications with Web Frameworksguestf7bc30
 
Optimising Your Front End Workflow With Symfony, Twig, Bower and Gulp
Optimising Your Front End Workflow With Symfony, Twig, Bower and GulpOptimising Your Front End Workflow With Symfony, Twig, Bower and Gulp
Optimising Your Front End Workflow With Symfony, Twig, Bower and GulpMatthew Davis
 
Master the New Core of Drupal 8 Now: with Symfony and Silex
Master the New Core of Drupal 8 Now: with Symfony and SilexMaster the New Core of Drupal 8 Now: with Symfony and Silex
Master the New Core of Drupal 8 Now: with Symfony and SilexRyan Weaver
 
Enemy of the state
Enemy of the stateEnemy of the state
Enemy of the stateMike North
 

What's hot (20)

Writing Software not Code with Cucumber
Writing Software not Code with CucumberWriting Software not Code with Cucumber
Writing Software not Code with Cucumber
 
Magento - a Zend Framework Application
Magento - a Zend Framework ApplicationMagento - a Zend Framework Application
Magento - a Zend Framework Application
 
Ajax Applications with RichFaces and JSF 2
Ajax Applications with RichFaces and JSF 2Ajax Applications with RichFaces and JSF 2
Ajax Applications with RichFaces and JSF 2
 
Application Diagnosis with Zend Server Tracing
Application Diagnosis with Zend Server TracingApplication Diagnosis with Zend Server Tracing
Application Diagnosis with Zend Server Tracing
 
Progressive Enhancement
Progressive EnhancementProgressive Enhancement
Progressive Enhancement
 
สปริงเฟรมเวิร์ค4.1
สปริงเฟรมเวิร์ค4.1สปริงเฟรมเวิร์ค4.1
สปริงเฟรมเวิร์ค4.1
 
Story Driven Development With Cucumber
Story Driven Development With CucumberStory Driven Development With Cucumber
Story Driven Development With Cucumber
 
End-to-end web-testing in ruby ecosystem
End-to-end web-testing in ruby ecosystemEnd-to-end web-testing in ruby ecosystem
End-to-end web-testing in ruby ecosystem
 
A Debugging Adventure: Journey through Ember.js Glue
A Debugging Adventure: Journey through Ember.js GlueA Debugging Adventure: Journey through Ember.js Glue
A Debugging Adventure: Journey through Ember.js Glue
 
EPiServer Web Parts
EPiServer Web PartsEPiServer Web Parts
EPiServer Web Parts
 
"Managing API Complexity". Matthew Flaming, Temboo
"Managing API Complexity". Matthew Flaming, Temboo"Managing API Complexity". Matthew Flaming, Temboo
"Managing API Complexity". Matthew Flaming, Temboo
 
Intro to Rails
Intro to RailsIntro to Rails
Intro to Rails
 
Outside-in Development with Cucumber and Rspec
Outside-in Development with Cucumber and RspecOutside-in Development with Cucumber and Rspec
Outside-in Development with Cucumber and Rspec
 
How do speed up web pages? CSS & HTML Tricks
How do speed up web pages? CSS & HTML TricksHow do speed up web pages? CSS & HTML Tricks
How do speed up web pages? CSS & HTML Tricks
 
Optaros Surf Code Camp Walkthrough 2
Optaros Surf Code Camp Walkthrough 2Optaros Surf Code Camp Walkthrough 2
Optaros Surf Code Camp Walkthrough 2
 
Streamlining Your Applications with Web Frameworks
Streamlining Your Applications with Web FrameworksStreamlining Your Applications with Web Frameworks
Streamlining Your Applications with Web Frameworks
 
Optimising Your Front End Workflow With Symfony, Twig, Bower and Gulp
Optimising Your Front End Workflow With Symfony, Twig, Bower and GulpOptimising Your Front End Workflow With Symfony, Twig, Bower and Gulp
Optimising Your Front End Workflow With Symfony, Twig, Bower and Gulp
 
Palestra VCR
Palestra VCRPalestra VCR
Palestra VCR
 
Master the New Core of Drupal 8 Now: with Symfony and Silex
Master the New Core of Drupal 8 Now: with Symfony and SilexMaster the New Core of Drupal 8 Now: with Symfony and Silex
Master the New Core of Drupal 8 Now: with Symfony and Silex
 
Enemy of the state
Enemy of the stateEnemy of the state
Enemy of the state
 

Viewers also liked

Doag2011 unternehmensanwendungen adf_mobile_next_vl_jm_final
Doag2011 unternehmensanwendungen adf_mobile_next_vl_jm_finalDoag2011 unternehmensanwendungen adf_mobile_next_vl_jm_final
Doag2011 unternehmensanwendungen adf_mobile_next_vl_jm_finalVolker Linz
 
Knockout mvvm-m6-slides
Knockout mvvm-m6-slidesKnockout mvvm-m6-slides
Knockout mvvm-m6-slidesMasterCode.vn
 
NinjaScript and Mizugumo 2011-02-05
NinjaScript and Mizugumo 2011-02-05NinjaScript and Mizugumo 2011-02-05
NinjaScript and Mizugumo 2011-02-05lrdesign
 
Modern Web Development
Modern Web DevelopmentModern Web Development
Modern Web DevelopmentRobert Nyman
 
Presentacion de la práctica de Ajax 2016
Presentacion de la práctica de Ajax 2016Presentacion de la práctica de Ajax 2016
Presentacion de la práctica de Ajax 2016Carlos Almarcha Ruiz
 

Viewers also liked (6)

Gal presentation
Gal presentationGal presentation
Gal presentation
 
Doag2011 unternehmensanwendungen adf_mobile_next_vl_jm_final
Doag2011 unternehmensanwendungen adf_mobile_next_vl_jm_finalDoag2011 unternehmensanwendungen adf_mobile_next_vl_jm_final
Doag2011 unternehmensanwendungen adf_mobile_next_vl_jm_final
 
Knockout mvvm-m6-slides
Knockout mvvm-m6-slidesKnockout mvvm-m6-slides
Knockout mvvm-m6-slides
 
NinjaScript and Mizugumo 2011-02-05
NinjaScript and Mizugumo 2011-02-05NinjaScript and Mizugumo 2011-02-05
NinjaScript and Mizugumo 2011-02-05
 
Modern Web Development
Modern Web DevelopmentModern Web Development
Modern Web Development
 
Presentacion de la práctica de Ajax 2016
Presentacion de la práctica de Ajax 2016Presentacion de la práctica de Ajax 2016
Presentacion de la práctica de Ajax 2016
 

Similar to Code diving in Ruby and Rails

Rails-3-app-auto-generator-20100817
Rails-3-app-auto-generator-20100817Rails-3-app-auto-generator-20100817
Rails-3-app-auto-generator-20100817Tse-Ching Ho
 
To Batch Or Not To Batch
To Batch Or Not To BatchTo Batch Or Not To Batch
To Batch Or Not To BatchLuca Mearelli
 
Rapid Prototyping FTW!!!
Rapid Prototyping FTW!!!Rapid Prototyping FTW!!!
Rapid Prototyping FTW!!!cloudbring
 
Intro to-rails-webperf
Intro to-rails-webperfIntro to-rails-webperf
Intro to-rails-webperfNew Relic
 
Porting Rails Apps to High Availability Systems
Porting Rails Apps to High Availability SystemsPorting Rails Apps to High Availability Systems
Porting Rails Apps to High Availability SystemsMarcelo Pinheiro
 
Redux at scale
Redux at scaleRedux at scale
Redux at scaleinovia
 
10 tips for Redux at scale
10 tips for Redux at scale10 tips for Redux at scale
10 tips for Redux at scaleinovia
 
Picking gem ruby for penetration testers
Picking gem ruby for penetration testersPicking gem ruby for penetration testers
Picking gem ruby for penetration testersPaolo Perego
 
Advanced App Building - Tips, Tricks & Lessons Learned
Advanced App Building - Tips, Tricks & Lessons LearnedAdvanced App Building - Tips, Tricks & Lessons Learned
Advanced App Building - Tips, Tricks & Lessons LearnedJay Graves
 
20141210 rakuten techtalk
20141210 rakuten techtalk20141210 rakuten techtalk
20141210 rakuten techtalkHiroshi SHIBATA
 
Introduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman OrtegaIntroduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman Ortegaarman o
 
Gem That (2009)
Gem That (2009)Gem That (2009)
Gem That (2009)lazyatom
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php PresentationAlan Pinstein
 
CICONF 2012 - Don't Make Me Read Your Mind
CICONF 2012 - Don't Make Me Read Your MindCICONF 2012 - Don't Make Me Read Your Mind
CICONF 2012 - Don't Make Me Read Your Mindciconf
 
Building Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in RailsBuilding Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in RailsJim Jeffers
 
Using Ruby in Android Development
Using Ruby in Android DevelopmentUsing Ruby in Android Development
Using Ruby in Android DevelopmentAdam Blum
 
Keeping it small - Getting to know the Slim PHP micro framework
Keeping it small - Getting to know the Slim PHP micro frameworkKeeping it small - Getting to know the Slim PHP micro framework
Keeping it small - Getting to know the Slim PHP micro frameworkJeremy Kendall
 
The Future of Dependency Management for Ruby
The Future of Dependency Management for RubyThe Future of Dependency Management for Ruby
The Future of Dependency Management for RubyHiroshi SHIBATA
 
Blow up when things are wrong
Blow up when things are wrongBlow up when things are wrong
Blow up when things are wrongVesa Vänskä
 

Similar to Code diving in Ruby and Rails (20)

Rails-3-app-auto-generator-20100817
Rails-3-app-auto-generator-20100817Rails-3-app-auto-generator-20100817
Rails-3-app-auto-generator-20100817
 
To Batch Or Not To Batch
To Batch Or Not To BatchTo Batch Or Not To Batch
To Batch Or Not To Batch
 
Rapid Prototyping FTW!!!
Rapid Prototyping FTW!!!Rapid Prototyping FTW!!!
Rapid Prototyping FTW!!!
 
Intro to-rails-webperf
Intro to-rails-webperfIntro to-rails-webperf
Intro to-rails-webperf
 
Porting Rails Apps to High Availability Systems
Porting Rails Apps to High Availability SystemsPorting Rails Apps to High Availability Systems
Porting Rails Apps to High Availability Systems
 
Redux at scale
Redux at scaleRedux at scale
Redux at scale
 
10 tips for Redux at scale
10 tips for Redux at scale10 tips for Redux at scale
10 tips for Redux at scale
 
Ruby For Startups
Ruby For StartupsRuby For Startups
Ruby For Startups
 
Picking gem ruby for penetration testers
Picking gem ruby for penetration testersPicking gem ruby for penetration testers
Picking gem ruby for penetration testers
 
Advanced App Building - Tips, Tricks & Lessons Learned
Advanced App Building - Tips, Tricks & Lessons LearnedAdvanced App Building - Tips, Tricks & Lessons Learned
Advanced App Building - Tips, Tricks & Lessons Learned
 
20141210 rakuten techtalk
20141210 rakuten techtalk20141210 rakuten techtalk
20141210 rakuten techtalk
 
Introduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman OrtegaIntroduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman Ortega
 
Gem That (2009)
Gem That (2009)Gem That (2009)
Gem That (2009)
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php Presentation
 
CICONF 2012 - Don't Make Me Read Your Mind
CICONF 2012 - Don't Make Me Read Your MindCICONF 2012 - Don't Make Me Read Your Mind
CICONF 2012 - Don't Make Me Read Your Mind
 
Building Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in RailsBuilding Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in Rails
 
Using Ruby in Android Development
Using Ruby in Android DevelopmentUsing Ruby in Android Development
Using Ruby in Android Development
 
Keeping it small - Getting to know the Slim PHP micro framework
Keeping it small - Getting to know the Slim PHP micro frameworkKeeping it small - Getting to know the Slim PHP micro framework
Keeping it small - Getting to know the Slim PHP micro framework
 
The Future of Dependency Management for Ruby
The Future of Dependency Management for RubyThe Future of Dependency Management for Ruby
The Future of Dependency Management for Ruby
 
Blow up when things are wrong
Blow up when things are wrongBlow up when things are wrong
Blow up when things are wrong
 

Recently uploaded

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 

Recently uploaded (20)

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

Code diving in Ruby and Rails

  • 1. Code Diving in Ruby Evan Dorn Founder, Logical Reality Design http://lrdesign.com evan@lrdesign.com @idahoev Friday, August 9, 13
  • 2. SO YOU’RE CODING ALONG WHEN... Friday, August 9, 13
  • 3. 1) InvoicesController as an admin GET index should paginate all unpaid invoices as @unpaid_invoices Failure/Error: get :index NoMethodError: undefined method `unpayed' for #<Class:0x007fd8cfe9ee18> # /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ activerecord-3.2.12/lib/active_record/dynamic_matchers.rb:55:in `method_missing' # ./app/controllers/invoices_controller.rb:7:in `index' # /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ actionpack-3.2.12/lib/action_controller/metal/implicit_render.rb:4:in `send_action' # /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ actionpack-3.2.12/lib/abstract_controller/base.rb:167:in `process_action' # /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ actionpack-3.2.12/lib/action_controller/metal/rendering.rb:10:in `process_action' # /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ actionpack-3.2.12/lib/abstract_controller/callbacks.rb:18:in `block in process_action' # /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ activesupport-3.2.12/lib/active_support/callbacks.rb:447:in `_run__3859364058582123788__process_action__4176185741589430016__callbacks' # /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ activesupport-3.2.12/lib/active_support/callbacks.rb:405:in `__run_callback' # /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ activesupport-3.2.12/lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks' # /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ activesupport-3.2.12/lib/active_support/callbacks.rb:81:in `run_callbacks' # /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ actionpack-3.2.12/lib/abstract_controller/callbacks.rb:17:in `process_action' # /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ actionpack-3.2.12/lib/action_controller/metal/rescue.rb:29:in `process_action' # /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ actionpack-3.2.12/lib/action_controller/metal/instrumentation.rb:30:in `block in process_action' Friday, August 9, 13
  • 5. BUT THEN YOU NOTICE THIS... Friday, August 9, 13
  • 6. 1) InvoicesController as an admin GET index should paginate all unpaid invoices as @unpaid_invoices Failure/Error: get :index NoMethodError: undefined method `unpayed' for #<Class:0x007fd8cfe9ee18> # /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ activerecord-3.2.12/lib/active_record/dynamic_matchers.rb:55:in `method_missing' # ./app/controllers/invoices_controller.rb:7:in `index' # /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ actionpack-3.2.12/lib/action_controller/metal/implicit_render.rb:4:in `send_action' # /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ actionpack-3.2.12/lib/abstract_controller/base.rb:167:in `process_action' # /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ actionpack-3.2.12/lib/action_controller/metal/rendering.rb:10:in `process_action' # /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ actionpack-3.2.12/lib/abstract_controller/callbacks.rb:18:in `block in process_action' # /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ activesupport-3.2.12/lib/active_support/callbacks.rb:447:in `_run__3859364058582123788__process_action__4176185741589430016__callbacks' # /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ activesupport-3.2.12/lib/active_support/callbacks.rb:405:in `__run_callback' # /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ activesupport-3.2.12/lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks' # /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ activesupport-3.2.12/lib/active_support/callbacks.rb:81:in `run_callbacks' # /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ actionpack-3.2.12/lib/abstract_controller/callbacks.rb:17:in `process_action' # /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ actionpack-3.2.12/lib/action_controller/metal/rescue.rb:29:in `process_action' # /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ actionpack-3.2.12/lib/action_controller/metal/instrumentation.rb:30:in `block in process_action' Friday, August 9, 13
  • 7. 1) InvoicesController as an admin GET index should paginate all unpaid invoices as @unpaid_invoices Failure/Error: get :index NoMethodError: undefined method `unpayed' for #<Class:0x007fd8cfe9ee18> # /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ activerecord-3.2.12/lib/active_record/dynamic_matchers.rb:55:in `method_missing' # ./app/controllers/invoices_controller.rb:7:in `index' # /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ actionpack-3.2.12/lib/action_controller/metal/implicit_render.rb:4:in `send_action' # /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ actionpack-3.2.12/lib/abstract_controller/base.rb:167:in `process_action' # /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ actionpack-3.2.12/lib/action_controller/metal/rendering.rb:10:in `process_action' # /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ actionpack-3.2.12/lib/abstract_controller/callbacks.rb:18:in `block in process_action' # /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ activesupport-3.2.12/lib/active_support/callbacks.rb:447:in `_run__3859364058582123788__process_action__4176185741589430016__callbacks' # /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ activesupport-3.2.12/lib/active_support/callbacks.rb:405:in `__run_callback' # /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ activesupport-3.2.12/lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks' # /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ activesupport-3.2.12/lib/active_support/callbacks.rb:81:in `run_callbacks' # /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ actionpack-3.2.12/lib/abstract_controller/callbacks.rb:17:in `process_action' # /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ actionpack-3.2.12/lib/action_controller/metal/rescue.rb:29:in `process_action' # /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ actionpack-3.2.12/lib/action_controller/metal/instrumentation.rb:30:in `block in process_action' Friday, August 9, 13
  • 9. /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/active_support/ core_ext/hash/keys.rb:25:in `symbolize_keys': You blew it, dumbass (RuntimeError) from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/ active_record/connection_adapters/abstract/connection_specification.rb:45:in `resolve_hash_connection' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/ active_record/connection_adapters/abstract/connection_specification.rb:41:in `resolve_string_connection' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/ active_record/connection_adapters/abstract/connection_specification.rb:25:in `spec' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/ active_record/connection_adapters/abstract/connection_specification.rb:130:in `establish_connection' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/ active_record/railtie.rb:82:in `block (2 levels) in <class:Railtie>' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/ active_support/lazy_load_hooks.rb:36:in `instance_eval' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/ active_support/lazy_load_hooks.rb:36:in `execute_hook' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/ active_support/lazy_load_hooks.rb:26:in `block in on_load' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/ active_support/lazy_load_hooks.rb:25:in `each' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/ active_support/lazy_load_hooks.rb:25:in `on_load' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/ active_record/railtie.rb:74:in `block in <class:Railtie>' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/ initializable.rb:30:in `instance_exec' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/ initializable.rb:30:in `run' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/ initializable.rb:55:in `block in run_initializers' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/ initializable.rb:54:in `each' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/ initializable.rb:54:in `run_initializers' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/ application.rb:136:in `initialize!' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/ railtie/configurable.rb:30:in `method_missing' from /Volumes/Valinor/Users/evan/Development/Ruby/apps/tracks/config/environment.rb:5:in `<top (required)>' from /Volumes/Valinor/Users/evan/Development/Ruby/apps/tracks/spec/spec_helper.rb:3:in `require' from /Volumes/Valinor/Users/evan/Development/Ruby/apps/tracks/spec/spec_helper.rb:3:in `<top Friday, August 9, 13
  • 10. /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/active_support/ core_ext/hash/keys.rb:25:in `symbolize_keys': You blew it, dumbass (RuntimeError) from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/ active_record/connection_adapters/abstract/connection_specification.rb:45:in `resolve_hash_connection' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/ active_record/connection_adapters/abstract/connection_specification.rb:41:in `resolve_string_connection' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/ active_record/connection_adapters/abstract/connection_specification.rb:25:in `spec' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/ active_record/connection_adapters/abstract/connection_specification.rb:130:in `establish_connection' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/ active_record/railtie.rb:82:in `block (2 levels) in <class:Railtie>' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/ active_support/lazy_load_hooks.rb:36:in `instance_eval' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/ active_support/lazy_load_hooks.rb:36:in `execute_hook' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/ active_support/lazy_load_hooks.rb:26:in `block in on_load' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/ active_support/lazy_load_hooks.rb:25:in `each' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/ active_support/lazy_load_hooks.rb:25:in `on_load' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/ active_record/railtie.rb:74:in `block in <class:Railtie>' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/ initializable.rb:30:in `instance_exec' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/ initializable.rb:30:in `run' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/ initializable.rb:55:in `block in run_initializers' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/ initializable.rb:54:in `each' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/ initializable.rb:54:in `run_initializers' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/ application.rb:136:in `initialize!' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/ railtie/configurable.rb:30:in `method_missing' from /Volumes/Valinor/Users/evan/Development/Ruby/apps/tracks/config/environment.rb:5:in `<top (required)>' from /Volumes/Valinor/Users/evan/Development/Ruby/apps/tracks/spec/spec_helper.rb:3:in `require' from /Volumes/Valinor/Users/evan/Development/Ruby/apps/tracks/spec/spec_helper.rb:3:in `<top Friday, August 9, 13
  • 11. /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/active_support/ core_ext/hash/keys.rb:25:in `symbolize_keys': You blew it, dumbass (RuntimeError) from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/ active_record/connection_adapters/abstract/connection_specification.rb:45:in `resolve_hash_connection' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/ active_record/connection_adapters/abstract/connection_specification.rb:41:in `resolve_string_connection' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/ active_record/connection_adapters/abstract/connection_specification.rb:25:in `spec' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/ active_record/connection_adapters/abstract/connection_specification.rb:130:in `establish_connection' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/ active_record/railtie.rb:82:in `block (2 levels) in <class:Railtie>' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/ active_support/lazy_load_hooks.rb:36:in `instance_eval' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/ active_support/lazy_load_hooks.rb:36:in `execute_hook' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/ active_support/lazy_load_hooks.rb:26:in `block in on_load' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/ active_support/lazy_load_hooks.rb:25:in `each' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/ active_support/lazy_load_hooks.rb:25:in `on_load' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/ active_record/railtie.rb:74:in `block in <class:Railtie>' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/ initializable.rb:30:in `instance_exec' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/ initializable.rb:30:in `run' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/ initializable.rb:55:in `block in run_initializers' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/ initializable.rb:54:in `each' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/ initializable.rb:54:in `run_initializers' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/ application.rb:136:in `initialize!' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/ railtie/configurable.rb:30:in `method_missing' from /Volumes/Valinor/Users/evan/Development/Ruby/apps/tracks/config/environment.rb:5:in `<top (required)>' from /Volumes/Valinor/Users/evan/Development/Ruby/apps/tracks/spec/spec_helper.rb:3:in `require' from /Volumes/Valinor/Users/evan/Development/Ruby/apps/tracks/spec/spec_helper.rb:3:in `<top Friday, August 9, 13
  • 12. /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/active_support/ core_ext/hash/keys.rb:25:in `symbolize_keys': You blew it, dumbass (RuntimeError) from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/ active_record/connection_adapters/abstract/connection_specification.rb:45:in `resolve_hash_connection' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/ active_record/connection_adapters/abstract/connection_specification.rb:41:in `resolve_string_connection' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/ active_record/connection_adapters/abstract/connection_specification.rb:25:in `spec' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/ active_record/connection_adapters/abstract/connection_specification.rb:130:in `establish_connection' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/ active_record/railtie.rb:82:in `block (2 levels) in <class:Railtie>' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/ active_support/lazy_load_hooks.rb:36:in `instance_eval' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/ active_support/lazy_load_hooks.rb:36:in `execute_hook' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/ active_support/lazy_load_hooks.rb:26:in `block in on_load' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/ active_support/lazy_load_hooks.rb:25:in `each' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/ active_support/lazy_load_hooks.rb:25:in `on_load' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activerecord-3.2.12/lib/ active_record/railtie.rb:74:in `block in <class:Railtie>' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/ initializable.rb:30:in `instance_exec' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/ initializable.rb:30:in `run' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/ initializable.rb:55:in `block in run_initializers' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/ initializable.rb:54:in `each' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/ initializable.rb:54:in `run_initializers' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/ application.rb:136:in `initialize!' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/railties-3.2.12/lib/rails/ railtie/configurable.rb:30:in `method_missing' from /Volumes/Valinor/Users/evan/Development/Ruby/apps/tracks/config/environment.rb:5:in `<top (required)>' from /Volumes/Valinor/Users/evan/Development/Ruby/apps/tracks/spec/spec_helper.rb:3:in `require' from /Volumes/Valinor/Users/evan/Development/Ruby/apps/tracks/spec/spec_helper.rb:3:in `<top Friday, August 9, 13
  • 13. IT’S PROBABLY SOMETHING YOU DID. Friday, August 9, 13
  • 14. IT’S PROBABLY SOMETHING YOU DID. (but the error’s not in your code) Friday, August 9, 13
  • 15. RAILS’ CODE IS HARD TO UNDERSTAND Friday, August 9, 13
  • 16. RAILS’ CODE IS HARD TO UNDERSTAND But that doesn’t matter! Dive in anyway. Friday, August 9, 13
  • 17. RUBY IS A RUN-TIME LANGUAGE Friday, August 9, 13
  • 18. RUBY IS A RUN-TIME LANGUAGE •This makes it hard to find stuff! Friday, August 9, 13
  • 19. RUBY IS A RUN-TIME LANGUAGE •This makes it hard to find stuff! •Your IDE isn’t much help Friday, August 9, 13
  • 20. RUBY IS A RUN-TIME LANGUAGE •This makes it hard to find stuff! •Your IDE isn’t much help •So find stuff AT RUN TIME Friday, August 9, 13
  • 21. JUST OPEN THAT FILE Friday, August 9, 13
  • 22. JUST OPEN THAT FILE Don’t be intimidated ... it’s all just Ruby Friday, August 9, 13
  • 23. JUST OPEN THAT FILE ~/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/active_support/ core_ext/hash/keys.rb:25:in `symbolize_keys': You blew it, dumbass (RuntimeError) from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ activerecord-3.2.12/lib/active_record/connection_adapters/abstract/ connection_specification.rb:45:in `resolve_hash_connection' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ activerecord-3.2.12/lib/active_record/connection_adapters/abstract/ connection_specification.rb:41:in `resolve_string_connection' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ Don’t be intimidated ... it’s all just Ruby Friday, August 9, 13
  • 24. JUST OPEN THAT FILE ~/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12/lib/active_support/ core_ext/hash/keys.rb:25:in `symbolize_keys': You blew it, dumbass (RuntimeError) from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ activerecord-3.2.12/lib/active_record/connection_adapters/abstract/ connection_specification.rb:45:in `resolve_hash_connection' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ activerecord-3.2.12/lib/active_record/connection_adapters/abstract/ connection_specification.rb:41:in `resolve_string_connection' from /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ $ vim ~evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/activesupport-3.2.12 Don’t be intimidated ... it’s all just Ruby Friday, August 9, 13
  • 26. USE GEM... $ gem env Friday, August 9, 13
  • 27. USE GEM... RubyGems Environment: - RUBYGEMS VERSION: 1.8.25 - RUBY VERSION: 1.9.3 (2012-11-10 patchlevel 327) [x86_64-darwin11.4.2] - INSTALLATION DIRECTORY: /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fas - RUBY EXECUTABLE: /Volumes/Valinor/Users/evan/.rvm/rubies/ruby-1.9.3-p327-fast/bin/ - EXECUTABLE DIRECTORY: /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327- fast@tracks/bin - RUBYGEMS PLATFORMS: - ruby - x86_64-darwin-11 - GEM PATHS: - /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks - /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@global - GEM CONFIGURATION: $ gem env Friday, August 9, 13
  • 28. USE GEM... RubyGems Environment: - RUBYGEMS VERSION: 1.8.25 - RUBY VERSION: 1.9.3 (2012-11-10 patchlevel 327) [x86_64-darwin11.4.2] - INSTALLATION DIRECTORY: /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fas - RUBY EXECUTABLE: /Volumes/Valinor/Users/evan/.rvm/rubies/ruby-1.9.3-p327-fast/bin/ - EXECUTABLE DIRECTORY: /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327- fast@tracks/bin - RUBYGEMS PLATFORMS: - ruby - x86_64-darwin-11 - GEM PATHS: - /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks - /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@global - GEM CONFIGURATION: $ gem env Friday, August 9, 13
  • 29. USE GEM... RubyGems Environment: - RUBYGEMS VERSION: 1.8.25 - RUBY VERSION: 1.9.3 (2012-11-10 patchlevel 327) [x86_64-darwin11.4.2] - INSTALLATION DIRECTORY: /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fas - RUBY EXECUTABLE: /Volumes/Valinor/Users/evan/.rvm/rubies/ruby-1.9.3-p327-fast/bin/ - EXECUTABLE DIRECTORY: /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327- fast@tracks/bin - RUBYGEMS PLATFORMS: - ruby - x86_64-darwin-11 - GEM PATHS: - /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks - /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@global - GEM CONFIGURATION: $ gem env $ cd /Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks Friday, August 9, 13
  • 31. WHAT’S THIS VALUE? #activesupport-3.2.12/lib/active_support/core_ext/hash class Hash # Return a new hash with all keys converted to symbols, as # long as they respond to +to_sym+. # # { 'name' => 'Rob', 'years' => '28' }.symbolize_keys # #=> { :name => "Rob", :years => "28" } def symbolize_keys dup.symbolize_keys! end alias_method :to_options, :symbolize_keys alias_method :to_options!, :symbolize_keys! # Validate all keys in a hash match *valid keys, raising ArgumentError on a mismatch. # Note that keys are NOT treated indifferently, meaning if you use strings for keys but assert symbols Friday, August 9, 13
  • 32. WHAT’S THIS VALUE? #activesupport-3.2.12/lib/active_support/core_ext/hash class Hash # Return a new hash with all keys converted to symbols, as # long as they respond to +to_sym+. # # { 'name' => 'Rob', 'years' => '28' }.symbolize_keys # #=> { :name => "Rob", :years => "28" } def symbolize_keys dup.symbolize_keys! end alias_method :to_options, :symbolize_keys alias_method :to_options!, :symbolize_keys! # Validate all keys in a hash match *valid keys, raising ArgumentError on a mismatch. # Note that keys are NOT treated indifferently, meaning if you use strings for keys but assert symbols Friday, August 9, 13
  • 33. WHAT’S THIS VALUE? #activesupport-3.2.12/lib/active_support/core_ext/hash class Hash # Return a new hash with all keys converted to symbols, as # long as they respond to +to_sym+. # # { 'name' => 'Rob', 'years' => '28' }.symbolize_keys # #=> { :name => "Rob", :years => "28" } def symbolize_keys p self dup.symbolize_keys! end alias_method :to_options, :symbolize_keys alias_method :to_options!, :symbolize_keys! # Validate all keys in a hash match *valid keys, raising ArgumentError on a mismatch. # Note that keys are NOT treated indifferently, meaning if you Friday, August 9, 13
  • 34. TOO MUCH OUTPUT! .{:client_id=>"24"} {"controller"=>"invoices", "action"=>"new"} .{:client_id=>"27"} {"controller"=>"invoices", "action"=>"new"} .{:client_id=>"30"} {"controller"=>"invoices", "action"=>"new"} .{:client_id=>"33"} {"controller"=>"invoices", "action"=>"new"} .{:client_id=>"37"} {"controller"=>"invoices", "action"=>"new"} .{:id=>"19"} {"id"=>"19", "controller"=>"invoices", "action"=>"edit"} .{:id=>"20"} {"id"=>"20", "controller"=>"invoices", "action"=>"edit"} {:controller=>"devise/ sessions", :action=>"new", :use_route=>"login", :only_path=>true} . {:invoice=>{:due_on=>"2013-05-14", :client_id=>"42", :notes=>"value for notes"}} Friday, August 9, 13
  • 35. OUTPUT AND STOP #activesupport-3.2.12/lib/active_support/core_ext/hash class Hash # Return a new hash with all keys converted to symbols, as # long as they respond to +to_sym+. # # { 'name' => 'Rob', 'years' => '28' }.symbolize_keys # #=> { :name => "Rob", :years => "28" } def symbolize_keys raise self # stop running! dup.symbolize_keys! end alias_method :to_options, :symbolize_keys alias_method :to_options!, :symbolize_keys! # Validate all keys in a hash match *valid keys, raising ArgumentError on a mismatch. # Note that keys are NOT treated indifferently, meaning if you Friday, August 9, 13
  • 36. ADD A CONDITION #activesupport-3.2.12/lib/active_support/core_ext/hash class Hash # Return a new hash with all keys converted to symbols, as # long as they respond to +to_sym+. # # { 'name' => 'Rob', 'years' => '28' }.symbolize_keys # #=> { :name => "Rob", :years => "28" } def symbolize_keys raise self if <some condition> dup.symbolize_keys! end alias_method :to_options, :symbolize_keys alias_method :to_options!, :symbolize_keys! # Validate all keys in a hash match *valid keys, raising ArgumentError on a mismatch. # Note that keys are NOT treated indifferently, meaning if you Friday, August 9, 13
  • 37. KEEP TRACK OF LOCATION #activesupport-3.2.12/lib/active_support/core_ext/hash class Hash # Return a new hash with all keys converted to symbols, as # long as they respond to +to_sym+. # # { 'name' => 'Rob', 'years' => '28' }.symbolize_keys # #=> { :name => "Rob", :years => "28" } def symbolize_keys p __FILE__, __LINE__ dup.symbolize_keys! end alias_method :to_options, :symbolize_keys alias_method :to_options!, :symbolize_keys! # Validate all keys in a hash match *valid keys, raising ArgumentError on a mismatch. # Note that keys are NOT treated indifferently, meaning if you Friday, August 9, 13
  • 38. LABEL WITH LOCATION #activesupport-3.2.12/lib/active_support/core_ext/hash class Hash # Return a new hash with all keys converted to symbols, as # long as they respond to +to_sym+. # # { 'name' => 'Rob', 'years' => '28' }.symbolize_keys # #=> { :name => "Rob", :years => "28" } def symbolize_keys p “#{__FILE__}:#{__LINE__}” => self dup.symbolize_keys! end alias_method :to_options, :symbolize_keys alias_method :to_options!, :symbolize_keys! # Validate all keys in a hash match *valid keys, raising ArgumentError on a mismatch. # Note that keys are NOT treated indifferently, meaning if you Friday, August 9, 13
  • 39. TAG WITH A NAME #activesupport-3.2.12/lib/active_support/core_ext/hash class Hash # Return a new hash with all keys converted to symbols, as # long as they respond to +to_sym+. # # { 'name' => 'Rob', 'years' => '28' }.symbolize_keys # #=> { :name => "Rob", :years => "28" } def symbolize_keys p :broken_hash => self dup.symbolize_keys! end alias_method :to_options, :symbolize_keys alias_method :to_options!, :symbolize_keys! # Validate all keys in a hash match *valid keys, raising ArgumentError on a mismatch. # Note that keys are NOT treated indifferently, meaning if you Friday, August 9, 13
  • 40. CLEAN IT UP #activesupport-3.2.12/lib/active_support/core_ext/hash class Hash # Return a new hash with all keys converted to symbols, as # long as they respond to +to_sym+. # # { 'name' => 'Rob', 'years' => '28' }.symbolize_keys # #=> { :name => "Rob", :years => "28" } def symbolize_keys require ‘pp’ pp self dup.symbolize_keys! end alias_method :to_options, :symbolize_keys alias_method :to_options!, :symbolize_keys! # Validate all keys in a hash match *valid keys, raising ArgumentError on a mismatch. Friday, August 9, 13
  • 42. HOW DID I GET HERE? Friday, August 9, 13
  • 43. HOW DID I GET HERE? #activesupport-3.2.12/lib/active_support/core_ext/hash class Hash # Return a new hash with all keys converted to symbols, as # long as they respond to +to_sym+. # # { 'name' => 'Rob', 'years' => '28' }.symbolize_keys # #=> { :name => "Rob", :years => "28" } def symbolize_keys require ‘pp’ pp caller[0..10] dup.symbolize_keys! end alias_method :to_options, :symbolize_keys alias_method :to_options!, :symbolize_keys! # Validate all keys in a hash match *valid keys, raising ArgumentError on a mismatch. Friday, August 9, 13
  • 44. “DOES THIS FILE LOAD?” module SomePossiblyIncludedMonkeyPatch def change_important_class_behavior # ... # ... end def obscure_some_key_method # ... # ... end end Friday, August 9, 13
  • 45. “DOES THIS FILE LOAD?” raise “Yes, somebody required me” module SomePossiblyIncludedMonkeyPatch def change_important_class_behavior # ... # ... end def obscure_some_key_method # ... # ... end end Friday, August 9, 13
  • 46. “WHY DIDN’T THIS FILE LOAD?” Friday, August 9, 13
  • 47. “WHY DIDN’T THIS FILE LOAD?” require ‘some_library/some_junk’ module MyNiftyBehavior def stuff Friday, August 9, 13
  • 48. “WHY DIDN’T THIS FILE LOAD?” require ‘some_library/some_junk’ module MyNiftyBehavior def stuff $ rspec spec/ No such file to load -- some_library/some_junk (LoadError) Friday, August 9, 13
  • 49. “WHY DIDN’T THIS FILE LOAD?” require ‘some_library/some_junk’ module MyNiftyBehavior def stuff $ rspec spec/ No such file to load -- some_library/some_junk (LoadError) ... pretty print the search path Friday, August 9, 13
  • 50. “WHY DIDN’T THIS FILE LOAD?” require ‘some_library/some_junk’ module MyNiftyBehavior def stuff $ rspec spec/ No such file to load -- some_library/some_junk (LoadError) ... pretty print the search path require ‘pp’ pp $: require ‘some_library/some_junk’ module MyNiftyBehavior def stuff Friday, August 9, 13
  • 51. “WHO REQUIRED ME?” module SomePossiblyIncludedMonkeyPatch def change_important_class_behavior # ... # ... end def obscure_some_key_method # ... # ... end end Friday, August 9, 13
  • 52. “WHO REQUIRED ME?” p “Required By” => caller[0] module SomePossiblyIncludedMonkeyPatch def change_important_class_behavior # ... # ... end def obscure_some_key_method # ... # ... end end Friday, August 9, 13
  • 53. WHAT IF YOU DON’T KNOW THE RIGHT QUESTION YET? Friday, August 9, 13
  • 55. YOUR GEMFILE source 'http://rubygems.org' gem 'rails', '3.2.12' gem 'rack', '~> 1.4.0' gem 'rake' gem "will_paginate" gem 'devise' group :development, :test do gem 'rspec' gem 'rspec-rails' gem 'factory_girl_rails' gem 'debugger' end Friday, August 9, 13
  • 56. IN THE CODE class Hash # Return a new hash with all keys converted to symbols, as # long as they respond to +to_sym+. # # { 'name' => 'Rob', 'years' => '28' }.symbolize_keys # #=> { :name => "Rob", :years => "28" } def symbolize_keys debugger dup.symbolize_keys! end alias_method :to_options, :symbolize_keys alias_method :to_options!, :symbolize_keys! # Validate all keys in a hash match *valid keys, raising ArgumentError on a mismatch. # Note that keys are NOT treated indifferently, meaning if you use strings for keys but assert symbols Friday, August 9, 13
  • 58. RUNNING IT $ rails server -u Development Server: Friday, August 9, 13
  • 59. RUNNING IT $ rails server -u Development Server: $ rspec -d spec/ rSpec: Friday, August 9, 13
  • 60. RUNNING IT Arbitrary Ruby script: $ rdebug <command> $ rdebug rake db:seed Friday, August 9, 13
  • 61. WHO ARE YOU? #activesupport-3.2.12/lib/active_support/core_ext/hash class Hash def symbolize_keys debugger dup.symbolize_keys! end Friday, August 9, 13
  • 62. WHO ARE YOU? (rdb:1) eval dup.class #activesupport-3.2.12/lib/active_support/core_ext/hash class Hash def symbolize_keys debugger dup.symbolize_keys! end Friday, August 9, 13
  • 63. WHO ARE YOU? (rdb:1) eval dup.class Hash #activesupport-3.2.12/lib/active_support/core_ext/hash class Hash def symbolize_keys debugger dup.symbolize_keys! end Friday, August 9, 13
  • 64. WHO AM I? (rdb:1) eval self.class Friday, August 9, 13
  • 65. WHO AM I? (rdb:1) eval self.class Hash Friday, August 9, 13
  • 66. WHO CAN I CALL? (rdb:1) eval self.methods Friday, August 9, 13
  • 67. WHO CAN I CALL? (rdb:1) eval self.methods [:specify, :class_variable_defined?, :public_class_method, :methods, :use_instantiated_fixtures=, :filtered_examples, :before_all_ivars, :should, :const_defined?, :untrust, :local_constant_names, :should_not, :capture, :module_eval, :instance_methods, :clone, :load_dependency, :to_json, :run_hook, :all_apply?, :share_examples_for, :include?, :redefine_method, :to_yaml, :respond_to?, :examples, :fail_fast?, :unloadable, :it_should_behave_like, :<=>, :instance_variable_defined?, :register, :acts_like?, :psych_yaml_as, :debug_method, :fixture_class_names, :let!, :render_views, :focus, :private_class_method, :delegate, :public_constant, :singleton_methods, :pretty_print_instance_variables, :attr_internal_writer, :use_instantiated_fixtures?, :matcher, :try, :tests, :as_json, :gem, :untrusted?, :controller_class, :pending, :parent, :silence, :class_eval, Friday, August 9, 13
  • 68. WHO CAN I CALL? (rdb:1) eval self.methods.sort Friday, August 9, 13
  • 69. WHO CAN I CALL? (rdb:1) eval self.methods.sort [:!, :!=, :!~, :<=>, :==, :===, :=~, :[], : []=, :__id__, :__send__, :`, :acts_like?, :all?, :any?, :as_json, :assert_valid_keys, :assoc, :binding_n, :blank?, :breakpoint, :capture, :chunk, :class, :class_eval, :clear, :clone, :collect, :collect_concat, :compare_by_identity, :compare_by_identity?, :count, :cycle, :dbg_print, :dbg_puts, :debugger, :deep_dup, :deep_merge, :deep_merge!, :deep_symbolize_keys, :default, :default=, :default_proc, :default_proc=, :define_singleton_method, :delete, :delete_if, :detect, :diff, :display, :drop, :drop_while, :dup, :duplicable?, :each, :each_cons, :each_entry, :each_key, :each_pair, :each_slice, :each_value, :each_with_index, :each_with_object, :empty?, :enable_warnings, :encode_json, :entries, :enum_for, :eql?, :equal?, :except, :except!, :exclude?, :extend, :extract!, :extractable_options?, :fetch, :find, :find_all, :find_index, Friday, August 9, 13
  • 70. WHO CAN I CALL? (rdb:1) eval self.methods.grep(/merge/) Friday, August 9, 13
  • 71. WHO CAN I CALL? (rdb:1) eval self.methods.grep(/merge/) [:deep_merge!, :reverse_merge!, :merge!, :merge, :deep_merge, :reverse_merge, :merge_resultset] Friday, August 9, 13
  • 72. DEBUGGER HAS ‘PP’ BY DEFAULT Friday, August 9, 13
  • 73. WHO DO YOU INCLUDE? (rdb:1) pp dup.class.included_modules Friday, August 9, 13
  • 74. WHO DO YOU INCLUDE? (rdb:1) pp dup.class.included_modules [SimpleCov::HashMergeHelper, JSON::Ext::Generator::GeneratorMethods::Hash, Enumerable, RSpec::Steps::ClassMethods, JSON::Ext::Generator::GeneratorMethods::Object, ActiveSupport::Dependencies::Loadable, PP::ObjectMixin, Kernel] Friday, August 9, 13
  • 76. AT THE COMMAND-LINE -H (show filename) -n (show line number) -r (recurse directories) -i (ignore case -- use carefully) $ grep -Hnir <pattern> <path> Friday, August 9, 13
  • 78. USEFUL PATTERNS $ grep -Hnr “def *my_method” * Method definitions: Friday, August 9, 13
  • 79. USEFUL PATTERNS $ grep -Hnr “def *my_method” * Method definitions: $ grep <stuff> | grep -v “ *#” Ignore comments: Friday, August 9, 13
  • 80. ACK > GREP $ ack <pattern> Friday, August 9, 13
  • 81. ACK > GREP Friday, August 9, 13
  • 82. ACK > GREP •Looks only in programming files (ignores logs!) Friday, August 9, 13
  • 83. ACK > GREP •Looks only in programming files (ignores logs!) •brew install ack Friday, August 9, 13
  • 84. ACK > GREP •Looks only in programming files (ignores logs!) •brew install ack •Configurable via .ackrc Friday, August 9, 13
  • 85. ACK > GREP •Looks only in programming files (ignores logs!) •brew install ack •Configurable via .ackrc •https://gist.github.com/IdahoEv/5580770 Friday, August 9, 13
  • 86. BUT THEN THIS... Friday, August 9, 13
  • 87. BUT THEN THIS... $ ack “def *my_method” Friday, August 9, 13
  • 88. BUT THEN THIS... $ ack “def *my_method” $ Friday, August 9, 13
  • 89. BUT THEN THIS... $ ack “def *my_method” $ ... it doesn’t exist Friday, August 9, 13
  • 90. BUT THEN THIS... $ ack “def *my_method” $ ... it doesn’t exist Friday, August 9, 13
  • 91. BECAUSE RUBY LETS YOU DO THIS... Friday, August 9, 13
  • 92. module RSpec module Core class ExampleGroup class << self delegate_to_metadata :described_class, :file_path alias_method :display_name, :description alias_method :describes, :described_class # @private # @macro [attach] define_example_method # @param [String] name # @param [Hash] extra_options # @param [Block] implementation def self.define_example_method(name, extra_options={}) module_eval(<<-END_RUBY, __FILE__, __LINE__) def #{name}(desc=nil, *args, &block) options = build_metadata_hash_from(args) options.update(:pending => RSpec::Core::Pending::) unless block options.update(#{extra_options.inspect}) examples << RSpec::Core::Example.new(self, desc, options, block) examples.last end END_RUBY end define_example_method :example define_example_method :it define_example_method :specify define_example_method :focus, :focused => true, :focus => true Friday, August 9, 13
  • 93. module RSpec module Core class ExampleGroup class << self delegate_to_metadata :described_class, :file_path alias_method :display_name, :description alias_method :describes, :described_class # @private # @macro [attach] define_example_method # @param [String] name # @param [Hash] extra_options # @param [Block] implementation def self.define_example_method(name, extra_options={}) module_eval(<<-END_RUBY, __FILE__, __LINE__) def #{name}(desc=nil, *args, &block) options = build_metadata_hash_from(args) options.update(:pending => RSpec::Core::Pending::) unless block options.update(#{extra_options.inspect}) examples << RSpec::Core::Example.new(self, desc, options, block) examples.last end END_RUBY end define_example_method :example define_example_method :it define_example_method :specify define_example_method :focus, :focused => true, :focus => true Friday, August 9, 13
  • 95. WHO DO YOU INCLUDE? #activesupport-3.2.12/lib/active_support/core_ext/hash class Hash # ... snip ... def symbolize_keys debugger dup.symbolize_keys! end # ... snip ... end Friday, August 9, 13
  • 96. WHO DO YOU INCLUDE? (rdb:1) pp self.class.included_modules [SimpleCov::HashMergeHelper, JSON::Ext::Generator::GeneratorMethods::Hash, Enumerable, RSpec::Steps::ClassMethods, JSON::Ext::Generator::GeneratorMethods::Object, ActiveSupport::Dependencies::Loadable, PP::ObjectMixin, Kernel] Friday, August 9, 13
  • 97. WHO DEFINED THAT METHOD? (rdb:1) eval self.method(:merge_resultset).owner Friday, August 9, 13
  • 98. WHO DEFINED THAT METHOD? (rdb:1) eval self.method(:merge_resultset).owner SimpleCov::HashMergeHelper Friday, August 9, 13
  • 99. BUT DEFINED WHERE? (rdb:1) pp self.method(:merge_resultset).source_location Friday, August 9, 13
  • 100. BUT DEFINED WHERE? (rdb:1) pp self.method(:merge_resultset).source_location ["~/evan/.rvm/gems/ruby-1.9.3-p327-fast@tracks/gems/ simplecov-0.5.4/lib/simplecov/merge_helpers.rb", 25] Friday, August 9, 13
  • 101. EVEN WORKS ON DYNAMIC METHODS! Friday, August 9, 13
  • 102. EVEN WORKS ON DYNAMIC METHODS! #/spec/controllers/invoices_controller_spec.rb require 'spec_helper' describe InvoicesController do debugger describe "as an admin" do before(:each) do authenticate(:admin) Friday, August 9, 13
  • 103. EVEN WORKS ON DYNAMIC METHODS! (rdb:1) eval method(:example).source_location Friday, August 9, 13
  • 104. EVEN WORKS ON DYNAMIC METHODS! (rdb:1) eval method(:example).source_location ["/Volumes/Valinor/Users/evan/.rvm/gems/ruby-1.9.3-p327- fast@tracks/gems/rspec-core-2.13.1/lib/rspec/core/ example_group.rb", 61] Friday, August 9, 13
  • 105. WHERE TO LOOK NEXT •Pry (https://github.com/pry/pry) •API Docs: http://www.ruby-doc.org/core-2.0 • Kernel • Module • Method Friday, August 9, 13
  • 106. Thanks! Evan Dorn Founder, Logical Reality Design http://lrdesign.com evan@lrdesign.com @idahoev Text Friday, August 9, 13