About
Buy my book
Exceptional Ruby is the definitive guide to exceptions and failure handling in Ruby.
Pages
Categories
Tag Archives: ruby
Ruby Thread Locals are also Fiber-Local
I was briefly concerned that thread-local variables would not also be Fiber-local, since fibers have their own stack. This would be a problem for any code which uses thread-local variables to delimit a stack context, e.g. to implement dynamically-scoped variables … Continue reading
Decoration is best, except when it isn’t
I think by now we all know to prefer composition over inheritance. But in a language with a lot of options, what’s the best kind of composition to use? Composing an adventure Consider an adventure game, with objects representing player … Continue reading
Another Take on Smalltalk-Style Controll Flow (SBPP #6)
The latest Smalltalk-to-Ruby translation in my SBPPRB archive is “Dispatched Interpretation”. It’s one of the bigger ones I’ve tackled so far. I’m not going to go over the whole pattern here; for that you’ll just need to buy a copy … Continue reading
Testing that a block is called
CapnKernul asks: Hey Avdi. How would you test that a method’s provided block is called in RSpec? Would you stub #to_proc (for &block) and mock #call? Typically the way I test that a block is called goes something like this: … Continue reading
DRYing up your validations using DB reflection
Avoiding silent truncation of your model fields requires putting length validations on them. But this can introduce duplication of knowledge. In this post I demonstrate how to pull limit information directly from the DB into your model validations. Continue reading
RVM.el and Inf-Ruby (Emacs Reboot #14)
With my Emacs config files better organized, it’s time now to turn my attention to improving my experience editing Ruby files. First of all, I want to be able to quickly and easily drop into an IRB session from the … Continue reading
Declarative Keyword Parameters in Ruby (SBPP #5)
Reading SBPP has got me thinking about keyword parameters. Ruby doesn’t have keyword arguments, but it fakes them pretty well: def explain(options={}) “the #{options[:the]} says #{options[:says]}” end explain the: “pig”, says: “oink” # => “the pig says oink” explain the: … Continue reading
SBPP #4: method Cascades
In Smalltalk, you can “cascade” side-effectful calls to the same object using the semicolon (;) operator. E.g.: If I understand it correctly, the semicolon is effectively a K-combinator or “Kestrel”. I am jealous. Sure, we have Object#tap, but that’s awfully … Continue reading
Posted in Smalltalk Best Practice Patterns
Tagged combinators, kestrel, patterns, ruby, smalltalk
7 Comments
