io driver.io
io cell_spec.io
I watching the demo/use cases video for contracts.ruby and recorded some thoughts.
The use case states that you can avoid bugs like needing string keys instead of symbol keys be enforcing a contract that requires the method input to be a string.
IMO you should instead create a flexible interface that will allow any "stringable" input to be given to the method. That is, use the implicit string conversion methods to_s
to make a string of it for indexing into the hash.
desc "Launch a Capybara session in a console" | |
task capyconsole: :environment do | |
require "capybara" | |
require "pry" | |
driver = case ENV.fetch('DRIVER', 'phantomjs') | |
when 'phantomjs' | |
require "capybara/poltergeist" | |
Capybara.register_driver :poltergeist_debug do |app| |
Jim Weirich:
This is how I explain it… Ruby has Procs and Lambdas. Procs are created with
Proc.new { }
, lambdas are created withlambda {}
and->() {}
.
In Ruby 1.8,
proc {}
creates lambda, and Ruby 1.9 it creates procs (don't ask).
Lambdas use method semantics when handling parameters, procs use assignment semantics when handling parameters.
This means lambdas, like methods, will raise an ArgumentError when called with fewer arguments than they were defined with. Procs will simply assign nil to variables for arguments that were not passed in.