by chao- · 13y ago · 0 comments
I have been awaiting Ruby keyword arguments for a very long time, but the first time I heard them brought up (relating to 2.0), the person explaining had some qualms with how they were implemented. For the life of me I cannot remember what bothered them, but if that rings a bell for anyone else, please chime in.
https://twitter.com/brixen/status/281180931950264320
https://twitter.com/garybernhardt/status/281181122736582656.
Not sure if that's what you're thinking of.
@ch0wn: I'm pretty sure that chao- was talking about the implementation of keyword arguments, not refinements.
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.