There's a really in-depth article on them that also covers concerns about the implementation: http://blog.headius.com/2012/11/refining-ruby.html
sub withCamelize (&) {
my ($thunk) = @_;
local *{'String::camelize'} = sub { ... };
$thunk->()
}
sub camelize_and_join {
my ($str_ary) = @_;
withCamelize {
join ', ', map { $_->camelize } @$str_ary
}
}
So you can probably already accomplish the same with Ruby's equivalent of 'local' for dynamic scoping.Second, refinements apply lexically. Consider a class A where refinements have been declared, and a class B where they have not. Class A code calls Class B code. Class B code will not see class A's refinements. In the case of dynamic scope, the refinements in use by class A would be visible to class B code, when called from code within class A.
And the lack of dynamic scoping in Ruby can cause problems elsewhere: http://news.ycombinator.com/item?id=5072925
PS. I seem fond of dynamic scoping because I've posted lots of examples here on HN: http://www.hnsearch.com/search#request/all&q=draegtun+dy...
Refinements mean things like method lookup are sensitive to the context and become much more fun.