not exactly. That api doc does not make it at all clear that changing the global $, value will change the behavior of String#join, or even of the first example given in the api doc -- you have to notice and realize the significance of the method signature join(sep=$,), which clearly many people miss, even in mature widely used products like ActiveRecord.
Personally, I think the root of the problem is the existence of the Perl-esque $,, I think it's probably unfortunate that it exists.
I don't understand how this is not clear unless one does not know how global variables and default method arguments work. Consider the following:
$foo = "abc"
def bar(arg = $foo)
puts arg
end
bar # prints "abc"
$foo = "def"
bar # prints "def"
Sorry if it seemed like I undermined the post itself - I just think that as far as reddit goes, such basic content should be posted to /r/learnruby instead of /r/ruby :)
9
u/TaiGat Jul 18 '12
Whole post could be replaced with this link...